-
Notifications
You must be signed in to change notification settings - Fork 166
[terra-button] Create selectable button #3940
Conversation
6ecd187
to
4aeef39
Compare
packages/terra-button/src/Button.jsx
Outdated
* @private | ||
* Whether or not the button can be selected (toggleable button). | ||
*/ | ||
isSelectable: PropTypes.bool, |
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.
can we add a console.warn when this prop s used ? something like 'this prop will be deprecated in future and do not recommend it for use'.
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.
Added in 3ea7af9
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.
Removed in 44abd39 as prop was changed to custom.
packages/terra-button/src/Button.jsx
Outdated
@@ -326,6 +350,7 @@ class Button extends React.Component { | |||
onFocus={this.handleFocus} | |||
href={href} | |||
ref={refCallback} | |||
aria-pressed={isSelectable ? this.state.isSelected : undefined} |
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.
what is the SR reading out when aria-pressed is set to True ?
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.
It says "Toggle button pressed, <button_label>"
cc612cd
to
80c275b
Compare
@@ -46,7 +46,6 @@ exports[`correctly applies the theme context className 1`] = ` | |||
> | |||
<button | |||
aria-disabled={false} | |||
aria-pressed={false} |
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.
why are we removing aria-pressed from button group ..?
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.
This was getting removed due to the condition in button. Updated button component to add aria-pressed only when "isSelected" is used so that ButtonGroup would continue to receive aria-pressed as before.
aria-pressed is now back in 54c4c36
packages/terra-button/src/Button.jsx
Outdated
@@ -154,6 +163,8 @@ class Button extends React.Component { | |||
this.shouldShowFocus = true; | |||
} | |||
|
|||
this.handleOnChange(event); |
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.
let's invoke this only for selectable button
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.
check was added in within handleOnChange (54c4c36#diff-39f6c87ccf92298263c905de24e815f96ac1c87e46309e7d88ac4513f8bb7193R152).
Now moved before calling handler in 54c4c36
packages/terra-button/src/Button.jsx
Outdated
@@ -174,7 +185,7 @@ class Button extends React.Component { | |||
|
|||
// Add focus styles for keyboard navigation | |||
if (event.nativeEvent.keyCode === KeyCode.KEY_SPACE || event.nativeEvent.keyCode === KeyCode.KEY_RETURN) { | |||
this.setState({ focused: true }); | |||
this.setState(prevState => ({ focused: true, isSelected: !prevState.isSelected })); |
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.
I would move this out to different block and update only if isSelectable is true to prevent unintended re-render of component
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.
Added check in 54c4c36
packages/terra-button/src/Button.jsx
Outdated
@@ -212,6 +223,7 @@ class Button extends React.Component { | |||
if (this.props.onMouseDown) { | |||
this.props.onMouseDown(event); | |||
} | |||
this.setState(prevState => ({ isSelected: !prevState.isSelected })); |
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.
same here we need to invoke only for selectable button
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.
Added check in 54c4c36
packages/terra-button/src/Button.jsx
Outdated
@@ -255,6 +269,7 @@ class Button extends React.Component { | |||
{ compact: isCompact }, | |||
{ 'is-active': this.state.active && !isDisabled }, | |||
{ 'is-focused': this.state.focused && !isDisabled }, | |||
{ 'is-selected': customProps.isSelectable && this.state.isSelected && !isDisabled }, |
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.
let's spread out the isSelectable on top and use it instead of referring it through customProps chaining on multiple place for better readability
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.
That would cause unlisted prop lint err. Instead now moved to the top like this: 54c4c36#diff-39f6c87ccf92298263c905de24e815f96ac1c87e46309e7d88ac4513f8bb7193R132
This way handlers can use it outside of render.
&.is-selected { | ||
background-color: var(--terra-button-selected-background-color, #52585b); | ||
border-color: var(--terra-button-selected-border-color, #52585b); | ||
box-shadow: var(--terra-button-selected-box-shadow); | ||
color: var(--terra-button-selected-color, #fff); | ||
} |
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.
I believe is-Selected is the only class we would need rest other styles should be same as default button ( which might be already added on _mixin.scss of button package.
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.
Updated along with renaming in cfcc950
|
cfcc950
to
e23b8e0
Compare
Summary
What was changed:
Add private prop
isSelectable
to allow terra-button to function as a toggleable button.Why it was changed:
These changes were requested by Mpages team to have a sub-variant of terra-button which could be toggleable.
Testing
This change was tested using:
Reviews
In addition to engineering reviews, this PR needs:
Additional Details
This PR resolves:
UXPLATFORM-9749
Thank you for contributing to Terra.
@cerner/terra
Unselected
Selected