Skip to content

[added] Add contentLabel prop to put aria-label on modal content #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ npm install --save react-modal
onRequestClose={requestCloseFn}
closeTimeoutMS={n}
style={customStyle}
contentLabel="Modal"
>
<h1>Modal Content</h1>
<p>Etc.</p>
Expand Down Expand Up @@ -136,7 +137,9 @@ var App = React.createClass({
isOpen={this.state.modalIsOpen}
onAfterOpen={this.afterOpenModal}
onRequestClose={this.closeModal}
style={customStyles} >
style={customStyles}
contentLabel="Example Modal"
>

<h2 ref="subtitle">Hello</h2>
<button onClick={this.closeModal}>close</button>
Expand Down Expand Up @@ -171,7 +174,9 @@ pass the 'shouldCloseOnOverlayClick' prop with 'false' value.
onRequestClose={requestCloseFn}
closeTimeoutMS={n}
shouldCloseOnOverlayClick={false}
style={customStyle}>
style={customStyle}
contentLabel="No Overlay Click Modal"
>

<h1>Force Modal</h1>
<p>Modal cannot be closed when clicking the overlay area</p>
Expand Down
3 changes: 2 additions & 1 deletion lib/components/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ var Modal = React.createClass({
closeTimeoutMS: React.PropTypes.number,
ariaHideApp: React.PropTypes.bool,
shouldCloseOnOverlayClick: React.PropTypes.bool,
role: React.PropTypes.string
role: React.PropTypes.string,
contentLabel: React.PropTypes.string.isRequired
},

getDefaultProps: function () {
Expand Down
3 changes: 2 additions & 1 deletion lib/components/ModalPortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ var ModalPortal = module.exports = React.createClass({
onKeyDown: this.handleKeyDown,
onMouseDown: this.handleContentMouseDown,
onMouseUp: this.handleContentMouseUp,
role: this.props.role
role: this.props.role,
"aria-label": this.props.contentLabel
},
this.props.children
)
Expand Down
7 changes: 7 additions & 0 deletions specs/Modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ describe('Modal', function () {
unmountModal();
});

it('renders the modal with a aria-label based on the contentLabel prop', function () {
var child = 'I am a child of Modal, and he has sent me here...';
var component = renderModal({isOpen: true, contentLabel: 'Special Modal'}, child);
equal(component.portal.refs.content.getAttribute('aria-label'), 'Special Modal');
unmountModal();
});

it('has default props', function() {
var node = document.createElement('div');
Modal.setAppElement(document.createElement('div'));
Expand Down