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

[Discover] Fix sidebar element focus behavior when adding / removing columns #75749

Conversation

kertal
Copy link
Member

@kertal kertal commented Aug 24, 2020

Summary

The keys of the sidebar's field elements were generated by the index in the array. So when adding a column to the selected columns, its successor got the key of the element just added. This caused the weird behavior in this case (next element got focus, also the field details popover was displayed if it was active before ).

To prevent a short flickering in Chrome when clicking on the sidebar element, those elements get focus onClick

Fixes #72721

@@ -29,6 +29,5 @@ export function createDiscoverSidebarDirective(reactDirective: any) {
['onRemoveField', { watchDepth: 'reference' }],
['selectedIndexPattern', { watchDepth: 'reference' }],
['setIndexPattern', { watchDepth: 'reference' }],
['state', { watchDepth: 'reference' }],
Copy link
Member Author

Choose a reason for hiding this comment

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

PR also contains a few cleanups of unused state variable

@kertal kertal added Team:Visualizations Visualization editors, elastic-charts and infrastructure Feature:Discover Discover Application v7.10.0 release_note:fix v8.0.0 labels Aug 24, 2020
@kertal kertal self-assigned this Aug 24, 2020
@kertal kertal marked this pull request as ready for review August 24, 2020 14:57
@kertal kertal requested a review from a team August 24, 2020 14:57
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@andreadelrio
Copy link
Contributor

Untitled1

@kertal seems like there's some weird jumps of the + icon happening? Take a look at what happens when clicking on "day_of_week" and "email"

@kertal
Copy link
Member Author

kertal commented Aug 25, 2020

Untitled1

@kertal seems like there's some weird jumps of the + icon happening? Take a look at what happens when clicking on "day_of_week" and "email"

good catch, so it's because of the ownFocus property of EuiPopover, seems the first element of the list that got focus, is getting focus for milliseconds, when clicking on another side bar item. When you close the popover after clicking on 3 sidebar items, you can see the focus return to the first sidebar element. this may be browser depended behavior, what element gets focus, when you remove an element that has focus? no sure what to do here, unless manually setting focus when accessing the react element with a mouse click?

@andreadelrio
Copy link
Contributor

Untitled1
@kertal seems like there's some weird jumps of the + icon happening? Take a look at what happens when clicking on "day_of_week" and "email"

good catch, so it's because of the ownFocus property of EuiPopover, seems the first element of the list that got focus, is getting focus for milliseconds, when clicking on another side bar item. When you close the popover after clicking on 3 sidebar items, you can see the focus return to the first sidebar element. this may be browser depended behavior, what element gets focus, when you remove an element that has focus? no sure what to do here, unless manually setting focus when accessing the react element with a mouse click?

@kertal Not 100% sure I'm following, could this be a bug on the EUI side then?

@kertal
Copy link
Member Author

kertal commented Aug 27, 2020

@kertal Not 100% sure I'm following, could this be a bug on the EUI side then?

No, it's the way Chrome chooses, which element to focus, when you remove the Popover.

  1. you click on an sidebar element 1
  2. the EuiPopover 1 gets focus.
  3. you click on the sidebar element 2
  4. for a short moment, between showing Popover 1 and Popover 2, element 1 gets focus, and therefore it displays the add button
  5. you click on the sidebar element 3
  6. Chrome again decides to focus element 1, the add button is displayed, until Popover 3 is displayed
    ....

@kertal
Copy link
Member Author

kertal commented Aug 27, 2020

@elasticmachine merge upstream

@elasticmachine elasticmachine requested a review from a team as a code owner August 27, 2020 14:48
…r' of github.com:kertal/kibana into kertal-pr-2020-08-24-fix-discover-sidebar-focus-behavior
Comment on lines +136 to +138
if (ev.type === 'click') {
ev.currentTarget.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.

@andreadelrio this should prevent Chrome from setting focus to the last focused sidebar element in case of a click

Copy link
Contributor

Choose a reason for hiding this comment

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

Tested this and it seems to solve the issue properly.

Copy link
Contributor

@andreadelrio andreadelrio left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for making the adjustments.

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

Code LGTM, I tested it mainly on Chrome but also made some tests on Safari and FF, the bug is solved 🙂

<button onClick={onClick} {...buttonProps} className={buttonClasses}>
<button
onClick={(e) => {
if (e.type === 'click') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious, if it is ever something else than 'click'?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it could also be triggered by an enter key, but in this case it should already have focus

@Dosant
Copy link
Contributor

Dosant commented Sep 2, 2020

(about flickering button)
@andreadelrio: @kertal Not 100% sure I'm following, could this be a bug on the EUI side then?
@kertal: No, it's the way Chrome chooses, which element to focus, when you remove the Popover.

I don't think this is a native behaviour.
Looks like focus locking and returning is handled by: react-focus-lock under the EUI hood https://github.com/theKashey/react-focus-lock#unmounting-and-focus-management

With that in mind, I guess there is a way for EUI popover to expose more granular apis for handling focus locking. Not sure if it worth it in this case or if we are OK with proposed solution.

Copy link
Contributor

@streamich streamich left a comment

Choose a reason for hiding this comment

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

Could you please check if we need the change in field_button.tsx, I'm thinking maybe this issue is already fixed with the other changes, but if we do (confirmed with @kertal that we indeed need this), LGTM, checked on Chome/Mac.

@kertal
Copy link
Member Author

kertal commented Sep 2, 2020

(about flickering button)
@andreadelrio: @kertal Not 100% sure I'm following, could this be a bug on the EUI side then?
@kertal: No, it's the way Chrome chooses, which element to focus, when you remove the Popover.

I don't think this is a native behaviour.
Looks like focus locking and returning is handled by: react-focus-lock under the EUI hood https://github.com/theKashey/react-focus-lock#unmounting-and-focus-management

With that in mind, I guess there is a way for EUI popover to expose more granular apis for handling focus locking. Not sure if it worth it in this case or if we are OK with proposed solution.

@Dosant thx for the context and input! dear @chandlerprall & @thompsongl, are you a ok with the suggested solution to manually set focus before the EuiPopover takes focus over, or is there something that can be done on EUI side? thx

@kertal
Copy link
Member Author

kertal commented Sep 2, 2020

@elasticmachine merge upstream

@chandlerprall
Copy link
Contributor

dear @chandlerprall & @thompsongl, are you a ok with the suggested solution to manually set focus before the EuiPopover takes focus over, or is there something that can be done on EUI side? thx

Definitely worth looking into EUI's focus trap integration more. The demonstrated behaviour is unexpected, at worst I would expect it to flash focus back to the previously clicked button, not the first item in the list. I would create an EUI issue and link to it in your onClick->focus fix, so if we can resolve the issue in EUI it's a quick path back to removing this patch.

@kertal
Copy link
Member Author

kertal commented Sep 2, 2020

dear @chandlerprall & @thompsongl, are you a ok with the suggested solution to manually set focus before the EuiPopover takes focus over, or is there something that can be done on EUI side? thx

Definitely worth looking into EUI's focus trap integration more. The demonstrated behaviour is unexpected, at worst I would expect it to flash focus back to the previously clicked button, not the first item in the list. I would create an EUI issue and link to it in your onClick->focus fix, so if we can resolve the issue in EUI it's a quick path back to removing this patch.

@chandlerprall Right, so I will merge this, and create an EUI issue and link it

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

async chunks size

id value diff baseline
discover 430.7KB +20.0B 430.6KB

page load bundle size

id value diff baseline
kibanaReact 648.2KB +70.0B 648.1KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@kertal kertal merged commit 7134cd7 into elastic:master Sep 3, 2020
kertal added a commit to kertal/kibana that referenced this pull request Sep 3, 2020
…columns (elastic#75749)

* Use field.name instead of idx for key in li element

* onClick adds focus to button

* prevent Chrome jumping back to last focused element
@kertal kertal added release_note:skip Skip the PR/issue when compiling release notes and removed release_note:fix labels Sep 3, 2020
kertal added a commit that referenced this pull request Sep 3, 2020
…columns (#75749) (#76621)

* Use field.name instead of idx for key in li element

* onClick adds focus to button

* prevent Chrome jumping back to last focused element
jloleysens added a commit to jloleysens/kibana that referenced this pull request Sep 3, 2020
…nes/processors-forms-k-s

* 'master' of github.com:elastic/kibana: (216 commits)
  [Ingest Manager] Split Registry errors into Connection & Response (elastic#76558)
  [Security Solution] add an excess validation instead of the exact match (elastic#76472)
  Introduce TS incremental builds & move src/test_utils to TS project  (elastic#76082)
  fix bad merge (elastic#76629)
  [Newsfeed] Ensure the version format when calling the API (elastic#76381)
  remove server_extensions mixin (elastic#76606)
  Remove legacy applications and legacy mode (elastic#75987)
  [Discover] Fix sidebar element focus behavior when adding / removing columns (elastic#75749)
  Replace FetchOptions with ISearchOptions (elastic#76538)
  Move streams utils to the core  (elastic#76397)
  [Ingest Manager] Wording & linking improvements (elastic#76284)
  remove legacy kibana plugin (elastic#76064)
  [Form lib] Fix regression on field not being validated after reset to its default value. (elastic#76379)
  Legacy SO import: Fix bug causing multiple overrides to only show the last confirm modal (elastic#76482)
  [APM] Service maps layout enhancements (elastic#76481)
  [Security Solution][Detection Engine] Remove RuleTypeSchema in favor of Type for TypeScript (elastic#76586)
  [Security Solution][Exceptions] - Updates enum schema and tests (elastic#76544)
  Index Pattern class - remove toJSON and toString (elastic#76246)
  skip failing suite (elastic#76581)
  Split up and clarify Enterprise Search codeowners (elastic#76580)
  ...

# Conflicts:
#	x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/processor_settings_fields.tsx
#	x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/processors/foreach.tsx
jloleysens added a commit to jloleysens/kibana that referenced this pull request Sep 3, 2020
…oleysens/kibana into ingest-pipelines/processors-forms-k-s

* 'ingest-pipelines/processors-forms-k-s' of github.com:jloleysens/kibana: (216 commits)
  [Ingest Manager] Split Registry errors into Connection & Response (elastic#76558)
  [Security Solution] add an excess validation instead of the exact match (elastic#76472)
  Introduce TS incremental builds & move src/test_utils to TS project  (elastic#76082)
  fix bad merge (elastic#76629)
  [Newsfeed] Ensure the version format when calling the API (elastic#76381)
  remove server_extensions mixin (elastic#76606)
  Remove legacy applications and legacy mode (elastic#75987)
  [Discover] Fix sidebar element focus behavior when adding / removing columns (elastic#75749)
  Replace FetchOptions with ISearchOptions (elastic#76538)
  Move streams utils to the core  (elastic#76397)
  [Ingest Manager] Wording & linking improvements (elastic#76284)
  remove legacy kibana plugin (elastic#76064)
  [Form lib] Fix regression on field not being validated after reset to its default value. (elastic#76379)
  Legacy SO import: Fix bug causing multiple overrides to only show the last confirm modal (elastic#76482)
  [APM] Service maps layout enhancements (elastic#76481)
  [Security Solution][Detection Engine] Remove RuleTypeSchema in favor of Type for TypeScript (elastic#76586)
  [Security Solution][Exceptions] - Updates enum schema and tests (elastic#76544)
  Index Pattern class - remove toJSON and toString (elastic#76246)
  skip failing suite (elastic#76581)
  Split up and clarify Enterprise Search codeowners (elastic#76580)
  ...
gmmorris added a commit to gmmorris/kibana that referenced this pull request Sep 3, 2020
* master: (340 commits)
  [data.search.SearchSource] Remove legacy ES client APIs. (elastic#75943)
  [release notes] automatically retry on Github API 5xx errors (elastic#76447)
  [es_ui_shared] Fix eslint exhaustive deps rule (elastic#76392)
  [i18n] Integrate 7.9.1 Translations (elastic#76391)
  [APM] Update aggregations to support script sources (elastic#76429)
  [Security Solution] Refactor Network Top Countries to use Search Strategy (elastic#76244)
  Document security settings available on ESS (elastic#76513)
  [Ingest Manager] Add input revision to the config send to the agent (elastic#76327)
  [DOCS] Identifies cloud settings for Monitoring (elastic#76579)
  [DOCS] Identifies Cloud settings in Dev Tools (elastic#76583)
  [Ingest Manager] Better default value for fleet long polling timeout (elastic#76393)
  [data.indexPatterns] Fix broken rollup index pattern creation (elastic#76593)
  [Ingest Manager] Split Registry errors into Connection & Response (elastic#76558)
  [Security Solution] add an excess validation instead of the exact match (elastic#76472)
  Introduce TS incremental builds & move src/test_utils to TS project  (elastic#76082)
  fix bad merge (elastic#76629)
  [Newsfeed] Ensure the version format when calling the API (elastic#76381)
  remove server_extensions mixin (elastic#76606)
  Remove legacy applications and legacy mode (elastic#75987)
  [Discover] Fix sidebar element focus behavior when adding / removing columns (elastic#75749)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Discover] Focus behavior in field list is confusing
9 participants