@@ -4,14 +4,14 @@ import FAQSection from "../components/FAQSection"
4
4
import { graphql } from "gatsby"
5
5
6
6
export const useAccordion = ( ) => {
7
- const toggleChildrenClass = ( element : HTMLElement ) => {
7
+ const toggleChildrenClass = ( element : React . ReactNode ) => {
8
8
console . log ( nextUntil ( element , 'h3' ) )
9
9
Array . from ( nextUntil ( element , 'h3' ) ) . map ( p =>
10
10
p . classList . toggle ( 'show' )
11
11
) ;
12
12
} ;
13
13
14
- var nextUntil = function ( elem : HTMLElement , selector : string ) {
14
+ var nextUntil = function ( elem : any , selector : string ) {
15
15
16
16
// Setup siblings array
17
17
var siblings = [ ] ;
@@ -41,13 +41,16 @@ export const useAccordion = () => {
41
41
const hash = location . hash ? location . hash . split ( '#' ) [ 1 ] : '' ;
42
42
43
43
if ( hash ) {
44
- const parent = document && document . getElementById ( hash ) ;
44
+ const anchor = document && document . getElementById ( hash )
45
+ const heading : any = anchor && anchor . parentNode ;
45
46
46
- document . getElementById ( hash ) . classList . toggle ( 'open' ) ;
47
- toggleChildrenClass ( parent ) ;
47
+ if ( heading ) {
48
+ heading . classList . toggle ( 'open' ) ;
49
+ toggleChildrenClass ( heading ) ;
50
+ }
48
51
}
49
52
50
- const toggleClasses = ( e : Event ) => {
53
+ const toggleClasses = ( e : any ) => {
51
54
if ( e . target . localName !== 'h3' ) return ;
52
55
history . replaceState ( { } , '' , '#' + e . target . getElementsByTagName ( 'a' ) [ 0 ] . id ) ;
53
56
history . scrollRestoration = 'manual' ;
@@ -72,10 +75,8 @@ export default ({ pageContext, data }: any) => {
72
75
const bPosition = b . frontmatter . position
73
76
if ( aPosition < bPosition ) {
74
77
return - 1
75
- } else if ( aPosition > bPosition ) {
76
- return 1
77
78
}
78
- return 0
79
+ return 1
79
80
} )
80
81
81
82
return (
@@ -88,7 +89,7 @@ export default ({ pageContext, data }: any) => {
88
89
{ sections . map (
89
90
(
90
91
{
91
- frontmatter : { title, permalink, questions } ,
92
+ frontmatter : { title, permalink } ,
92
93
rawMarkdownBody,
93
94
} : any ,
94
95
i
@@ -97,7 +98,6 @@ export default ({ pageContext, data }: any) => {
97
98
key = { i }
98
99
title = { title }
99
100
permalink = { permalink }
100
- questions = { questions }
101
101
rawMarkdownBody = { rawMarkdownBody }
102
102
pageContext = { pageContext }
103
103
/>
0 commit comments