Skip to content

Commit

Permalink
bug: fix accessibility warning when open a Modal
Browse files Browse the repository at this point in the history
add the following code:

  componentWillMount() {
    Modal.setAppElement('body');
  }

To prevent this accessibility warning in the console, whenever the Modal opens,

> Warning: react-modal: App element is not defined. Please use `Modal.
	setAppElement(el)` or `set appElement={el}`. This is needed so
	screen readers don't see main content when modal is opened. It is
	not recommended, but you can opt-out by setting `ariaHideApp={false}`

react-modal issue-133 describes the issue, and solutions are provided
	in the discussion:
	reactjs/react-modal#133
I also summarized these solutions on StackOverflow:
	https://stackoverflow.com/questions/48269381/warning-react-modal-app-element-is-not-defined-please-use-modal-setappeleme/48270342#48270342
And submitted github-issue/waffle item to Udacity:
	https://github.com/udacity/reactnd-issues/issues/233
Also in the process to updating the documents so I can submit a PR to
	for related issue-576:
	reactjs/react-modal#576
  • Loading branch information
SherylHohman committed Jan 15, 2018
1 parent 02e10b2 commit e723abc
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class App extends Component {
ingredientsModalOpen: false,
}

componentWillMount() {
Modal.setAppElement('body');
}

openFoodModal = ({ meal, day }) => {
this.setState(() => ({
foodModalOpen: true,
Expand Down

0 comments on commit e723abc

Please sign in to comment.