-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Components: Add isFocusable state to Button #19337
Conversation
@@ -212,7 +212,7 @@ | |||
outline: none; | |||
} | |||
|
|||
&:active:focus:enabled { | |||
&:not([aria-disabled="true"]):active:focus { | |||
box-shadow: none; | |||
} |
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.
The styles changes make me a bit nervous :P because we have some many button styles ovverrides in the UI that I know this can trigger specificity issues and should be tested properly.
@@ -30,6 +35,7 @@ export function Button( props, ref ) { | |||
isSecondary, | |||
isLink, | |||
isDestructive, | |||
isFocusable, |
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.
Should this default to true instead? I feel this was needed in every disabled button we have in the UI. I'm even wondering if we need a prop or just do this automatically.
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.
Now, it makes me wonder how often we want to have a button which is both disabled and not focusable at the same time. It feels like for accessibility reasons it should always be focusable.
https://ux.stackexchange.com/questions/103239/should-disabled-elements-be-focusable-for-accessibility-purposes - it only confirms this reasoning.
It might be a good idea to set isFocusable to true by default as suggested.
We might be some disabled and not focusable buttons but it might be simply wrong. We should found those cases and take further steps based on that.
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.
Made isFocusable
true by default
I did some quick research and it feels like readOnly doesn’t fit here. I can only see it work mostly in the context of form elements which take input. |
I still don't know what's the best approach to keep the tooltip contrast high when the button is disabled. Right now, button has reduced Ideally, tooltips should always render outside the button using Portal or something similar. But maybe that's something for another PR. |
Should we remove the tooltip when the button is disabled? |
This is what I found in https://inclusive-components.design/tooltips-toggletips/:
I think we should keep them. In addition, we should stop using |
@gziolo You can reproduce it in the storybook (Button stories). It seems that it works in the editor because it's using |
It's a known issue then. I did some source code checking and I found this: gutenberg/packages/components/src/popover/index.js Lines 491 to 506 in 87e5415
If there is no |
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 include the note in the CHANGELOG file about this new prop:
https://github.com/WordPress/gutenberg/blob/master/packages/components/CHANGELOG.md
Otherwise, it looks good. @youknowriad, do you still have concerns? I would be in favor of landing this change.
I don't have concerns, this is a great PR and I believe there's a lot of places where we can remove code as a follow-up. (We use this pattern in a lot of places). I still wonder whether the prop is necessary at all, is there a place where we do want to effectively "disable" the button. |
I can remove the prop for now and add it later if it’s needed or make it experimental? |
Maybe we can do a quick audit of our existing "disabled" buttons in our code base and remove it if we want this consistently? |
Sounds good! I’ll have a look. |
Well, that's a great question. We need to find the answer first, I also shared it on WordPress Slack in the accessibility channel (link requires registration): https://wordpress.slack.com/archives/C02RP4X03/p1578572361042000 |
The WAI-ARIA recommendations have a dedicated section to this topic: https://www.w3.org/TR/wai-aria-practices/#kbd_disabled_controls After reading the article above and the conversation in the link @gziolo shared, since this will change how native buttons work in the browser, I'd make the prop |
ok, that works for me 👍 |
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.
Still good, it makes sense to proceed this way 👍
@@ -39,6 +44,7 @@ export function Button( props, ref ) { | |||
shortcut, | |||
label, | |||
children, | |||
__experimentalIsFocusable: isFocusable, |
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's the story of this prop, should we make it stable @gziolo ? Recently I found a use-case where we have a button that switches from disabled to enabled and back and this causes focus loss unless this prop is true. So I'm going to use it but since it's now 2 years old, I was wondering if we should mark it stable? What's the reason for the experimental state.
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, we can promote it to stable after checking how the same functionality has evolved in Reakit.
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.
In Reakit it was named focusable
. That caused a bit of confusion. It wasn't obvious that the prop would make the element focusable when it was disabled. Some people were setting this prop to false thinking it would disable focus on the element.
We're renaming it to accessibleWhenDisabled
in v2 (this name may still change though).
Description
This PR tries to address this comment made by @gziolo: #18931 (comment)
This is specially useful when the presence of a button is important enough to be perceivable. For example: a disabled tab that will be activated when the user completes another task.
Even though we should take the low contrast into consideration, sighted users will generally perceive the presence of the button, but screen reader users navigating with Tab won't.
This also enables tooltips for
disabled label="tooltip"
buttons. That's the standard behavior when using<button disabled title="title">
:How has this been tested?
Checking unit tests and storybook. But I can't reliably test event handlers with Enzyme. #18855 or #17303 could help with that.
Types of changes
New feature
Checklist: