File tree Expand file tree Collapse file tree 3 files changed +59
-2
lines changed Expand file tree Collapse file tree 3 files changed +59
-2
lines changed Original file line number Diff line number Diff line change @@ -155,6 +155,10 @@ Class(es) to apply to the 'button' element.
155155
156156Class(es) to apply to element.
157157
158+ #### region: ` boolean`
159+
160+ Make the element have a region role.
161+
158162---
159163
160164### AccordionItemState
Original file line number Diff line number Diff line change @@ -66,4 +66,49 @@ describe('AccordionItem', () => {
6666 expect ( getByText ( 'Hello World' ) ) . toBeTruthy ( ) ;
6767 } ) ;
6868 } ) ;
69+
70+ describe ( 'role region' , ( ) => {
71+ it ( 'enables aria-labelledby' , ( ) => {
72+ const { getByRole } = render (
73+ < Accordion >
74+ < AccordionItem >
75+ < AccordionItemPanel region >
76+ Hello World
77+ </ AccordionItemPanel >
78+ </ AccordionItem >
79+ </ Accordion > ,
80+ ) ;
81+ expect (
82+ getByRole ( 'region' ) . getAttribute ( 'aria-labelledby' ) ,
83+ ) . toBeTruthy ( ) ;
84+ } ) ;
85+
86+ it ( 'disables aria-labelledby when absent' , ( ) => {
87+ const { getByText, queryByRole } = render (
88+ < Accordion >
89+ < AccordionItem >
90+ < AccordionItemPanel > Hello World</ AccordionItemPanel >
91+ </ AccordionItem >
92+ </ Accordion > ,
93+ ) ;
94+ expect ( queryByRole ( 'region' ) ) . toBeNull ( ) ;
95+ expect (
96+ getByText ( 'Hello World' ) . getAttribute ( 'aria-labelledby' ) ,
97+ ) . toBeFalsy ( ) ;
98+ } ) ;
99+
100+ it ( 'disables aria-labelledby when false' , ( ) => {
101+ const { getByText, queryByRole } = render (
102+ < Accordion >
103+ < AccordionItem >
104+ < AccordionItemPanel region = { false } > Hello World</ AccordionItemPanel >
105+ </ AccordionItem >
106+ </ Accordion > ,
107+ ) ;
108+ expect ( queryByRole ( 'region' ) ) . toBeNull ( ) ;
109+ expect (
110+ getByText ( 'Hello World' ) . getAttribute ( 'aria-labelledby' ) ,
111+ ) . toBeFalsy ( ) ;
112+ } ) ;
113+ } ) ;
69114} ) ;
Original file line number Diff line number Diff line change @@ -3,10 +3,11 @@ import { DivAttributes } from '../helpers/types';
33import { assertValidHtmlId } from '../helpers/uuid' ;
44import { Consumer as ItemConsumer , ItemContext } from './ItemContext' ;
55
6- type Props = DivAttributes & { className ?: string } ;
6+ type Props = DivAttributes & { region ?: boolean ; className ?: string } ;
77
88const AccordionItemPanel = ( {
99 className = 'accordion__panel' ,
10+ region,
1011 id,
1112 ...rest
1213} : Props ) : JSX . Element => {
@@ -15,12 +16,19 @@ const AccordionItemPanel = ({
1516 assertValidHtmlId ( id ) ;
1617 }
1718
19+ const attrs = {
20+ ...panelAttributes ,
21+ 'aria-labelledby' : region ? panelAttributes [ 'aria-labelledby' ] : undefined ,
22+ } ;
23+ console . log ( region )
24+
1825 return (
1926 < div
2027 data-accordion-component = "AccordionItemPanel"
2128 className = { className }
2229 { ...rest }
23- { ...panelAttributes }
30+ { ...attrs }
31+ role = { region ? 'region' : undefined }
2432 />
2533 ) ;
2634 } ;
You can’t perform that action at this time.
0 commit comments