Skip to content

Commit c60dc03

Browse files
August Toman-YihKenny Wang
August Toman-Yih
authored and
Kenny Wang
committed
[fixed] only add aria-expanded to Collapse when an ARIA role is present
Also remove redundant aria-expanded from Panel collapsible body Signed-off-by: Kenny Wang <[email protected]>
1 parent a200626 commit c60dc03

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

src/Collapse.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Collapse extends React.Component {
4848
<Transition
4949
ref='transition'
5050
{...this.props}
51-
aria-expanded={this.props.in}
51+
aria-expanded={this.props.role ? this.props.in : null}
5252
className={this._dimension() === 'width' ? 'width' : ''}
5353
exitedClassName='collapse'
5454
exitingClassName='collapsing'
@@ -184,7 +184,12 @@ Collapse.propTypes = {
184184
* should animate in its specified dimension. Called with the current
185185
* dimension prop value and the DOM node.
186186
*/
187-
getDimensionValue: React.PropTypes.func
187+
getDimensionValue: React.PropTypes.func,
188+
189+
/**
190+
* ARIA role of collapsible element
191+
*/
192+
role: React.PropTypes.string
188193
};
189194

190195
Collapse.defaultProps = {

src/Panel.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ const Panel = React.createClass({
7979
<div
8080
className={collapseClass}
8181
id={this.props.id}
82-
ref='panel'
83-
aria-expanded={this.isExpanded()}>
82+
ref='panel'>
8483
{this.renderBody()}
8584

8685
</div>

test/CollapseSpec.js

+20
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,24 @@ describe('Collapse', function () {
213213
assert.equal(instance.collapse._dimension(), 'whatevs');
214214
});
215215
});
216+
217+
describe('with a role', function() {
218+
beforeEach(function(){
219+
instance = ReactTestUtils.renderIntoDocument(
220+
<Component role="note">Panel content</Component>
221+
);
222+
});
223+
224+
it('sets aria-expanded true when expanded', function() {
225+
let node = React.findDOMNode(instance);
226+
instance.setProps({ in: true});
227+
assert.equal(node.getAttribute('aria-expanded'), 'true');
228+
});
229+
230+
it('sets aria-expanded false when collapsed', function() {
231+
let node = React.findDOMNode(instance);
232+
instance.setProps({ in: false});
233+
assert.equal(node.getAttribute('aria-expanded'), 'false');
234+
});
235+
});
216236
});

test/PanelSpec.js

-4
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,15 @@ describe('Panel', function () {
191191
let instance = ReactTestUtils.renderIntoDocument(
192192
<Panel collapsible={true} expanded={true} header="Heading">Panel content</Panel>
193193
);
194-
let collapse = React.findDOMNode(instance).querySelector('.panel-collapse');
195194
let anchor = React.findDOMNode(instance).querySelector('.panel-title a');
196-
assert.equal(collapse.getAttribute('aria-expanded'), 'true');
197195
assert.equal(anchor.getAttribute('aria-expanded'), 'true');
198196
});
199197

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

0 commit comments

Comments
 (0)