Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/components/selectable/selectable_list/_selectable_list.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Expand height of list via flex box
.euiSelectableList {
&:focus-within {
@include euiFocusRing;
// NOTE: This is currently only visible on supported browsers (all except FF)
// which is (unfortunately) better than always displaying the focus ring to mouse users
&:has(:focus-visible) {
Comment on lines -3 to +4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See WICG/focus-visible#151 for more discussion - :focus-within unfortunately grabs all focus including mouse clicks, when we likely only want keyboard focus. :focus-within-visible was discarded by WICG as a spec, with :has() being the recommended way forward.

@include euiFocusRing(null, $euiFocusRingSize / 2, false);
}
}

// Expand height of list via flex box
.euiSelectableList-fullHeight {
flex-grow: 1;
}
Expand All @@ -18,6 +20,11 @@
.euiSelectableList__list {
@include euiOverflowShadow;
@include euiScrollBar;

&:focus,
& > ul:focus {
outline: none; // Focus outline handled by parent .euiSelectableList
}
}

.euiSelectableList__groupLabel {
Expand Down
25 changes: 17 additions & 8 deletions src/themes/amsterdam/global_styling/mixins/_states.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,31 @@
// This re-uses the same faux focus ring mixin, but adjusts the outline instead
// @param {size} Old param from default theme that won't be used, so it should always be `null`
// @param {offset} Accepts a specific number or 'inner' or 'outer' to adjust outline position
@mixin euiFocusRing($size: null, $offset: false) {
// @param {includeFocusVisible} Allows turning off :not:focus-visible selector (which can interfere with some manual usages)
@mixin euiFocusRing($size: null, $offset: false, $focusVisibleSelectors: true) {
// Safari & Firefox
outline: $euiFocusRingSize solid currentColor;

// Chrome
&:focus-visible {
outline-style: auto;
}
@if ($focusVisibleSelectors) {
// Chrome
&:focus-visible {
outline-style: auto;
}

&:not(:focus-visible) {
outline: none;
&:not(:focus-visible) {
outline: none;
}
} @else {
outline-style: auto;
Comment on lines +11 to +21
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extra $focusVisibleSelectors param/conditional rendering needed to be added for the pseudo focus ring styles to work correctly on an item that didn't actually contain focus, only focus within.

the :not(:focus-visible) in particular was what causing an outline: none and for the previous mixin include on .euiSelectableList to not work.

However, the outline-style: auto is still needed for outline styles in Safari and FF to inherit their default browser focus ring styles (Safari's focus ring looks particularly ugly w/o auto - no border-radius, etc).

}

// Adjusting position with offset
@if (type-of($offset) == number) {
outline-offset: #{$offset}px;
@if (unitless($offset)) {
outline-offset: #{$offset}px;
} @else {
outline-offset: #{$offset};
}
Comment on lines +26 to +30
Copy link
Contributor Author

@cee-chen cee-chen Mar 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a bug where output would be 1pxpx if $euiFocusRingSize / 2 was passed in to the $offset param.

Also offset needs to be pretty exact here because otherwise the horizontal border between selectable list options cuts into the outline on Chrome & Edge:

} @else if ($offset == 'inner') {
outline-offset: -$euiFocusRingSize;
} @else if ($offset == 'outer') {
Expand Down
3 changes: 3 additions & 0 deletions upcoming_changelogs/6637.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Bug fixes**

- Fixed visual listbox focus ring bug on non-searchable `EuiSelectable`s