File tree Expand file tree Collapse file tree 5 files changed +62
-6
lines changed Expand file tree Collapse file tree 5 files changed +62
-6
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 @@ -15,7 +15,7 @@ ReactDOM.render(
1515 < AccordionItemHeading >
1616 < AccordionItemButton > Heading One</ AccordionItemButton >
1717 </ AccordionItemHeading >
18- < AccordionItemPanel >
18+ < AccordionItemPanel region >
1919 Sunt in reprehenderit cillum ex proident qui culpa fugiat
2020 pariatur aliqua nostrud consequat consequat enim quis sit
2121 consectetur ad aute ea ex eiusmod id esse culpa et pariatur
@@ -26,7 +26,7 @@ ReactDOM.render(
2626 < AccordionItemHeading >
2727 < AccordionItemButton > Heading Two</ AccordionItemButton >
2828 </ AccordionItemHeading >
29- < AccordionItemPanel >
29+ < AccordionItemPanel region >
3030 Velit tempor dolore commodo voluptate id do nulla do ut
3131 proident cillum ad cillum voluptate deserunt fugiat ut sed
3232 cupidatat ut consectetur consequat incididunt sed in culpa
@@ -37,7 +37,7 @@ ReactDOM.render(
3737 < AccordionItemHeading >
3838 < AccordionItemButton > Heading Three</ AccordionItemButton >
3939 </ AccordionItemHeading >
40- < AccordionItemPanel >
40+ < AccordionItemPanel region >
4141 Lorem ipsum esse occaecat voluptate duis incididunt amet
4242 eiusmod sunt commodo sunt enim anim ea culpa ut tempor
4343 dolore fugiat exercitation aliquip commodo dolore elit esse
Original file line number Diff line number Diff line change 11{
22 "name" : " react-accessible-accordion" ,
3- "version" : " 3.3.4 " ,
3+ "version" : " 4.0.0 " ,
44 "description" : " Accessible Accordion component for React" ,
55 "main" : " dist/umd/index.js" ,
66 "module" : " dist/es/index.js" ,
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,18 @@ const AccordionItemPanel = ({
1516 assertValidHtmlId ( id ) ;
1617 }
1718
19+ const attrs = {
20+ ...panelAttributes ,
21+ 'aria-labelledby' : region ? panelAttributes [ 'aria-labelledby' ] : undefined ,
22+ } ;
23+
1824 return (
1925 < div
2026 data-accordion-component = "AccordionItemPanel"
2127 className = { className }
2228 { ...rest }
23- { ...panelAttributes }
29+ { ...attrs }
30+ role = { region ? 'region' : undefined }
2431 />
2532 ) ;
2633 } ;
You can’t perform that action at this time.
0 commit comments