Skip to content

Commit

Permalink
[fixed] only add aria-expanded to Collapse when an ARIA role is present
Browse files Browse the repository at this point in the history
Also remove redundant aria-expanded from Panel collapsible body

Signed-off-by: Kenny Wang <[email protected]>
  • Loading branch information
August Toman-Yih authored and Kenny Wang committed Aug 3, 2015
1 parent a200626 commit c60dc03
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/Collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Collapse extends React.Component {
<Transition
ref='transition'
{...this.props}
aria-expanded={this.props.in}
aria-expanded={this.props.role ? this.props.in : null}
className={this._dimension() === 'width' ? 'width' : ''}
exitedClassName='collapse'
exitingClassName='collapsing'
Expand Down Expand Up @@ -184,7 +184,12 @@ Collapse.propTypes = {
* should animate in its specified dimension. Called with the current
* dimension prop value and the DOM node.
*/
getDimensionValue: React.PropTypes.func
getDimensionValue: React.PropTypes.func,

/**
* ARIA role of collapsible element
*/
role: React.PropTypes.string
};

Collapse.defaultProps = {
Expand Down
3 changes: 1 addition & 2 deletions src/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ const Panel = React.createClass({
<div
className={collapseClass}
id={this.props.id}
ref='panel'
aria-expanded={this.isExpanded()}>
ref='panel'>
{this.renderBody()}

</div>
Expand Down
20 changes: 20 additions & 0 deletions test/CollapseSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,24 @@ describe('Collapse', function () {
assert.equal(instance.collapse._dimension(), 'whatevs');
});
});

describe('with a role', function() {
beforeEach(function(){
instance = ReactTestUtils.renderIntoDocument(
<Component role="note">Panel content</Component>
);
});

it('sets aria-expanded true when expanded', function() {
let node = React.findDOMNode(instance);
instance.setProps({ in: true});
assert.equal(node.getAttribute('aria-expanded'), 'true');
});

it('sets aria-expanded false when collapsed', function() {
let node = React.findDOMNode(instance);
instance.setProps({ in: false});
assert.equal(node.getAttribute('aria-expanded'), 'false');
});
});
});
4 changes: 0 additions & 4 deletions test/PanelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,15 @@ describe('Panel', 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');
});

Expand Down

0 comments on commit c60dc03

Please sign in to comment.