Skip to content

Commit

Permalink
[fixed] Accessibility: Panel header uses aria-controls
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Jun 18, 2015
1 parent 1e552cc commit ccc50e0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ const Panel = React.createClass({
return (
<a
href={'#' + (this.props.id || '')}
aria-controls={this.props.collapsible ? this.props.id : null}
className={this.isExpanded() ? null : 'collapsed'}
aria-expanded={this.isExpanded() ? 'true' : 'false'}
onClick={this.handleSelect}>
Expand Down
56 changes: 36 additions & 20 deletions test/PanelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,6 @@ describe('Panel', function () {
assert.ok(anchor.className.match(/\bcollapsed\b/));
});

it('Should be aria-expanded=true', function () {
let instance = ReactTestUtils.renderIntoDocument(
<Panel collapsible={true} expanded={true} header="Heading">Panel content</Panel>
);
let collapse = React.findDOMNode(instance).querySelector('.panel-collapse');
let anchor = React.findDOMNode(instance).querySelector('.panel-title a');
assert.equal(collapse.getAttribute('aria-expanded'), 'true');
assert.equal(anchor.getAttribute('aria-expanded'), 'true');
});

it('Should be aria-expanded=false', function () {
let instance = ReactTestUtils.renderIntoDocument(
<Panel collapsible={true} expanded={false} header="Heading">Panel content</Panel>
);
let collapse = React.findDOMNode(instance).querySelector('.panel-collapse');
let anchor = React.findDOMNode(instance).querySelector('.panel-title a');
assert.equal(collapse.getAttribute('aria-expanded'), 'false');
assert.equal(anchor.getAttribute('aria-expanded'), 'false');
});

it('Should call onSelect handler', function (done) {
function handleSelect (e, key) {
assert.equal(key, '1');
Expand Down Expand Up @@ -204,4 +184,40 @@ describe('Panel', function () {
assert.equal(children[0].nodeName, 'TABLE');
assert.notOk(children[0].className.match(/\bpanel-body\b/));
});

describe('Web Accessibility', function(){

it('Should be aria-expanded=true', function () {
let instance = ReactTestUtils.renderIntoDocument(
<Panel collapsible={true} expanded={true} header="Heading">Panel content</Panel>
);
let collapse = React.findDOMNode(instance).querySelector('.panel-collapse');
let anchor = React.findDOMNode(instance).querySelector('.panel-title a');
assert.equal(collapse.getAttribute('aria-expanded'), 'true');
assert.equal(anchor.getAttribute('aria-expanded'), 'true');
});

it('Should be aria-expanded=false', function () {
let instance = ReactTestUtils.renderIntoDocument(
<Panel collapsible={true} expanded={false} header="Heading">Panel content</Panel>
);
let collapse = React.findDOMNode(instance).querySelector('.panel-collapse');
let anchor = React.findDOMNode(instance).querySelector('.panel-title a');
assert.equal(collapse.getAttribute('aria-expanded'), 'false');
assert.equal(anchor.getAttribute('aria-expanded'), 'false');
});

it('Should add aria-controls with id', function () {
let instance = ReactTestUtils.renderIntoDocument(
<Panel id='panel-1' collapsible expanded header="Heading">Panel content</Panel>
);

let collapse = React.findDOMNode(instance).querySelector('.panel-collapse');
let anchor = React.findDOMNode(instance).querySelector('.panel-title a');

assert.equal(collapse.getAttribute('id'), 'panel-1');
assert.equal(anchor.getAttribute('aria-controls'), 'panel-1');
});

});
});

0 comments on commit ccc50e0

Please sign in to comment.