File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed
packages/gitbook/src/components/DocumentView/Expandable Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change @@ -15,11 +15,11 @@ export function Details(props: {
1515 open ?: boolean ;
1616 className ?: ClassValue ;
1717} ) {
18- const { children, id, open , className } = props ;
18+ const { children, id, className } = props ;
1919
2020 const detailsRef = React . useRef < HTMLDetailsElement > ( null ) ;
2121
22- const [ anchorElement , setAnchorElement ] = React . useState < Element | null | undefined > ( ) ;
22+ const [ openFromHash , setOpenFromHash ] = React . useState ( false ) ;
2323
2424 const hash = useHash ( ) ;
2525 /**
@@ -31,20 +31,17 @@ export function Details(props: {
3131 return ;
3232 }
3333 if ( hash === id ) {
34- setAnchorElement ( detailsRef . current ) ;
35- } else {
36- const activeElement = document . getElementById ( hash ) ;
37- if ( activeElement && detailsRef . current ?. contains ( activeElement ) ) {
38- setAnchorElement ( activeElement ) ;
39- }
34+ setOpenFromHash ( true ) ;
4035 }
36+ const activeElement = document . getElementById ( hash ) ;
37+ setOpenFromHash ( Boolean ( activeElement && detailsRef . current ?. contains ( activeElement ) ) ) ;
4138 } , [ hash , id ] ) ;
4239
4340 return (
4441 < details
4542 ref = { detailsRef }
4643 id = { id }
47- open = { open || Boolean ( anchorElement ) }
44+ open = { props . open || openFromHash }
4845 className = { tcls (
4946 className ,
5047 'group/expandable' ,
You can’t perform that action at this time.
0 commit comments