-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
What problem does this address?
Buttons support the ability to retain focus while being disabled, via the __experimentalIsFocusable
prop. However, when this is enabled on secondary and tertiary buttons, they do not have a focus ring. For example, the "Reset filters" button here is focused and only mostly disabled, but that is not visibly evident.
This is caused by an issue of specificity in the CSS, with .is-secondary
and .is-tertiary
overriding previously established focus styling for buttons using box-shadow
and outline
:
gutenberg/packages/components/src/button/style.scss
Lines 125 to 134 in 1bf654b
&:disabled, | |
&[aria-disabled="true"], | |
&[aria-disabled="true"]:hover { | |
color: $gray-600; | |
background: transparent; | |
transform: none; | |
opacity: 1; | |
box-shadow: none; | |
outline: none; | |
} |
gutenberg/packages/components/src/button/style.scss
Lines 38 to 43 in 1bf654b
&:focus:not(:disabled) { | |
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) $components-color-accent; | |
// Windows High Contrast mode will show this outline, but not the box-shadow. | |
outline: 3px solid transparent; | |
} |
What is your proposed solution?
The fix could be as straightforward as changing the scope or specificity of one of the other rules, to allow for the focus styling to propagate. This is probably most easily achieved by moving the box-shadow
and outline
declarations into a sub-block:
diff --git a/packages/components/src/button/style.scss b/packages/components/src/button/style.scss
index 03273056cf..4b11d9169a 100644
--- a/packages/components/src/button/style.scss
+++ b/packages/components/src/button/style.scss
@@ -129,8 +129,11 @@
background: transparent;
transform: none;
opacity: 1;
- box-shadow: none;
- outline: none;
+
+ &:not(:focus) {
+ box-shadow: none;
+ outline: none;
+ }
}
}
This will at least allow mostly-disabled buttons to pick up the focus styling applied to other controls:
Metadata
Metadata
Assignees
Labels
Type
Projects
Status