Skip to content

Commit 6e310b0

Browse files
Merge pull request salesforce#1460 from davidlygagnon/david.lygagnon/warning_setAppElement
Add warning when Settings.setAppElement is not set.
2 parents 4e26336 + 2ed4208 commit 6e310b0

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

components/app-launcher/index.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const defaultProps = {
3131
assistiveText: {
3232
trigger: 'Open App Launcher',
3333
},
34+
ariaHideApp: true,
3435
title: 'App Launcher',
3536
};
3637

@@ -82,6 +83,10 @@ const AppLauncher = createReactClass({
8283
assistiveText: PropTypes.shape({
8384
trigger: PropTypes.string,
8485
}),
86+
/**
87+
* Boolean indicating if the appElement should be hidden.
88+
*/
89+
ariaHideApp: PropTypes.bool,
8590
/**
8691
* One or more `<AppLauncherSection />`s each containing one or more `<AppLauncherTile />`s
8792
*/
@@ -248,6 +253,7 @@ const AppLauncher = createReactClass({
248253
</button>
249254
</div>
250255
<Modal
256+
ariaHideApp={this.props.ariaHideApp}
251257
contentClassName="slds-modal__content slds-app-launcher__content slds-p-around--medium"
252258
contentStyle={{ minHeight: modalContentStaticHeight }}
253259
isOpen={isOpen}

components/component-docs.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,17 @@
374374
"computed": false
375375
}
376376
},
377+
"ariaHideApp": {
378+
"type": {
379+
"name": "bool"
380+
},
381+
"required": false,
382+
"description": "Boolean indicating if the appElement should be hidden. _Tested with snapshot testing._",
383+
"defaultValue": {
384+
"value": "true",
385+
"computed": false
386+
}
387+
},
377388
"children": {
378389
"type": {
379390
"name": "node"
@@ -7321,6 +7332,17 @@
73217332
"computed": false
73227333
}
73237334
},
7335+
"ariaHideApp": {
7336+
"type": {
7337+
"name": "bool"
7338+
},
7339+
"required": false,
7340+
"description": "Boolean indicating if the appElement should be hidden. _Tested with snapshot testing._",
7341+
"defaultValue": {
7342+
"value": "true",
7343+
"computed": false
7344+
}
7345+
},
73247346
"assistiveText": {
73257347
"type": {
73267348
"name": "shape",

components/modal/index.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import shortid from 'shortid';
2424
// This component's `checkProps` which issues warnings to developers about properties when in development mode (similar to React's built in development tools)
2525
import checkProps from './check-props';
2626

27+
import checkAppElementIsSet from '../../utilities/warning/check-app-element-set';
28+
2729
import Button from '../button';
2830

2931
import { MODAL } from '../../utilities/constants';
@@ -33,6 +35,10 @@ const propTypes = {
3335
* Vertical alignment of Modal.
3436
*/
3537
align: PropTypes.oneOf(['top', 'center']),
38+
/**
39+
* Boolean indicating if the appElement should be hidden.
40+
*/
41+
ariaHideApp: PropTypes.bool,
3642
/**
3743
* **Assistive text for accessibility.**
3844
* This object is merged with the default props object on every render.
@@ -150,6 +156,7 @@ const defaultProps = {
150156
closeButton: 'Close',
151157
},
152158
align: 'center',
159+
ariaHideApp: true,
153160
dismissible: true,
154161
};
155162

@@ -181,6 +188,9 @@ class Modal extends React.Component {
181188
componentWillMount () {
182189
this.generatedId = shortid.generate();
183190
checkProps(MODAL, this.props);
191+
if (this.props.ariaHideApp) {
192+
checkAppElementIsSet();
193+
}
184194
}
185195

186196
componentDidMount () {
@@ -450,6 +460,7 @@ class Modal extends React.Component {
450460

451461
return (
452462
<ReactModal
463+
ariaHideApp={this.props.ariaHideApp}
453464
contentLabel="Modal"
454465
isOpen={this.props.isOpen}
455466
onRequestClose={this.closeModal}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */
2+
/* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */
3+
/* eslint-disable import/no-mutable-exports */
4+
5+
import warning from 'warning';
6+
import Settings from '../../components/settings';
7+
8+
let checkAppElementIsSet = function () {};
9+
10+
if (process.env.NODE_ENV !== 'production') {
11+
checkAppElementIsSet = function () {
12+
const appElement = Settings.getAppElement();
13+
/* eslint-disable max-len */
14+
warning(
15+
!!appElement,
16+
'[Design System React] App element is not defined. Please use Settings.setAppElement(el).' +
17+
' By default, `Modal` will add `aria-hidden=true` to the `body` tag, but this disables some assistive technologies.' +
18+
' To prevent this you can add Settings.setAppElement(el) to your application with `el` being the root node of your application' +
19+
' that you would like to hide from assistive technologies when the `Modal` is open.'
20+
);
21+
};
22+
}
23+
24+
export default checkAppElementIsSet;

0 commit comments

Comments
 (0)