Skip to content
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

[EuiSelectable] Fix focus ring on non-searchable listboxes #6637

Merged
merged 3 commits into from
Mar 9, 2023

Conversation

cee-chen
Copy link
Member

@cee-chen cee-chen commented Mar 7, 2023

Summary

closes #6633

This PR attempts to fix the odd focus ring behavior for EuiSelectables that are listboxes only (i.e., do not have the searchable prop).

Unfortunately, due to limitations of :focus-within and :focus-visible (WICG/focus-visible#151), we can only support clear focus rings for for browsers that support the :has selector (i.e. all browsers except FF, which is working on :has support).

Before (Chrome)

After (Chrome) - keyboard focus only

Before (FF)

After (FF) - both keyboard & mouse focus

QA

  • Go to https://eui.elastic.co/pr_6637/#/forms/selectable#the-basics
  • In Chrome/Safari/Edge, confirm that keyboard tabbing to the listbox shows a non-wonky-looking focus ring and allows all normal navigation/selection key behavior
  • In Chrome/Safari/Edge, confirm that clicking on options still works as before and does not show a focus ring

General checklist

  • Checked in both light and dark modes
  • Checked in Chrome, Safari, Edge, and Firefox
  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

Comment on lines -3 to +4
&: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) {
Copy link
Member 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.

Comment on lines +26 to +30
@if (unitless($offset)) {
outline-offset: #{$offset}px;
} @else {
outline-offset: #{$offset};
}
Copy link
Member 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:

Comment on lines +11 to +21
@if ($focusVisibleSelectors) {
// Chrome
&:focus-visible {
outline-style: auto;
}

&:not(:focus-visible) {
outline: none;
&:not(:focus-visible) {
outline: none;
}
} @else {
outline-style: auto;
Copy link
Member 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).

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6637/

@cee-chen
Copy link
Member Author

cee-chen commented Mar 9, 2023

@daveyholler Any chance you can review this PR today? 🙏 It should hopefully be fairly quick.

Copy link
Contributor

@daveyholler daveyholler left a comment

Choose a reason for hiding this comment

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

I peeped the PR preview. This looks good!

@cee-chen cee-chen merged commit 319bd99 into elastic:main Mar 9, 2023
@cee-chen cee-chen deleted the selectable-focus branch March 9, 2023 23:13
1Copenut added a commit to elastic/kibana that referenced this pull request Mar 23, 2023
## Summary

eui@76.0.2 ⏩ eui@76.3.0

## [`76.3.0`](https://github.com/elastic/eui/tree/v76.3.0)

- Updated `EuiSkipLink`'s `fallbackDestination` prop to support an array
of query selector strings
([#6646](elastic/eui#6646))

**Bug fixes**

- Fixed `EuiFlyout` to preserve body scrollbar width on open
([#6645](elastic/eui#6645))
- Fixed `EuiImage`'s full screen mode to not scroll jump & to preserve
body scrollbar width on open
([#6645](elastic/eui#6645))
- Fixed `EuiCodeBlock`'s full screen mode to not scroll jump & to
preserve body scrollbar width on open
([#6645](elastic/eui#6645))

## [`76.2.0`](https://github.com/elastic/eui/tree/v76.2.0)

- Added new `renderCustomGridBody` escape hatch rendering prop to
`EuiDataGrid` ([#6624](elastic/eui#6624))

**Bug fixes**

- Fixed visual listbox focus ring bug on non-searchable `EuiSelectable`s
([#6637](elastic/eui#6637))
- Added a legacy `alert` alias for the `warning` `EuiIcon` type
([#6640](elastic/eui#6640))
- Fixed a type definition incorrectly coming from a dev dependency,
which was causing issues for some consuming projects
([#6643](elastic/eui#6643))

## [`76.1.0`](https://github.com/elastic/eui/tree/v76.1.0)

- Added more detailed screen reader instructions to `EuiSelectable`,
`EuiSuggest`, `EuiSelectableTemplateSitewide`, `EuiRange`, and
`EuiDualRange`. ([#6589](elastic/eui#6589))
- Added new `placeholder` prop to `EuiSuperSelect`
([#6630](elastic/eui#6630))
- Added new `setCellPopoverProps` parameter callback to `EuiDataGrid`'s
`renderCellPopover` prop
([#6632](elastic/eui#6632))

**Bug fixes**

- Fixed an ARIA attribute in `EuiSelectableList`
([#6589](elastic/eui#6589))
- Fixed `EuiSelectable` to no longer show active selection state or
respond to the Up/Down arrow keys when focus is inside the selectable
container, but not on the searchbox or listbox.
([#6631](elastic/eui#6631))

---------

Co-authored-by: Tiago Costa <tiago.costa@elastic.co>
jennypavlova pushed a commit to jennypavlova/kibana that referenced this pull request Mar 24, 2023
## Summary

eui@76.0.2 ⏩ eui@76.3.0

## [`76.3.0`](https://github.com/elastic/eui/tree/v76.3.0)

- Updated `EuiSkipLink`'s `fallbackDestination` prop to support an array
of query selector strings
([elastic#6646](elastic/eui#6646))

**Bug fixes**

- Fixed `EuiFlyout` to preserve body scrollbar width on open
([elastic#6645](elastic/eui#6645))
- Fixed `EuiImage`'s full screen mode to not scroll jump & to preserve
body scrollbar width on open
([elastic#6645](elastic/eui#6645))
- Fixed `EuiCodeBlock`'s full screen mode to not scroll jump & to
preserve body scrollbar width on open
([elastic#6645](elastic/eui#6645))

## [`76.2.0`](https://github.com/elastic/eui/tree/v76.2.0)

- Added new `renderCustomGridBody` escape hatch rendering prop to
`EuiDataGrid` ([elastic#6624](elastic/eui#6624))

**Bug fixes**

- Fixed visual listbox focus ring bug on non-searchable `EuiSelectable`s
([elastic#6637](elastic/eui#6637))
- Added a legacy `alert` alias for the `warning` `EuiIcon` type
([elastic#6640](elastic/eui#6640))
- Fixed a type definition incorrectly coming from a dev dependency,
which was causing issues for some consuming projects
([elastic#6643](elastic/eui#6643))

## [`76.1.0`](https://github.com/elastic/eui/tree/v76.1.0)

- Added more detailed screen reader instructions to `EuiSelectable`,
`EuiSuggest`, `EuiSelectableTemplateSitewide`, `EuiRange`, and
`EuiDualRange`. ([elastic#6589](elastic/eui#6589))
- Added new `placeholder` prop to `EuiSuperSelect`
([elastic#6630](elastic/eui#6630))
- Added new `setCellPopoverProps` parameter callback to `EuiDataGrid`'s
`renderCellPopover` prop
([elastic#6632](elastic/eui#6632))

**Bug fixes**

- Fixed an ARIA attribute in `EuiSelectableList`
([elastic#6589](elastic/eui#6589))
- Fixed `EuiSelectable` to no longer show active selection state or
respond to the Up/Down arrow keys when focus is inside the selectable
container, but not on the searchbox or listbox.
([elastic#6631](elastic/eui#6631))

---------

Co-authored-by: Tiago Costa <tiago.costa@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[EuiSelectable] Non-searchable listboxes' focus rings
3 participants