Skip to content
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

Replaced focus state with focus-visible #20252

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions src/components/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,11 @@ const defaultProps = {
class Checkbox extends React.Component {
constructor(props) {
super(props);
this.state = {
isFocused: false,
};

this.onFocus = this.onFocus.bind(this);
this.onBlur = this.onBlur.bind(this);
this.handleSpaceKey = this.handleSpaceKey.bind(this);
this.firePressHandlerOnClick = this.firePressHandlerOnClick.bind(this);
}

onFocus() {
this.setState({isFocused: true});
}

onBlur() {
this.setState({isFocused: false});
}

handleSpaceKey(event) {
if (event.code !== 'Space') {
return;
Expand All @@ -83,13 +70,6 @@ class Checkbox extends React.Component {
return;
}

const wasChecked = this.props.isChecked;

// If checkbox is checked and focused, make sure it's unfocused when pressed.
if (this.state.isFocused && wasChecked) {
this.onBlur();
}

this.props.onPress();
}

Expand All @@ -99,10 +79,7 @@ class Checkbox extends React.Component {
disabled={this.props.disabled}
onPress={this.firePressHandlerOnClick}
onMouseDown={this.props.onMouseDown}
onFocus={this.onFocus}
onBlur={this.onBlur}
ref={this.props.forwardedRef}
onPressOut={this.onBlur}
style={this.props.style}
onKeyDown={this.handleSpaceKey}
accessibilityRole="checkbox"
Expand All @@ -120,8 +97,10 @@ class Checkbox extends React.Component {
this.props.isChecked && styles.checkedContainer,
this.props.hasError && styles.borderColorDanger,
this.props.disabled && styles.cursorDisabled,
(this.state.isFocused || this.props.isChecked) && styles.borderColorFocus,
bernhardoj marked this conversation as resolved.
Show resolved Hide resolved
this.props.isChecked && styles.borderColorFocus,
]}
// Used as CSS selector to customize focus-visible style
dataSet={{checkbox: true}}
>
{this.props.isChecked && (
<Icon
Expand Down
3 changes: 3 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
select:focus-visible, select:focus[data-focusvisible-polyfill] {
box-shadow: none;
}
div[role="checkbox"]:focus-visible > div[data-checkbox], div[role="checkbox"]:focus[data-focusvisible-polyfill] > div[data-checkbox] {
border-color: #03D47C !important;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sure many will disagree with this change especially when this is using theme colors which are not controlled by our theme.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to bring it to slack to get a consensus? Or if we did already, please share the link.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Responded here: #18801 (comment)

}
::-ms-reveal {
display: none;
}
Expand Down