Skip to content

Commit e8ada8b

Browse files
committed
Remove {...props} from button DOM node in Button and Stateful Button
1 parent a40910e commit e8ada8b

File tree

5 files changed

+62
-34
lines changed

5 files changed

+62
-34
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# filesystem
1+
22
.DS_Store
33

44
# dependencies
@@ -24,3 +24,5 @@ server/public/assets/bundle
2424
scripts/pre-commit.sh
2525
coverage/
2626
storybook/
27+
28+
.jscsrc

components/button-stateful/index.jsx

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import TooltipTrigger from '../popover-tooltip/trigger';
3232

3333
import { BUTTON_STATEFUL } from '../../utilities/constants';
3434

35-
const blurElement = e => e.currentTarget.blur();
3635

3736
const propTypes = {
3837
/**
@@ -54,15 +53,18 @@ const propTypes = {
5453
* If true, button/icon is white. Meant for buttons or utility icons on dark backgrounds.
5554
*/
5655
inverse: PropTypes.bool,
56+
onBlur: PropTypes.func,
5757
onClick: PropTypes.func,
58+
onFocus: PropTypes.func,
59+
onKeyDown: PropTypes.func,
60+
onKeyPress: PropTypes.func,
61+
onKeyUp: PropTypes.func,
62+
onMouseEnter: PropTypes.func,
63+
onMouseLeave: PropTypes.func,
5864
/**
5965
* If true, button scales to 100% width on small form factors.
6066
*/
6167
responsive: PropTypes.bool,
62-
/**
63-
* Write <code>'-1'</code> if you don't want the user to tab to the button.
64-
*/
65-
tabIndex: PropTypes.string,
6668
/**
6769
* Initial label and icon (optional) of button.
6870
*/
@@ -75,6 +77,10 @@ const propTypes = {
7577
* Deselect label and icon (optional) of button.
7678
*/
7779
stateThree: PropTypes.object,
80+
/**
81+
* Write <code>'-1'</code> if you don't want the user to tab to the button.
82+
*/
83+
tabIndex: PropTypes.string,
7884
tooltip: PropTypes.node,
7985
variant: PropTypes.oneOf(['base', 'neutral', 'brand', 'destructive', 'icon'])
8086
};
@@ -112,6 +118,11 @@ class ButtonStateful extends TooltipTrigger {
112118
if (!isBoolean(this.props.active)) this.setState({ active: !this.state.active });
113119
}
114120

121+
handleBlur(e) {
122+
if(this.props.onBlur) this.props.onBlur(e);
123+
e.currentTarget.blur();
124+
}
125+
115126
getClassName (active) {
116127
return classNames(this.props.className, 'slds-button', {
117128
'slds-button--neutral': this.props.variant !== 'icon',
@@ -124,17 +135,23 @@ class ButtonStateful extends TooltipTrigger {
124135
}
125136

126137
render () {
127-
const props = omit(this.props, ['className', 'label', 'onClick', 'type', 'active']);
128138
const active = isBoolean(this.props.active) ? this.props.active : this.state.active;
129139

130140
if (this.props.variant === 'icon') {
131141
return (
132142
<button
133-
onMouseLeave={blurElement}
143+
aria-live="polite"
134144
className={this.getClassName(active)}
145+
disabled={this.props.disabled}
146+
onBlur={this.handleBlur.bind(this)}
135147
onClick={this.handleClick.bind(this)}
136-
{...props}
137-
aria-live="polite"
148+
onFocus={this.props.onFocus}
149+
onKeyDown={this.props.onKeyDown}
150+
onKeyPress={this.props.onKeyPress}
151+
onKeyUp={this.props.onKeyUp}
152+
onMouseEnter={this.props.onMouseEnter}
153+
onMouseLeave={this.handleBlur.bind(this)}
154+
tabIndex={this.props.tabIndex}
138155
>
139156
<ButtonIcon
140157
assistiveText={active ? `${this.props.assistiveText} selected` : this.props.assistiveText}
@@ -147,14 +164,21 @@ class ButtonStateful extends TooltipTrigger {
147164
</button>
148165
);
149166
}
150-
167+
151168
return (
152169
<button
153-
onMouseLeave={blurElement}
154-
className={this.getClassName(active)}
155170
aria-live="assertive"
171+
className={this.getClassName(active)}
172+
disabled={this.props.disabled}
173+
onBlur={this.handleBlur.bind(this)}
156174
onClick={this.handleClick.bind(this)}
157-
{...props}
175+
onFocus={this.props.onFocus}
176+
onKeyDown={this.props.onKeyDown}
177+
onKeyPress={this.props.onKeyPress}
178+
onKeyUp={this.props.onKeyUp}
179+
onMouseEnter={this.props.onMouseEnter}
180+
onMouseLeave={this.handleBlur.bind(this)}
181+
tabIndex={this.props.tabIndex}
158182
>
159183
<span className="slds-text-not-selected">
160184
<ButtonIcon

components/button/index.jsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,17 @@ const propTypes = {
6868
* Visible label on the button. If the button is an icon button with no label, you must use the <code>assistiveText</code> prop.
6969
*/
7070
label: PropTypes.string,
71+
onBlur: PropTypes.func,
7172
/**
7273
* Triggered when the button is clicked.
7374
*/
7475
onClick: PropTypes.func,
76+
onFocus: PropTypes.func,
77+
onKeyDown: PropTypes.func,
78+
onKeyPress: PropTypes.func,
79+
onKeyUp: PropTypes.func,
80+
onMouseEnter: PropTypes.func,
81+
onMouseLeave: PropTypes.func,
7582
/**
7683
* If true, button scales to 100% width on small form factors.
7784
*/
@@ -185,28 +192,19 @@ class Button extends TooltipTrigger {
185192
}
186193

187194
render () {
188-
const props = omit(this.props, [
189-
'assistiveText',
190-
'className',
191-
'hint',
192-
'iconCategory',
193-
'iconName',
194-
'iconPosition',
195-
'iconSize',
196-
'iconVariant',
197-
'inverse',
198-
'label',
199-
'onClick',
200-
'responsive',
201-
'tooltip',
202-
'variant'
203-
]);
204-
205195
return (
206196
<button
207197
className={this.getClassName()}
208-
{...props}
198+
disabled={this.props.disabled}
199+
onBlur={this.props.onBlur}
209200
onClick={this.handleClick}
201+
onFocus={this.props.onFocus}
202+
onKeyDown={this.props.onKeyDown}
203+
onKeyPress={this.props.onKeyPress}
204+
onKeyUp={this.props.onKeyUp}
205+
onMouseEnter={this.props.onMouseEnter}
206+
onMouseLeave={this.props.onBlur}
207+
tabIndex={this.props.tabIndex}
210208
>
211209
{this.props.iconPosition === 'right' ? this.renderLabel() : null}
212210

stories/button-stateful/index.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ storiesOf(BUTTON_STATEFUL, module)
2020
.add('Icon', () => getButtonStateful({
2121
variant: 'icon',
2222
label: 'Neutral Icon',
23-
iconName: 'check'
23+
iconName: 'check',
24+
onFocus: action('hover'),
25+
onMouseEnter: (e) => { console.log('target is ', e.target) }
2426
}));

stories/button/index.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ storiesOf(BUTTON, module)
2323
.add('Neutral Icon', () => getButton({
2424
label: 'Neutral Icon',
2525
iconName: 'download',
26-
iconPosition: 'left'
26+
iconPosition: 'left',
27+
onFocus: action('focus'),
28+
onKeyDown: action('keyDown')
2729
}))
2830
.add('Disabled', () => getButton({ label: 'Disabled', disabled: true }))
2931
.add('Icon large', () => getIconButton({

0 commit comments

Comments
 (0)