From a2c38cc1032500ac697bf1d1d68dbb256b7fb097 Mon Sep 17 00:00:00 2001 From: hiluluke Date: Mon, 27 Aug 2018 19:27:01 +0800 Subject: [PATCH] [fixed] set default role for accessibility --- docs/README.md | 1 + specs/Modal.spec.js | 13 +++++++++++++ src/components/Modal.js | 1 + 3 files changed, 15 insertions(+) diff --git a/docs/README.md b/docs/README.md index ab274454..bdefa05a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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" /* diff --git a/specs/Modal.spec.js b/specs/Modal.spec.js index 5fd1b1c2..d008dbf0 100644 --- a/specs/Modal.spec.js +++ b/specs/Modal.spec.js @@ -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( diff --git a/src/components/Modal.js b/src/components/Modal.js index 550cff12..7a9a959b 100644 --- a/src/components/Modal.js +++ b/src/components/Modal.js @@ -73,6 +73,7 @@ class Modal extends Component { isOpen: false, portalClassName, bodyOpenClassName, + role: "dialog", ariaHideApp: true, closeTimeoutMS: 0, shouldFocusAfterRender: true,