@@ -10,6 +10,8 @@ import { NavButton } from '../button/nav-button/nav-button';
1010interface CollapsibleContextProps {
1111 isExpanded : boolean ;
1212 toggle : ( ) => void ;
13+ expandLabel : string ;
14+ collapseLabel : string ;
1315}
1416
1517const CollapsibleContext = createContext < CollapsibleContextProps | undefined > ( undefined ) ;
@@ -28,9 +30,26 @@ export type CollapsibleProps = {
2830 isExpanded ?: boolean ;
2931 defaultExpanded ?: boolean ;
3032 onToggle ?: ( expanded : boolean ) => void ;
33+ /**
34+ * Accessible label for the button when the content is collapsed
35+ * @default 'Expand'
36+ */
37+ expandLabel ?: string ;
38+ /**
39+ * Accessible label for the button when the content is expanded
40+ * @default 'Collapse'
41+ */
42+ collapseLabel ?: string ;
3143} ;
3244
33- export function Collapsible ( { children, isExpanded, defaultExpanded = false , onToggle } : CollapsibleProps ) {
45+ export function Collapsible ( {
46+ children,
47+ isExpanded,
48+ defaultExpanded = false ,
49+ onToggle,
50+ expandLabel = 'Expand' ,
51+ collapseLabel = 'Collapse' ,
52+ } : CollapsibleProps ) {
3453 const isControlled = isExpanded !== undefined ;
3554 const [ internalExpanded , setInternalExpanded ] = useState ( defaultExpanded ) ;
3655
@@ -45,7 +64,9 @@ export function Collapsible({ children, isExpanded, defaultExpanded = false, onT
4564 } , [ actualExpanded , isControlled , onToggle ] ) ;
4665
4766 return (
48- < CollapsibleContext . Provider value = { { isExpanded : actualExpanded , toggle } } > { children } </ CollapsibleContext . Provider >
67+ < CollapsibleContext . Provider value = { { isExpanded : actualExpanded , toggle, expandLabel, collapseLabel } } >
68+ { children }
69+ </ CollapsibleContext . Provider >
4970 ) ;
5071}
5172
@@ -54,7 +75,7 @@ Collapsible.Button = function CollapsibleButton() {
5475
5576 return (
5677 < NavButton
57- aria-label = { context ?. isExpanded ? 'Collapse' : 'Expand' }
78+ aria-label = { context ?. isExpanded ? context . collapseLabel : context ?. expandLabel }
5879 className = { clsx ( styles [ 'expand-button' ] , {
5980 [ styles [ 'expanded' ] ] : context ?. isExpanded ,
6081 } ) }
0 commit comments