Skip to content

Commit

Permalink
[added] Accessibility: role 'alert' and aria-label to Alert component
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Jun 18, 2015
1 parent 3423e70 commit 4adaa70
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ const Alert = React.createClass({

propTypes: {
onDismiss: React.PropTypes.func,
dismissAfter: React.PropTypes.number
dismissAfter: React.PropTypes.number,
closeLabel: React.PropTypes.string
},

getDefaultProps() {
return {
bsClass: 'alert',
bsStyle: 'info'
bsStyle: 'info',
closeLabel: 'Close Alert'
};
},

Expand All @@ -22,9 +24,9 @@ const Alert = React.createClass({
<button
type="button"
className="close"
onClick={this.props.onDismiss}
aria-hidden="true">
&times;
aria-label={this.props.closeLabel}
onClick={this.props.onDismiss}>
<span aria-hidden="true">&times;</span>
</button>
);
},
Expand All @@ -36,7 +38,7 @@ const Alert = React.createClass({
classes['alert-dismissable'] = isDismissable;

return (
<div {...this.props} className={classNames(this.props.className, classes)}>
<div {...this.props} role='alert' className={classNames(this.props.className, classes)}>
{isDismissable ? this.renderDismissButton() : null}
{this.props.children}
</div>
Expand Down
22 changes: 22 additions & 0 deletions test/AlertSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,26 @@ describe('Alert', function () {
);
assert.ok(React.findDOMNode(instance).className.match(/\balert-danger\b/));
});

describe('Web Accessibility', function(){
it('Should have alert role', function () {
let instance = ReactTestUtils.renderIntoDocument(
<Alert>Message</Alert>
);

assert.equal(React.findDOMNode(instance).getAttribute('role'), 'alert');
});

it('Should have add ARIAs to button', function () {
let instance = ReactTestUtils.renderIntoDocument(
<Alert onDismiss={()=>{}} closeLabel='close'>Message</Alert>
);

let button = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'button');

assert.equal(React.findDOMNode(button).getAttribute('aria-label'), 'close');
assert.equal(React.findDOMNode(button).children[0].getAttribute('aria-hidden'), 'true');
});

});
});

0 comments on commit 4adaa70

Please sign in to comment.