Skip to content

Commit a2c38cc

Browse files
wszgxadiasbruno
authored andcommitted
[fixed] set default role for accessibility
1 parent 921358e commit a2c38cc

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

Diff for: docs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ import ReactModal from 'react-modal';
9999
shouldReturnFocusAfterClose={true}
100100
/*
101101
String indicating the role of the modal, allowing the 'dialog' role to be applied if desired.
102+
This attribute is `dialog` by default.
102103
*/
103104
role="dialog"
104105
/*

Diff for: specs/Modal.spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ export default () => {
117117
contentAttribute(modal, "role").should.be.eql("dialog");
118118
});
119119

120+
// eslint-disable-next-line max-len
121+
it("renders the modal content with the default aria role when not provided", () => {
122+
const child = "I am a child of Modal, and he has sent me here...";
123+
const modal = renderModal({ isOpen: true }, child);
124+
contentAttribute(modal, "role").should.be.eql("dialog");
125+
});
126+
127+
it("does not render the aria role when provided role with null", () => {
128+
const child = "I am a child of Modal, and he has sent me here...";
129+
const modal = renderModal({ isOpen: true, role: null }, child);
130+
should(contentAttribute(modal, "role")).be.eql(null);
131+
});
132+
120133
it("sets aria-label based on the contentLabel prop", () => {
121134
const child = "I am a child of Modal, and he has sent me here...";
122135
const modal = renderModal(

Diff for: src/components/Modal.js

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class Modal extends Component {
7373
isOpen: false,
7474
portalClassName,
7575
bodyOpenClassName,
76+
role: "dialog",
7677
ariaHideApp: true,
7778
closeTimeoutMS: 0,
7879
shouldFocusAfterRender: true,

0 commit comments

Comments
 (0)