@@ -22,6 +22,10 @@ export interface CAccordionItemContextProps {
2222export const CAccordionItemContext = createContext ( { } as CAccordionItemContextProps )
2323
2424export interface CAccordionItemProps extends HTMLAttributes < HTMLDivElement > {
25+ /**
26+ * The id global attribute defines an identifier (ID) that must be unique in the whole document.
27+ */
28+ id ?: string
2529 /**
2630 * A string of all className you want applied to the base component.
2731 */
@@ -33,9 +37,9 @@ export interface CAccordionItemProps extends HTMLAttributes<HTMLDivElement> {
3337}
3438
3539export const CAccordionItem = forwardRef < HTMLDivElement , CAccordionItemProps > (
36- ( { children, className, itemKey, ...rest } , ref ) => {
37- const id = useId ( )
38- const _itemKey = useRef ( itemKey ?? id )
40+ ( { children, className, id , itemKey, ...rest } , ref ) => {
41+ const _id = id ?? useId ( )
42+ const _itemKey = useRef ( itemKey ?? _id )
3943
4044 const { _activeItemKey, alwaysOpen, setActiveKey } = useContext ( CAccordionContext )
4145 const [ visible , setVisible ] = useState ( Boolean ( _activeItemKey === _itemKey . current ) )
@@ -52,12 +56,12 @@ export const CAccordionItem = forwardRef<HTMLDivElement, CAccordionItemProps>(
5256
5357 return (
5458 < div className = { classNames ( 'accordion-item' , className ) } { ...rest } ref = { ref } >
55- < CAccordionItemContext . Provider value = { { id, setVisible, visible } } >
59+ < CAccordionItemContext . Provider value = { { id : _id , setVisible, visible } } >
5660 { children }
5761 </ CAccordionItemContext . Provider >
5862 </ div >
5963 )
60- } ,
64+ }
6165)
6266
6367CAccordionItem . propTypes = {
0 commit comments