55 * found at http://www.apache.org/licenses/LICENSE-2.0.
66 */
77
8- import React , { useEffect , useRef , useState } from 'react' ;
8+ import React , { ButtonHTMLAttributes , HTMLAttributes , createRef , useEffect , useState } from 'react' ;
99import PropTypes from 'prop-types' ;
1010import { useAccordion } from '@zendeskgarden/container-accordion' ;
1111import { getControlledValue } from '@zendeskgarden/container-utilities' ;
@@ -24,12 +24,14 @@ import { useChromeContext } from '../../utils/useChromeContext';
2424export const CollapsibleSubNavItem = React . forwardRef < HTMLDivElement , ICollapsibleSubNavItemProps > (
2525 ( { header, children, isExpanded : controlledExpanded , onChange, ...other } , ref ) => {
2626 const { isDark, isLight } = useChromeContext ( ) ;
27- const panelRef = useRef < HTMLDivElement > ( ) ;
27+ const panelRef = createRef < HTMLDivElement > ( ) ;
2828 const [ internalExpanded , setInternalExpanded ] = useState ( controlledExpanded ) ;
2929 const expanded = getControlledValue ( controlledExpanded , internalExpanded ) ;
30- const expandedSections = expanded ? [ 0 ] : [ ] ;
30+ const value = 0 ;
31+ const expandedSections = expanded ? [ value ] : [ ] ;
3132
3233 const { getHeaderProps, getTriggerProps, getPanelProps } = useAccordion ( {
34+ sections : [ value ] ,
3335 expandedSections,
3436 onChange : ( ) => {
3537 const isExpanded = expandedSections . length === 0 ;
@@ -46,21 +48,22 @@ export const CollapsibleSubNavItem = React.forwardRef<HTMLDivElement, ICollapsib
4648 if ( expanded && panelRef . current ) {
4749 panelRef . current . style . maxHeight = `${ panelRef . current . scrollHeight } px` ;
4850 }
49- } , [ expanded , children ] ) ;
51+ } , [ expanded , children , panelRef ] ) ;
5052
5153 return (
5254 < div ref = { ref } >
53- < div { ...getHeaderProps ( { ariaLevel : 2 } ) } >
55+ < div { ...getHeaderProps ( { 'aria-level' : 2 } ) } >
5456 < StyledSubNavItemHeader
5557 isDark = { isDark }
5658 isLight = { isLight }
57- { ... getTriggerProps ( {
58- isExpanded : expanded ,
59- index : 0 ,
59+ isExpanded = { expanded }
60+ { ... ( getTriggerProps ( {
61+ ... other ,
6062 role : null ,
61- tabIndex : null ,
62- ...other
63- } ) }
63+ tabIndex : null as any ,
64+ value
65+ } ) as ButtonHTMLAttributes < HTMLButtonElement > ) }
66+ type = "button"
6467 >
6568 < >
6669 { header }
@@ -71,11 +74,11 @@ export const CollapsibleSubNavItem = React.forwardRef<HTMLDivElement, ICollapsib
7174 </ StyledSubNavItemHeader >
7275 </ div >
7376 < StyledSubNavPanel
74- { ... getPanelProps ( {
75- index : 0 ,
76- isHidden : ! expanded ,
77- ref : panelRef
78- } ) }
77+ isHidden = { ! expanded }
78+ { ... ( getPanelProps ( {
79+ ref : panelRef ,
80+ value
81+ } ) as HTMLAttributes < HTMLDivElement > ) }
7982 >
8083 { children }
8184 </ StyledSubNavPanel >
0 commit comments