Skip to content

Commit ccc50e0

Browse files
committed
[fixed] Accessibility: Panel header uses aria-controls
1 parent 1e552cc commit ccc50e0

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

Diff for: src/Panel.js

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ const Panel = React.createClass({
176176
return (
177177
<a
178178
href={'#' + (this.props.id || '')}
179+
aria-controls={this.props.collapsible ? this.props.id : null}
179180
className={this.isExpanded() ? null : 'collapsed'}
180181
aria-expanded={this.isExpanded() ? 'true' : 'false'}
181182
onClick={this.handleSelect}>

Diff for: test/PanelSpec.js

+36-20
Original file line numberDiff line numberDiff line change
@@ -123,26 +123,6 @@ describe('Panel', function () {
123123
assert.ok(anchor.className.match(/\bcollapsed\b/));
124124
});
125125

126-
it('Should be aria-expanded=true', function () {
127-
let instance = ReactTestUtils.renderIntoDocument(
128-
<Panel collapsible={true} expanded={true} header="Heading">Panel content</Panel>
129-
);
130-
let collapse = React.findDOMNode(instance).querySelector('.panel-collapse');
131-
let anchor = React.findDOMNode(instance).querySelector('.panel-title a');
132-
assert.equal(collapse.getAttribute('aria-expanded'), 'true');
133-
assert.equal(anchor.getAttribute('aria-expanded'), 'true');
134-
});
135-
136-
it('Should be aria-expanded=false', function () {
137-
let instance = ReactTestUtils.renderIntoDocument(
138-
<Panel collapsible={true} expanded={false} header="Heading">Panel content</Panel>
139-
);
140-
let collapse = React.findDOMNode(instance).querySelector('.panel-collapse');
141-
let anchor = React.findDOMNode(instance).querySelector('.panel-title a');
142-
assert.equal(collapse.getAttribute('aria-expanded'), 'false');
143-
assert.equal(anchor.getAttribute('aria-expanded'), 'false');
144-
});
145-
146126
it('Should call onSelect handler', function (done) {
147127
function handleSelect (e, key) {
148128
assert.equal(key, '1');
@@ -204,4 +184,40 @@ describe('Panel', function () {
204184
assert.equal(children[0].nodeName, 'TABLE');
205185
assert.notOk(children[0].className.match(/\bpanel-body\b/));
206186
});
187+
188+
describe('Web Accessibility', function(){
189+
190+
it('Should be aria-expanded=true', function () {
191+
let instance = ReactTestUtils.renderIntoDocument(
192+
<Panel collapsible={true} expanded={true} header="Heading">Panel content</Panel>
193+
);
194+
let collapse = React.findDOMNode(instance).querySelector('.panel-collapse');
195+
let anchor = React.findDOMNode(instance).querySelector('.panel-title a');
196+
assert.equal(collapse.getAttribute('aria-expanded'), 'true');
197+
assert.equal(anchor.getAttribute('aria-expanded'), 'true');
198+
});
199+
200+
it('Should be aria-expanded=false', function () {
201+
let instance = ReactTestUtils.renderIntoDocument(
202+
<Panel collapsible={true} expanded={false} header="Heading">Panel content</Panel>
203+
);
204+
let collapse = React.findDOMNode(instance).querySelector('.panel-collapse');
205+
let anchor = React.findDOMNode(instance).querySelector('.panel-title a');
206+
assert.equal(collapse.getAttribute('aria-expanded'), 'false');
207+
assert.equal(anchor.getAttribute('aria-expanded'), 'false');
208+
});
209+
210+
it('Should add aria-controls with id', function () {
211+
let instance = ReactTestUtils.renderIntoDocument(
212+
<Panel id='panel-1' collapsible expanded header="Heading">Panel content</Panel>
213+
);
214+
215+
let collapse = React.findDOMNode(instance).querySelector('.panel-collapse');
216+
let anchor = React.findDOMNode(instance).querySelector('.panel-title a');
217+
218+
assert.equal(collapse.getAttribute('id'), 'panel-1');
219+
assert.equal(anchor.getAttribute('aria-controls'), 'panel-1');
220+
});
221+
222+
});
207223
});

0 commit comments

Comments
 (0)