Repository navigation
Button: Align focus styles with design system #78646
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
Changes from all commits
53fdaec
22d32db
d201b9d
7f978ba
aea9843
13bfbd3
23bb4a9
3dab0ab
0ca49f2
0be0364
064cde8
b845a4f
987884b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| @use "sass:color"; | ||
| @use "@wordpress/base-styles/colors" as *; | ||
| @use "@wordpress/base-styles/mixins"; | ||
| @use "@wordpress/base-styles/variables" as *; | ||
| @use "../utils/theme-variables" as *; | ||
|
|
||
|
|
@@ -11,6 +12,10 @@ | |
| */ | ||
|
|
||
| .components-button { | ||
| &:focus:not(:active) { | ||
| @include mixins.outset-ring__focus(); | ||
| } | ||
|
|
||
| display: inline-flex; | ||
| text-decoration: none; | ||
| font-family: inherit; | ||
|
|
@@ -21,11 +26,6 @@ | |
| cursor: var(--wpds-cursor-control); | ||
| appearance: none; | ||
| background: none; | ||
|
|
||
| @media not ( prefers-reduced-motion ) { | ||
| transition: box-shadow 0.1s linear; | ||
| } | ||
|
|
||
| height: $button-size; | ||
| align-items: center; | ||
| box-sizing: border-box; | ||
|
|
@@ -42,12 +42,6 @@ | |
| color: $components-color-accent; | ||
| } | ||
|
|
||
| // Focus. | ||
| // See https://github.com/WordPress/gutenberg/issues/13267 for more context on these selectors. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed this issue link because they're no longer relevant. |
||
| &:focus:not(:active) { | ||
| box-shadow: 0 0 0 var(--wp-admin-border-width-focus) $components-color-accent; | ||
| } | ||
|
|
||
| /** | ||
| * Primary button style. | ||
| */ | ||
|
|
@@ -59,24 +53,16 @@ | |
| text-decoration: none; | ||
| text-shadow: none; | ||
|
|
||
| // Show the boundary of the button, in High Contrast Mode. | ||
| outline: 1px solid transparent; | ||
|
|
||
| &:hover:not(:disabled) { | ||
| background: $components-color-accent-darker-10; | ||
| color: $components-color-accent-inverted; | ||
| } | ||
|
|
||
| &:active:not(:disabled) { | ||
| background: $components-color-accent-darker-20; | ||
| border-color: $components-color-accent-darker-20; | ||
| color: $components-color-accent-inverted; | ||
| } | ||
|
|
||
| &:focus:not(:active) { | ||
| box-shadow: inset 0 0 0 1px $components-color-background, 0 0 0 var(--wp-admin-border-width-focus) $components-color-accent; | ||
| } | ||
|
|
||
| &:disabled, | ||
| &:disabled:active:enabled, | ||
| &[aria-disabled="true"], | ||
|
|
@@ -85,12 +71,6 @@ | |
| // TODO: Prepare for theming (https://github.com/WordPress/gutenberg/pull/45466/files#r1030872724) | ||
| color: rgba($white, 0.4); | ||
| background: $components-color-accent; | ||
| border-color: $components-color-accent; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Primary styling is background + color, not a border stroke (secondary uses inset The forced-colors boundary did not come from Same reasoning applies to the other removed |
||
| outline: none; | ||
|
|
||
| &:focus:enabled { | ||
| box-shadow: inset 0 0 0 1px $components-color-background, 0 0 0 var(--wp-admin-border-width-focus) $components-color-accent; | ||
| } | ||
| } | ||
|
|
||
| &.is-busy, | ||
|
|
@@ -107,7 +87,10 @@ | |
| $components-color-accent 70% | ||
| ); | ||
| /* stylelint-enable */ | ||
| border-color: $components-color-accent; | ||
| } | ||
|
|
||
| @media (forced-colors: active) { | ||
| outline: 1px solid ButtonBorder; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -117,9 +100,6 @@ | |
|
|
||
| &.is-secondary, | ||
| &.is-tertiary { | ||
| // Show the boundary of the button, in High Contrast Mode. | ||
| outline: 1px solid transparent; | ||
|
|
||
| &:active:not(:disabled) { | ||
| box-shadow: none; | ||
| } | ||
|
|
@@ -131,15 +111,24 @@ | |
| background: transparent; | ||
| transform: none; | ||
| } | ||
|
|
||
| @media (forced-colors: active) { | ||
| outline: 1px solid ButtonBorder; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Secondary button style. | ||
| */ | ||
|
|
||
| &.is-secondary { | ||
| box-shadow: inset 0 0 0 $border-width $components-color-accent, 0 0 0 currentColor; | ||
| outline: 1px solid transparent; // Shown in high contrast mode. | ||
| @media not ( prefers-reduced-motion ) { | ||
| transition: box-shadow 0.1s linear; | ||
| } | ||
|
|
||
| box-shadow: | ||
| inset 0 0 0 $border-width $components-color-accent, | ||
| 0 0 0 currentColor; | ||
|
Comment on lines
+125
to
+131
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| white-space: nowrap; | ||
| color: $components-color-accent; | ||
| background: transparent; | ||
|
|
@@ -156,8 +145,9 @@ | |
| box-shadow: inset 0 0 0 $border-width var(--wpds-color-stroke-interactive-neutral-disabled); | ||
| } | ||
|
|
||
| &:focus:not(:active) { | ||
| box-shadow: 0 0 0 currentColor inset, 0 0 0 var(--wp-admin-border-width-focus) $components-color-accent; | ||
| @media (forced-colors: active) { | ||
| // Inset box-shadow borders are not reliable in forced-colors mode. | ||
| box-shadow: none; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -183,15 +173,6 @@ | |
| p + & { | ||
| margin-left: -($grid-unit-15 * 0.5); | ||
| } | ||
|
|
||
| &:disabled, | ||
| &[aria-disabled="true"], | ||
| &[aria-disabled="true"]:hover { | ||
| &:not(:focus) { | ||
| box-shadow: none; | ||
| outline: none; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -210,10 +191,6 @@ | |
| color: color.adjust($alert-red, $lightness: -20%); | ||
| } | ||
|
|
||
| &:focus:not(:active) { | ||
| box-shadow: 0 0 0 var(--wp-admin-border-width-focus) $alert-red; | ||
| } | ||
|
|
||
| &:active:not(:disabled, [aria-disabled="true"]) { | ||
| background: $gray-400; | ||
| } | ||
|
|
@@ -263,8 +240,9 @@ | |
|
|
||
| height: auto; | ||
|
|
||
| &:focus { | ||
| &:focus:not(:active) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Omitting |
||
| border-radius: $radius-small; | ||
| text-decoration: none; | ||
| } | ||
|
|
||
| &:disabled, | ||
|
|
@@ -273,14 +251,6 @@ | |
| } | ||
| } | ||
|
|
||
| // Windows High Contrast mode will show this outline, but not the box-shadow. | ||
| // This rule is placed after variant outline declarations (e.g. is-primary, | ||
| // is-secondary, is-tertiary) to ensure it wins by source order at the same | ||
| // specificity, while not using `:not(:active)` to avoid outline flicker. | ||
| &:focus { | ||
| outline: 3px solid transparent; | ||
| } | ||
|
|
||
| &:not(:disabled, [aria-disabled="true"]):active { | ||
| color: $components-color-foreground; | ||
| } | ||
|
|
@@ -383,22 +353,6 @@ | |
| } | ||
| } | ||
|
|
||
| &:focus:not(:active) { | ||
| box-shadow: inset 0 0 0 1px $components-color-background, 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. | ||
| &:focus { | ||
| outline: 2px solid transparent; | ||
| } | ||
| } | ||
|
|
||
| // Hide focus outline on :active to provide click feedback in forced-colors | ||
| // mode, where box-shadow is not visible. Higher specificity (0,3,0) | ||
| // ensures this wins over variant outline declarations. Placed after | ||
| // .is-pressed to also win by source order at equal specificity (0,3,0). | ||
| &:focus:active { | ||
| outline: none; | ||
| } | ||
|
|
||
| svg { | ||
|
|
||
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'll replace the tokens in a separate PR.