Skip to content

Commit 20f6efe

Browse files
committed
[added] Add contentLabel prop to put aria-label on modal content
This makes the modal better follow aria guidelines for dialogs. It also gives screenreader users some identity for the modal after it opens. closes #236
1 parent d78428b commit 20f6efe

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

lib/components/Modal.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ var Modal = React.createClass({
3737
closeTimeoutMS: React.PropTypes.number,
3838
ariaHideApp: React.PropTypes.bool,
3939
shouldCloseOnOverlayClick: React.PropTypes.bool,
40-
role: React.PropTypes.string
40+
role: React.PropTypes.string,
41+
contentLabel: React.PropTypes.string.isRequired
4142
},
4243

4344
getDefaultProps: function () {

lib/components/ModalPortal.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ var ModalPortal = module.exports = React.createClass({
202202
onKeyDown: this.handleKeyDown,
203203
onMouseDown: this.handleContentMouseDown,
204204
onMouseUp: this.handleContentMouseUp,
205-
role: this.props.role
205+
role: this.props.role,
206+
"aria-label": this.props.contentLabel
206207
},
207208
this.props.children
208209
)

specs/Modal.spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ describe('Modal', function () {
6565
unmountModal();
6666
});
6767

68+
it('renders the modal with a aria-label based on the contentLabel prop', function () {
69+
var child = 'I am a child of Modal, and he has sent me here...';
70+
var component = renderModal({isOpen: true, contentLabel: 'Special Modal'}, child);
71+
equal(component.portal.refs.content.getAttribute('aria-label'), 'Special Modal');
72+
unmountModal();
73+
});
74+
6875
it('has default props', function() {
6976
var node = document.createElement('div');
7077
Modal.setAppElement(document.createElement('div'));

0 commit comments

Comments
 (0)