Skip to content

Commit

Permalink
[fixed] set default role for accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
wszgxa authored and diasbruno committed Aug 29, 2018
1 parent 921358e commit a2c38cc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import ReactModal from 'react-modal';
shouldReturnFocusAfterClose={true}
/*
String indicating the role of the modal, allowing the 'dialog' role to be applied if desired.
This attribute is `dialog` by default.
*/
role="dialog"
/*
Expand Down
13 changes: 13 additions & 0 deletions specs/Modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ export default () => {
contentAttribute(modal, "role").should.be.eql("dialog");
});

// eslint-disable-next-line max-len
it("renders the modal content with the default aria role when not provided", () => {
const child = "I am a child of Modal, and he has sent me here...";
const modal = renderModal({ isOpen: true }, child);
contentAttribute(modal, "role").should.be.eql("dialog");
});

it("does not render the aria role when provided role with null", () => {
const child = "I am a child of Modal, and he has sent me here...";
const modal = renderModal({ isOpen: true, role: null }, child);
should(contentAttribute(modal, "role")).be.eql(null);
});

it("sets aria-label based on the contentLabel prop", () => {
const child = "I am a child of Modal, and he has sent me here...";
const modal = renderModal(
Expand Down
1 change: 1 addition & 0 deletions src/components/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Modal extends Component {
isOpen: false,
portalClassName,
bodyOpenClassName,
role: "dialog",
ariaHideApp: true,
closeTimeoutMS: 0,
shouldFocusAfterRender: true,
Expand Down

0 comments on commit a2c38cc

Please sign in to comment.