-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add consistent keyboard focus ring across interactive components (#2050)
* π Apply focus-within to button * π Fix checkbox border radius assignment * π Apply focus-within to checkbox * π Apply focus-within to radio * π Apply focus-within to toggle * π Change global focus ring color * π Apply focus-within to card * π Apply focus-within to dropdown * π Apply focus-within to input (formfield) * π Apply focus-within to textarea (formfield) * π Apply focus-within to link * π Apply focus-within to knob in range * π Specify padding on segment btn (closes #1744) This is a prerequisite for properly styling the segment button with a focus ring * π Apply focus-within to segmented-control * π Use element-as-button directive with chip * π Apply focus-within to chip * π§ Remove outline test from elm as btn directive This is part of restructuring focus ring tests. It is the responsibility of components themselves not this directive to apply focus styling. * π Introduce apply-focus mixin * π Use interaction state in button * π Extend apply-focus mixin with gap and shadow * π Use apply-focus in card * π Use apply-focus in link * βͺ Revert accidental color change * β»οΈ Remove accidental double pseudo class for link * π Adjust link focus ring border radius * π Use background color getter from utils * π Use apply-focus in dropdown * π Split mixin in two to support css shadow parts * π QoL improvements to focus mixin * π Use apply-focus-part in toggle * β»οΈ Clean up link, card and dropdown * π Fix missing string interpolation * β»οΈ Move apply-focus to shared form field styles * π Use apply-focus in checkbox * π Use apply-focus in chip * π Use apply-focus in radio * π Use apply-focus in range * π Use apply-focus in segmented-control * π Use apply-focus-part in Segmented Control * π Support elevation of four in card * π Add focus-visible mixin with fallbacks * π Replace apply-focus with focus-visible solution * π Apply mixins only on non-touch devices * β»οΈ Refactor navbar to leave room for focus ring * π Document and cleanup focus mixins * π¨ Formatting to improve readability * Remove typo in focus mixin comment * β»οΈ Add content-block to mixin * β»οΈ Reorder imports alphabetically * β»οΈ Use focus-ring-color variable via utils * π Update comments for focus to be more specific * β»οΈ Document toggle style changes * β»οΈ Reorder for clarity * π₯ Remove todo
- Loading branch information
1 parent
5b7b7d6
commit 11486d9
Showing
20 changed files
with
156 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
@use '../utils'; | ||
|
||
// --------------------------------------------------------------------------- | ||
// The apply-focus-visible mixin is used by most interactive elements to apply | ||
// a focus ring around the element when navigated to via a keyboard on a | ||
// non-touch device. | ||
|
||
/// @param {box-shadow} $shadow | ||
/// Add/preserve additional box-shadow (e.g. elevation) alongside the focus ring. | ||
/// @param {number} $gap | ||
/// The distance (in pixels) from the element boundary to the focus ring | ||
// --------------------------------------------------------------------------- | ||
@mixin apply-focus-visible($shadow: null, $gap: utils.size('xxxxs')) { | ||
@include utils.not-touch { | ||
$reset-focus-ring: 0 0 0 0 transparent; | ||
|
||
&:focus { | ||
// This is a fallback for safari and other browsers, so we still show the focus | ||
// ring on older versions that do not support :focus-visible. | ||
@include _focus-ring($shadow, $gap); | ||
} | ||
|
||
&:focus:not(:focus-visible) { | ||
// On browsers that do support focus-visible, we dont want anything to show on the | ||
// standard focus pseudo-class, so we reset it here, while still allowing to preserve | ||
// any shadow set on the element by the user. | ||
box-shadow: $shadow, $reset-focus-ring; | ||
} | ||
|
||
&:focus-visible { | ||
@include _focus-ring($shadow, $gap); | ||
} | ||
|
||
@content; | ||
} | ||
} | ||
|
||
// --------------------------------------------------------------------------- | ||
// The apply-focus-part mixin is used where ionics components do not allow | ||
// us to apply styling directly to the tabbed element, as it is hidden inside | ||
// a shadow root and not exposed as a part. In some of these cases, we are | ||
// unable to provide focus-visible like functionality, and thus the focus ring | ||
// will always show. | ||
|
||
/// @param {string} $part | ||
/// Add focus styles to a specific CSS Shadow Part. | ||
/// @param {box-shadow} $shadow | ||
/// Add/preserve additional box-shadow (e.g. elevation) alongside the focus ring. | ||
/// @param {number} $gap | ||
/// The distance (in pixels) from the element boundary to the focus ring | ||
// --------------------------------------------------------------------------- | ||
@mixin apply-focus-part($part, $shadow: null, $gap: utils.size('xxxxs')) { | ||
@include utils.not-touch { | ||
&:focus-within::part(#{$part}) { | ||
@include _focus-ring($shadow, $gap); | ||
} | ||
@content; | ||
} | ||
} | ||
|
||
@mixin _focus-ring($shadow, $gap) { | ||
$stroke-width: utils.size('xxxxs'); | ||
box-shadow: #{$shadow}, 0 0 0 $gap #{utils.get-color('background-color')}, | ||
0 0 0 $gap + $stroke-width utils.$focus-ring-color; | ||
transition: box-shadow utils.get-transition-duration('quick'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
@forward 'focus'; | ||
@forward 'hover'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.