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

[EuiDataGrid] Fix sorting console errors + header cell focus cleanup/refactors #5209

Merged

Conversation

cee-chen
Copy link
Member

@cee-chen cee-chen commented Sep 22, 2021

Summary

This PR contains 2 console error fixes, a functionality removal that was already not working on master, several cleanup/refactors of the EuiHeaderGridCellWrapper focus code (that I noticed and wanted to work on while debugging/fixing the above bugs), and several unit test improvements. I strongly recommend following along by commit.

  • Console error fixes
    • 6be8f53
      • I noticed that when dragging a column outside the popover, a destination is null error appears in the console:
      • This commit adds a simple object existence check to ensure it's not null.
    • ac5e058
      • closes [EuiDataGrid] Sorting columns after focusing a header cell throws console errors #4384
      • Currently in Safari, clicking on a header cell and then opening the Columns popover and attemping to drag/drop reorder the clicked header cell causes a focus fight:
      • This happens because the focusin/focusout events are firing repeatedly on the moved headercell, triggering focus events on the header cell and causing a fight between the cell and the reorder popover.
      • Removing the manual focusInteractives() call and instead relying on setIsCellEntered(true) removes this lock/fight, because the state change does not repeatedly call itself
      • TBH, It's possible that this isFocused conditional branch isn't even needed with current header cell behavior, but this is a pretty simple fix, so I'm leaving it as is
  • Functionality removal
    • 405b1c0
      • I chatted with @chandlerprall earlier to confirm that F2 keyboard event behavior is not working on master, and it makes sense that it isn't. We agreed that the logic for it can be removed, since we treat the header cell itself as the widget, which means there isn't a discernible focus state between cell focus or widget focus.
      • We also console warn when header control cells (which can contain any children) contain more than one interactable element.
  • Refactors
    • The remaining commits deal with several cleanups (mostly moving and combining code / unit tests) and is easier to follow along by commit.

QA

  • Go to https://eui.elastic.co/pr_5209/#/tabular-content/data-grid
  • In the Columns popover, confirm that dragging and dropping a column outside the popover does not generate a console error
  • In the Safari browser, confirm that clicking a header cell and then opening the Columns popover and trying to drag/drop the clicked header cell does not create a stack call console error

Checklist

- [ ] Check against all themes for compatibility in both light and dark modes
- [ ] Checked in mobile (toolbar doesn't appear on mobile)

  • Checked in Chrome, Safari, Edge, and Firefox

- [ ] Props have proper autodocs and playground toggles
- [ ] Added documentation
- [ ] Checked Code Sandbox works for any docs examples

- [ ] Checked for breaking changes and labeled appropriately

  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

Setting isCellEntered to true already makes that same call, so *should* have that same effect as long as we're consistent about changing logic via isCellEntered

This also fixes elastic#4384, which was a focus-lock issue caused focusin/focusout events firing multiple times. Now with the setIsCellEntered change, focus does not fire repeatedly
- now that we're not calling enableInteractives and focusInteractives directly but letting isCellEntered handle that for us, there's no need to include them

+ setIsCellEntered isn't necessary either/doesn't trigger the lint rule
- Separate focus tests for isFocused logic vs focusin / focusout events
- Removes the need for useCallback and setting the utility fns as dependencies, simplifying code

- refactor for loops to forEach's

- remove setIsCellEntered(true) in focusInteractables, since it now only gets called when isCellEntered is true
- they don't get called separately, so it makes sense to optimize the call and not make an extra tabbables call (+ reduces unnecessary branching)
- covers last uncovered branch in file

- move to bottom of the file rather than top, since after talking to Chandler this is an edge case that only applies to control header cells

+ remove `data-euigrid-tab-managed` attr - tests should pass without it
- convert functions to arrow functions
- use shorter headerNode var instead of ref
- it's had no effect since we switched header cells to use a popover for actions
@kibanamachine
Copy link

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

@cee-chen cee-chen marked this pull request as ready for review September 22, 2021 17:35
Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

Approving that #4384 will be fixed with this PR, tested in Chrome, Firefox, Safari, works as expected 👍

@cee-chen
Copy link
Member Author

@chandlerprall or @thompsongl - any chance one of you can review at this PR sometime this week? Or alternatively, is @kertal's approval with the fix sufficient for merge? Thanks as always for your time!

@@ -20,7 +20,7 @@ describe('EuiDataGridHeaderCellWrapper', () => {
id: 'someColumn',
index: 0,
headerIsInteractive: true,
children: <button data-euigrid-tab-managed="true" />,
children: <button />,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ugh, good catch!!

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

LGTM; good fixes & refactors! ship it 🦑

@cee-chen
Copy link
Member Author

Thanks Chandler!!

@cee-chen cee-chen enabled auto-merge (squash) September 27, 2021 19:49
@kibanamachine
Copy link

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

@cee-chen cee-chen merged commit 6fe740c into elastic:master Sep 27, 2021
@cee-chen cee-chen deleted the datagrid-header-cell-wrapper-refactors branch September 27, 2021 20:23
@kibanamachine
Copy link

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

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.

[EuiDataGrid] Sorting columns after focusing a header cell throws console errors
4 participants