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

Allow EuiDataGrid's default column width to update on resize #2991

Conversation

chandlerprall
Copy link
Contributor

@chandlerprall chandlerprall commented Mar 5, 2020

Summary

Fixes #2759

Problem & reproduction

When originally debugging the issue where datagrid's columns weren't sized correctly on page load, I noticed that at the initial mount, its wrapping flex row wasn't at the full size - only later did it expand to fit available space. I was able to replicate this kind of behaviour in the EUI docs by:

  • open datagrid example page
  • resize browser window to meet the mobile media query size
  • refresh
  • resize browser to screen width
  • notice that causing any kind of render pass at the top level recomputes the default column width

reproduction

Fix

  • added a useResizeObserver hook w/documentation & hook
  • implement useResizeObserver to fix the source bug in data grid

Other bug

In testing this across browsers, I found that IE11 + Safari (the two remaining with no ResizeObserver support) don't trigger the mutation observer fallback, as the content isn't mutated. This should be fixed separately, as it is a bug within the ResizeObserver fallback. I've created #3044 to track this.

Checklist

- [ ] Check against all themes for compatibility in both light and dark modes

  • Checked in mobile
  • Checked in IE11 and Firefox
    - [ ] Props have proper autodocs
    - [ ] Added documentation examples
    - [ ] Added or updated jest tests
  • Checked for breaking changes and labeled appropriately
    - [ ] Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

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

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

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

I'm ok with the approach. It'd be cooler if the observer components were based on shareable hooks and not classes, but I understand modification here

@chandlerprall
Copy link
Contributor Author

It'd be cooler if the observer components were based on shareable hooks and not classes, but I understand modification here

Definitely felt the same as I was putting this together. I'll see what I can do!

@snide snide added the priority label Mar 10, 2020
@chandlerprall chandlerprall force-pushed the bug/2759-datagrid-responsive-column-widths branch from 240b530 to b3bc695 Compare March 11, 2020 16:25
@elastic elastic deleted a comment from cla-checker-service bot Mar 11, 2020
@@ -150,6 +150,7 @@ export class EuiDataGridCell extends Component<
if (nextProps.visibleRowIndex !== this.props.visibleRowIndex) return true;
if (nextProps.colIndex !== this.props.colIndex) return true;
if (nextProps.columnId !== this.props.columnId) return true;
if (nextProps.columnType !== this.props.columnType) return true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If only React had a way to specify dependencies that also included an ESLint rule to tell you when you're missing one. Oh wait ... 😅

Maybe someday this'll be a function component with hooks.

Copy link
Contributor

@myasonik myasonik left a comment

Choose a reason for hiding this comment

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

Didn't dig into the code much, just a passing glance, but didn't see anything that would impact the component API or the accessibility so signing off on it.

Will let @thompsongl be the code eyes 🙂

@chandlerprall
Copy link
Contributor Author

@thompsongl refactored everything to be much nicer, updated PR description with more info.

@kibanamachine
Copy link

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

Copy link
Contributor

@snide snide left a comment

Choose a reason for hiding this comment

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

I don't have an answer for this and don't consider it a blocker. Just showing it in case anyone has any ideas on how to avoid the "jump". I realize I am a picky designer for even pointing it out. I may or may have recorded a video of this to make sure I wasn't seeing things, which might tell you about how small this issue is 🤣

Ultimately this is a much better tradeoff than what existed before. Tested for functionality and acts how I'd expect.

image

image

@chandlerprall
Copy link
Contributor Author

@snide nice catch! Pushed an update to fix that flash

@kibanamachine
Copy link

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

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@snide snide left a comment

Choose a reason for hiding this comment

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

Yesss! Thank you for the fix. Confirmed locally.

@kibanamachine
Copy link

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

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.

[Data Grid] Column widths need a slight pause before calculation
5 participants