-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[Chip] Replace :focus with :focus-visible #22430
Conversation
@oliviertassinari At the moment the current test coverage misses line 308. The following test is designed to meet the condition of the if block but the final assertion fails as the focusVisible class is still present. Is there anything I am missing? diff --git a/packages/material-ui/src/Chip/Chip.test.js b/packages/material-ui/src/Chip/Chip.test.js
index 6d42dc4c8..716362673 100644
--- a/packages/material-ui/src/Chip/Chip.test.js
+++ b/packages/material-ui/src/Chip/Chip.test.js
@@ -554,5 +554,19 @@ describe('<Chip />', () => {
expect(chip).to.have.class(classes.focusVisible);
});
+
+ it('should reset the focused state', () => {
+ const { container, setProps } = render(<Chip label="Test Chip" onClick={() => {}} />);
+ const chip = container.querySelector(`.${classes.root}`);
+ simulatePointerDevice();
+
+ focusVisible(chip);
+
+ expect(chip).to.have.class(classes.focusVisible);
+
+ setProps({ disabled: true });
+
+ expect(chip).not.to.have.class(classes.focusVisible);
+ }); |
7406635
to
6ce9ad4
Compare
@alexmotoc Turns out, it was because we didn't forward the disabled prop down to the ButtonBase component. I have pushed the approach one step further. It seems that we can use focusVisibleClassName with no downsides. |
966903b
to
c522df2
Compare
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'm missing some context how we went from clicking behavior that's not expected to applying :focus-visible
. :focus-visible
is not about :focus
that is visible but keyboard focus.
It's not clear why a generic div should be focus-visible and it seems to me there are a couple of concepts mixed up here. I'd like to go back to the issue and identify what the problem actually is in the context of #20470
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.
Looks good. Updating it with the latest commit on next
for good measure and then some minor nitpick about naming.
@@ -87,7 +87,7 @@ export const styles = (theme) => { | |||
userSelect: 'none', | |||
WebkitTapHighlightColor: 'transparent', | |||
cursor: 'pointer', | |||
'&:hover, &:focus': { | |||
'&$focusVisible, &:hover': { | |||
backgroundColor: emphasize(backgroundColor, 0.08), |
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.
Related note: we should probably look into applying https://material.io/design/interaction/states.html. This is would be for another pull request.
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.
Are you suggesting we apply different styling to focus compared with hover?
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.
Yes, it's something we have started to do, see #10870 for progress.
Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
60773e0
to
915ba6a
Compare
@alexmotoc Thank you :) |
Fix #22386
Clicking a chip no longer makes it appear selected. The
:focus-visible
styling only appears when using keyboard navigation.