Skip to content

Commit 9604a8d

Browse files
authored
Merge pull request salesforce#1445 from garygong/assistive-text2
Consolidate assistiveText props under one object [AppLauncherSection, Avatar, Breadcrumb, ButtonStateful, Button, GlobalHeader, GlobalNavigationBarDropdown]
2 parents d64268f + ced0ba5 commit 9604a8d

File tree

75 files changed

+544
-221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+544
-221
lines changed

components/accordion/__examples__/base.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Example extends React.Component {
3434
<Dropdown
3535
align="right"
3636
id="ButtonGroupExampleDropdown"
37-
assistiveText="More Options"
37+
assistiveText={{ icon: 'More Options' }}
3838
buttonVariant="icon"
3939
buttonClassName="slds-shrink-none"
4040
iconCategory="utility"

components/alert/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class Alert extends React.Component {
192192
</h2>
193193
{this.props.dismissible ? (
194194
<Button
195-
assistiveText={assistiveText.closeButton}
195+
assistiveText={{ icon: assistiveText.closeButton }}
196196
buttonRef={this.saveButtonRef}
197197
className="slds-notify__close"
198198
iconCategory="utility"

components/app-launcher/__docs__/storybook-stories.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ const DemoAppLauncherSection = createReactClass({
199199
return (
200200
<div>
201201
<AppLauncherSection
202+
assistiveText={{ collapseSection: 'Collapse Section' }}
202203
title="All Items"
203204
toggleable
204205
onToggleClick={action('Section `All Items` open -->')}

components/app-launcher/__tests__/section.browser-test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('SLDS APP LAUNCHER SECTION *******************************************'
4949
onToggleClick = sinon.spy();
5050

5151
mountSection({
52-
collapseSectionAssistiveText: 'Collapse Section',
52+
assistiveText: { collapseSection: 'Collapse Section' },
5353
onToggleClick,
5454
title: 'ALL THE ITEMS!',
5555
toggleable: true,

components/app-launcher/check-props.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,31 @@
44

55
import deprecatedProperty from '../../utilities/warning/deprecated-property';
66
import oneOfComponent from '../../utilities/warning/one-of-component';
7+
import { APP_LAUNCHER, APP_LAUNCHER_SECTION } from '../../utilities/constants';
78

89
let checkProps = function () {};
910

1011
if (process.env.NODE_ENV !== 'production') {
1112
checkProps = function (COMPONENT, props) {
12-
if (props.modalHeaderButton !== undefined) {
13-
oneOfComponent(COMPONENT, props, 'modalHeaderButton', ['SLDSButton']);
14-
}
13+
if (COMPONENT === APP_LAUNCHER) {
14+
if (props.modalHeaderButton !== undefined) {
15+
oneOfComponent(COMPONENT, props, 'modalHeaderButton', ['SLDSButton']);
16+
}
1517

16-
deprecatedProperty(
17-
COMPONENT,
18-
props.triggerAssistiveText,
19-
'triggerAssistiveText',
20-
"assistiveText['trigger']"
21-
);
18+
deprecatedProperty(
19+
COMPONENT,
20+
props.triggerAssistiveText,
21+
'triggerAssistiveText',
22+
"assistiveText['trigger']"
23+
);
24+
} else if (COMPONENT === APP_LAUNCHER_SECTION) {
25+
deprecatedProperty(
26+
COMPONENT,
27+
props.collapseSectionAssistiveText,
28+
'collapseSectionAssistiveText',
29+
"assistiveText['collapseSection']"
30+
);
31+
}
2232
};
2333
}
2434

components/app-launcher/section.jsx

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,21 @@ import isFunction from 'lodash.isfunction';
1919
// A simple javascript utility for conditionally joining classNames together.
2020
import classNames from 'classnames';
2121

22+
// This component's `checkProps` which issues warnings to developers about properties when in development mode (similar to React's built in development tools)
23+
import checkProps from './check-props';
24+
2225
// ## Children
2326
import Button from '../button';
2427

2528
// ## Constants
2629
import { APP_LAUNCHER_SECTION } from '../../utilities/constants';
2730

31+
const defaultProps = {
32+
assistiveText: {
33+
collapseSection: 'Toggle visibility of section',
34+
},
35+
};
36+
2837
/**
2938
* App Launcher Sections allow users to categorize App Tiles as well as toggle their display
3039
*/
@@ -35,6 +44,14 @@ const AppLauncherSection = createReactClass({
3544

3645
// ### Prop Types
3746
propTypes: {
47+
/**
48+
* **Assistive text for accessibility.**
49+
* This object is merged with the default props object on every render.
50+
* * `collapseSection`: The assistive text for the section collapse icons.
51+
*/
52+
assistiveText: PropTypes.shape({
53+
collapseSection: PropTypes.string,
54+
}),
3855
/**
3956
* The title for this section of apps
4057
*/
@@ -43,10 +60,6 @@ const AppLauncherSection = createReactClass({
4360
* Allows the user to show/hide the section
4461
*/
4562
toggleable: PropTypes.bool,
46-
/**
47-
* The assistive text for the section collapse icons
48-
*/
49-
collapseSectionAssistiveText: PropTypes.string,
5063
/**
5164
* An array of applications to display
5265
*/
@@ -62,9 +75,7 @@ const AppLauncherSection = createReactClass({
6275
},
6376

6477
getDefaultProps () {
65-
return {
66-
collapseSectionAssistiveText: 'Toggle visibility of section',
67-
};
78+
return defaultProps;
6879
},
6980

7081
getInitialState () {
@@ -73,6 +84,10 @@ const AppLauncherSection = createReactClass({
7384
};
7485
},
7586

87+
componentWillMount () {
88+
checkProps(APP_LAUNCHER_SECTION, this.props);
89+
},
90+
7691
toggleOpen (event) {
7792
this.setState({ isOpen: !this.state.isOpen });
7893

@@ -88,13 +103,21 @@ const AppLauncherSection = createReactClass({
88103
const sectionIsOpenClass = isOpen
89104
? 'slds-is-expanded'
90105
: 'slds-is-collapsed';
106+
const assistiveText = {
107+
...defaultProps.assistiveText,
108+
...this.props.assistiveText,
109+
};
91110

92111
return (
93112
<div className={classNames('slds-section', iconIsOpenClass)}>
94113
<div className="slds-section__title">
95114
{this.props.toggleable || this.props.onToggleClick ? (
96115
<Button
97-
assistiveText={this.props.collapseSectionAssistiveText}
116+
assistiveText={{
117+
icon:
118+
this.props.collapseSectionAssistiveText ||
119+
assistiveText.collapseSection,
120+
}}
98121
iconCategory="utility"
99122
iconName="switch"
100123
onClick={this.toggleOpen}

components/avatar/__examples__/base.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const Example = createReactClass({
1010
return (
1111
<IconSettings iconPath="/assets/icons">
1212
<Avatar
13-
assistiveText="Avatar image"
13+
assistiveText={{ icon: 'Avatar image' }}
1414
imgSrc="https://lightningdesignsystem.com/assets/images/avatar2.jpg"
1515
imgAlt="Person Name"
1616
/>

components/avatar/__examples__/entity-icon.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const Example = createReactClass({
1010
return (
1111
<IconSettings iconPath="/assets/icons">
1212
<Avatar
13-
assistiveText="Account icon avatar"
13+
assistiveText={{ icon: 'Avatar icon avatar' }}
1414
title="Avatar entity icon"
1515
variant="entity"
1616
/>

components/avatar/__examples__/user-icon.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const Example = createReactClass({
1010
return (
1111
<IconSettings iconPath="/assets/icons">
1212
<Avatar
13-
assistiveText="User Icon Avatar"
13+
assistiveText={{ icon: 'User Icon Avatar' }}
1414
title="User Icon Avatar"
1515
variant="user"
1616
/>

components/avatar/__tests__/__snapshots__/avatar.snapshot-test.jsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ exports[`Avatar Entity Icon Snapshot 1`] = `
3434
<span
3535
className="slds-assistive-text"
3636
>
37-
Account icon avatar
37+
Avatar icon avatar
3838
</span>
3939
</span>
4040
</span>

components/avatar/check-props.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 sunsetProperty from '../../utilities/warning/sunset-property';
6+
7+
let checkProps = function () {};
8+
9+
if (process.env.NODE_ENV !== 'production') {
10+
checkProps = function (COMPONENT, props) {
11+
if (typeof props.assistiveText === 'string') {
12+
sunsetProperty(
13+
COMPONENT,
14+
props.assistiveText,
15+
'assistiveText',
16+
'`assistiveText` as a string has been deprecated and is now an object to allow for multiple uses in the component. Please use `assistiveText.icon` instead.'
17+
);
18+
}
19+
};
20+
}
21+
22+
export default checkProps;

components/avatar/index.jsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
// ### React
99
import React from 'react';
1010
import PropTypes from 'prop-types';
11+
12+
// This component's `checkProps` which issues warnings to developers about properties when in development mode (similar to React's built in development tools)
13+
import checkProps from './check-props';
14+
1115
// ### classNames
1216
// [github.com/JedWatson/classnames](https://github.com/JedWatson/classnames) A
1317
// simple javascript utility for conditionally joining classNames together.
@@ -22,9 +26,13 @@ const displayName = AVATAR;
2226
// ### Prop Types
2327
const propTypes = {
2428
/**
25-
* Assistive text for accessibility that labels the icon.
29+
* **Assistive text for accessibility.**
30+
* This object is merged with the default props object on every render.
31+
* * `icon`: Assistive text for accessibility that labels the icon.
2632
*/
27-
assistiveText: PropTypes.string,
33+
assistiveText: PropTypes.shape({
34+
icon: PropTypes.string,
35+
}),
2836
/**
2937
* Class names to be applied to Avatar component.
3038
*/
@@ -60,6 +68,9 @@ const propTypes = {
6068
};
6169

6270
const defaultProps = {
71+
assistiveText: {
72+
icon: 'User or Account Icon',
73+
},
6374
imgAlt: '',
6475
size: 'medium',
6576
title: 'user avatar',
@@ -84,6 +95,10 @@ class Avatar extends React.Component {
8495
};
8596
}
8697

98+
componentWillMount () {
99+
checkProps(AVATAR, this.props);
100+
}
101+
87102
buildInitials () {
88103
const { label } = this.props;
89104
const name = label.trim();
@@ -114,10 +129,17 @@ class Avatar extends React.Component {
114129
}
115130

116131
renderIconAvatar () {
117-
const { assistiveText, variant } = this.props;
132+
const { variant } = this.props;
133+
const iconAssistiveText =
134+
typeof this.props.assistiveText === 'string'
135+
? this.props.assistiveText
136+
: {
137+
...defaultProps.assistiveText,
138+
...this.props.assistiveText,
139+
}.icon;
118140
return (
119141
<UtilityIcon
120-
assistiveText={assistiveText || 'User or Account Icon'}
142+
assistiveText={iconAssistiveText}
121143
category="standard"
122144
name={variant === 'entity' ? 'account' : 'user'}
123145
/>

components/breadcrumb/__examples__/base.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ const Example = createReactClass({
1616

1717
return (
1818
<IconSettings iconPath="/assets/icons">
19-
<BreadCrumb trail={trail} />
19+
<BreadCrumb
20+
assistiveText={{ label: 'Two item breadcrumb' }}
21+
trail={trail}
22+
/>
2023
</IconSettings>
2124
);
2225
},

components/breadcrumb/__tests__/__snapshots__/bread-crumb.snapshot-test.jsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`Breadcrumb Base Snapshot 1`] = `
44
<nav
5-
aria-label="Breadcrumbs"
5+
aria-label="Two item breadcrumb"
66
role="navigation"
77
>
88
<ol

components/breadcrumb/check-props.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 sunsetProperty from '../../utilities/warning/sunset-property';
6+
7+
let checkProps = function () {};
8+
9+
if (process.env.NODE_ENV !== 'production') {
10+
checkProps = function (COMPONENT, props) {
11+
if (typeof props.assistiveText === 'string') {
12+
sunsetProperty(
13+
COMPONENT,
14+
props.assistiveText,
15+
'assistiveText',
16+
'`assistiveText` as a string has been deprecated and is now an object to allow for multiple uses in the component. Please use `assistiveText.label` instead.'
17+
);
18+
}
19+
};
20+
}
21+
22+
export default checkProps;

components/breadcrumb/index.jsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,32 @@
1414
import React from 'react';
1515
import PropTypes from 'prop-types';
1616

17+
// This component's `checkProps` which issues warnings to developers about properties when in development mode (similar to React's built in development tools)
18+
import checkProps from './check-props';
19+
1720
// ## Constants
1821
import { BREADCRUMB } from '../../utilities/constants';
1922

23+
const defaultProps = {
24+
assistiveText: {
25+
label: 'Breadcrumbs',
26+
},
27+
};
28+
2029
/**
2130
* Use breadcrumbs to note the path of a record and help the user to navigate back to the parent.Breadcrumb based on SLDS 2.1.0-dev
2231
*/
2332
const Breadcrumb = (props) => {
24-
const { assistiveText, trail } = props;
33+
checkProps(BREADCRUMB, props);
34+
35+
const { trail } = props;
36+
const assistiveText =
37+
typeof props.assistiveText === 'string'
38+
? props.assistiveText
39+
: {
40+
...defaultProps.assistiveText,
41+
...props.assistiveText,
42+
}.label;
2543

2644
return (
2745
<nav role="navigation" aria-label={assistiveText}>
@@ -44,17 +62,19 @@ Breadcrumb.displayName = BREADCRUMB;
4462

4563
Breadcrumb.propTypes = {
4664
/**
47-
* The assistive text for the breadcrumb trail
65+
* **Assistive text for accessibility.**
66+
* This object is merged with the default props object on every render.
67+
* * `label`: The assistive text for the breadcrumb trail.
4868
*/
49-
assistiveText: PropTypes.string,
69+
assistiveText: PropTypes.shape({
70+
label: PropTypes.string,
71+
}),
5072
/**
5173
* An array of react elements presumably anchor elements.
5274
*/
5375
trail: PropTypes.array,
5476
};
5577

56-
Breadcrumb.defaultProps = {
57-
assistiveText: 'Breadcrumbs',
58-
};
78+
Breadcrumb.defaultProps = defaultProps;
5979

6080
export default Breadcrumb;

0 commit comments

Comments
 (0)