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] Disable arrow key navigation on non-search/listbox children #6631

Merged
merged 5 commits into from
Mar 6, 2023

Conversation

cee-chen
Copy link
Member

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

Summary

closes #6627

In #5613 and #5693, an early return was added to the space/enter keydown listeners to ensure the search clear button still worked without accidentally selecting an option.

It turns out we should have been more aggressive about this early return and put it in front of the entire listener so that the up/down arrow keys also did not function when on the clear button (or any other wildcard interactive content passed by consumers). The arrow keys and enter/space keys should only function when consumers are focused either on the searchbox, or on the listbox.

Before

before

After

after

Custom interactive child content within <EuiSelectable> (should remove focus/active state):

screencap

QA

  • Go to https://eui.elastic.co/pr_6631/#/forms/selectable#rendering-the-options (scroll all the way down)
  • Tab into the search box, arrow up/down, confirm active option selection works
  • Tab to the fake "Filters" button
  • Confirm that the active selection goes away
  • Confirm that using the up/down arrow keys does nothing on the button
  • Tab backwards to the search box and confirm active option selection/navigation works as expected

General checklist

  • Revert [REVERT ME] commit
  • Checked in Chrome, Safari, Edge, and Firefox
  • Added or updated jest and cypress tests
  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

- [ ] Checked in both light and dark modes
- [ ] Checked in mobile
- [ ] Props have proper autodocs (using @default if default values are missing) and playground toggles
- [ ] Added documentation
- [ ] Checked Code Sandbox works for any docs examples
- [ ] Checked for breaking changes and labeled appropriately
- [ ] Updated the Figma library counterpart

…-search/listbox children

- active highlight should go away since focus is no longer on the search/listbox

- blurring fix/workaround should still remain intact (goal is to DRY checks, not regress behavior)
@cee-chen cee-chen changed the title [EuiSelectable] Disable arrow key navigation on children not inside focus children [EuiSelectable] Disable arrow key navigation on non-search/listbox children Mar 3, 2023
Comment on lines -446 to +458
if (
((e.relatedTarget as Node)?.firstChild as HTMLElement)?.id === this.listId
) {
if (this.isFocusOnSearchOrListBox(e.relatedTarget)) {
Copy link
Member Author

@cee-chen cee-chen Mar 3, 2023

Choose a reason for hiding this comment

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

The goal of this change was just DRYness, I tested the 'double click' bug fixed/reported in #5021 fairly thoroughly in Chrome in EuiSelectable in a popover and EuiSelectableTemplateSitewide and am fairly sure there are no regressions.

onMouseDown = () => {
// Bypass onFocus when a click event originates from this.containerRef.
// Prevents onFocus from scrolling away from a clicked option and negating the selection event.
// https://github.com/elastic/eui/issues/4147
this.preventOnFocus = true;
};

onFocus = () => {
onFocus = (event?: FocusEvent) => {
Copy link
Member Author

@cee-chen cee-chen Mar 3, 2023

Choose a reason for hiding this comment

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

[Attaching to a random line for threading]

@miukimiu, @1Copenut - should non-searchable EuiSelectable's have this slightly-but-not-really visible focus ring around the listbox? (Note: this is happening on production, not just this PR)

Above screenshot is from FF, but it's happening on Chrome/Edge/Safari as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Tested in Chrome. I think it shouldn't have the visible focus ring around the listbox. It doesn't look good.

Screenshot 2023-03-06 at 17 46 18

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! I'll open up a follow-up issue for this since it's already happening in production: #6633

Comment on lines 125 to 127
onClick={() => {
inputRef?.focus();
}}
Copy link
Member Author

Choose a reason for hiding this comment

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

@Heenawter FYI - it looks like the searchProps.inputRef has to be a function (e.g. a state setter) and not a useRef, but you should definitely be able to auto-focus back to the searchbox once users are done with your custom filter component.

@cee-chen cee-chen marked this pull request as ready for review March 3, 2023 01:41
@kibanamachine
Copy link

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

Copy link
Contributor

@elizabetdev elizabetdev left a comment

Choose a reason for hiding this comment

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

Thanks, @cee-chen!

Tested the provided QA link in Chrome, Safari, and Firefox. It works well.

I also tested the searchable example and I confirm that it works as expected.

@cee-chen cee-chen enabled auto-merge (squash) March 6, 2023 17:58
@kibanamachine
Copy link

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

@cee-chen cee-chen merged commit e9e1200 into elastic:main Mar 6, 2023
@cee-chen cee-chen deleted the selectable-focus-children branch March 6, 2023 18:36
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.

(Accessibility) [EuiSelectable] Unable to make selections when second interactable element in focus
3 participants