-
Notifications
You must be signed in to change notification settings - Fork 435
Add warning when Settings.setAppElement is not set. #1460
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
interactivellama
merged 1 commit into
salesforce:master
from
davidlygagnon:david.lygagnon/warning_setAppElement
Jul 25, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ import shortid from 'shortid'; | |
// This component's `checkProps` which issues warnings to developers about properties when in development mode (similar to React's built in development tools) | ||
import checkProps from './check-props'; | ||
|
||
import checkAppElementIsSet from '../../utilities/warning/check-app-element-set'; | ||
|
||
import Button from '../button'; | ||
|
||
import { MODAL } from '../../utilities/constants'; | ||
|
@@ -33,6 +35,10 @@ const propTypes = { | |
* Vertical alignment of Modal. | ||
*/ | ||
align: PropTypes.oneOf(['top', 'center']), | ||
/** | ||
* Boolean indicating if the appElement should be hidden. | ||
*/ | ||
ariaHideApp: PropTypes.bool, | ||
/** | ||
* **Assistive text for accessibility.** | ||
* This object is merged with the default props object on every render. | ||
|
@@ -150,6 +156,7 @@ const defaultProps = { | |
closeButton: 'Close', | ||
}, | ||
align: 'center', | ||
ariaHideApp: true, | ||
dismissible: true, | ||
}; | ||
|
||
|
@@ -181,6 +188,9 @@ class Modal extends React.Component { | |
componentWillMount () { | ||
this.generatedId = shortid.generate(); | ||
checkProps(MODAL, this.props); | ||
if (this.props.ariaHideApp) { | ||
checkAppElementIsSet(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If consumer hasn't opted-out, check if the app element was set. The app-launcher component also uses this modal internally so I only need to add this check here. |
||
} | ||
} | ||
|
||
componentDidMount () { | ||
|
@@ -450,6 +460,7 @@ class Modal extends React.Component { | |
|
||
return ( | ||
<ReactModal | ||
ariaHideApp={this.props.ariaHideApp} | ||
contentLabel="Modal" | ||
isOpen={this.props.isOpen} | ||
onRequestClose={this.closeModal} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */ | ||
/* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */ | ||
/* eslint-disable import/no-mutable-exports */ | ||
|
||
import warning from 'warning'; | ||
import Settings from '../../components/settings'; | ||
|
||
let checkAppElementIsSet = function () {}; | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
checkAppElementIsSet = function () { | ||
const appElement = Settings.getAppElement(); | ||
/* eslint-disable max-len */ | ||
warning( | ||
!!appElement, | ||
'[Design System React] App element is not defined. Please use Settings.setAppElement(el).' + | ||
' By default, `Modal` will add `aria-hidden=true` to the `body` tag, but this disables some assistive technologies.' + | ||
' To prevent this you can add Settings.setAppElement(el) to your application with `el` being the root node of your application' + | ||
' that you would like to hide from assistive technologies when the `Modal` is open.' | ||
); | ||
}; | ||
} | ||
|
||
export default checkAppElementIsSet; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React modal has this prop to "opt out" of setAppElement. I think we should use that as well.