-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[DataTable] Remove fixed column UX #1605
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
Conversation
a1b7fd2
to
72e2e9e
Compare
72e2e9e
to
2498d91
Compare
Love the 🍏 : 🔴 ratio, going to 🎩 this tonight! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
width: $fixed-column-width; | ||
white-space: unset; | ||
min-width: $first-column-width; | ||
max-width: $first-column-width; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know why min and max work but not width? And I wonder if a different min-width would work. No need to take the extra space on mobile if the column width is not needed is what I'm thinking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question! I think I originally took the set width out and had no min/max, but the first column gets squished into almost nothing on small devices when the content is long and word-break: break-word
is set. So I was playing with adding either a max or a min when truncated and removing the work-break
, but forgot to take on or the other back out.
What I landed on is that normal table behavior should be the default, and if implementations want to have set minimum or maximum we can always enhance with a prop. So now there's only a min-width when truncate
is true
so that the first column is forced to truncate at that size.
The code looks good. Just a question about the min-width. Also, any way to increase code coverage or is this mostly a Percy job? |
I've got coverage up to almost 70%. I'm all for getting to 90%, but but it seems that the other codepaths are style related conditionals that aren't testable by anything but Percy. Since this bug is keeping all tables from displaying their first column across mobile, I don't think codecov passing should block shipping this. |
2498d91
to
e63ec8a
Compare
a9f8c66
to
d46e3c5
Compare
|
||
const headingMarkup = ( | ||
<tr> | ||
{headings.map((heading, headingIndex) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(extracted this anonymous callback into a class method like the other render{Row} callbacks, see 126 and 246)
); | ||
} | ||
|
||
private tallestCellHeights = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No more need to calculate/set/update row heights manually anymore. With the absolute positioning removed, normal table wrapping and resizing behavior is restored 🙌
} | ||
}; | ||
|
||
private setHeightsAndScrollPosition = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scroll position needed to be preserved when the row heights were being managed manually because the horizontal scroll position would be reset on rerender (most notably after clicking a sortable cell heading). This is no longer an issue.
); | ||
}; | ||
|
||
private renderFooter = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the absolute positioning of the first column cells made positioning the footer content seem egregious. I've changed the footer content to be rendered within a div
as a sibling to table's scroll container so calculating/setting/updating the footer's height and the scroll container's bottom margin is no longer needed.
onSort(headingIndex, newSortDirection); | ||
|
||
if (!truncate && this.scrollContainer.current) { | ||
const preservedScrollPosition = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
const direction = sorted ? sortDirection : defaultSortDirection; | ||
const source = direction === 'ascending' ? CaretUpMinor : CaretDownMinor; | ||
const source = direction === 'descending' ? CaretDownMinor : CaretUpMinor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(fixes icon to align with sort defaulting to ascending)
@dleroux @AndrewMusgrave After spending tonight working on codecov, I removed a bunch of additional code that was also no longer needed because of scrapping the fixed first column. Essentially, this component is much easier to reason about without that UX 🎉 |
Need a second look as more deadweight code was removed and codecov was increased.
I have written some tests for Data Table in a local branch last frideations, but haven't had the time to open a PR yet. I'll see if I can do that this friday, but don't let that stop you from shipping this :) |
}; | ||
|
||
const columnVisibilityData = collapsedHeaderCells.map( | ||
const columnVisibilityData = Array.from(headerCells).map( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array.from is used a few times here. Judging by this https://www.measurethat.net/Benchmarks/ShowResult/59877 looks like spreading is more performant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to change headerCells
from a NodeList to an Array, it's not spreadable unfortunately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know what scratch that. I just tried it and TS doesn't yell about it anymore!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎩 looks good. Great job on the testing. Funny to see so much code go ahead yet more additions because of testing. Just let a comment on array.from
vs spread
, but looks good!
206181b
to
29ecb85
Compare
WHY are these changes introduced?
Fixes #913 Finishes #1426
WHAT is this pull request doing?
The absolute positioning of the first column cells is no longer working across supported browsers, specifically Safari iOS (which means it doesn't work in any mobile browser in iOS). After @dleroux and I each explored other ways to accomplish the same UX with different CSS, there wasn't a clear path forward that doesn't cause other parts of the table to break.
I concluded that the fixed column experience is not worth the hacks or tradeoffs needed to fix in iOS nor the risk of future breaks. Removing the fixed first column enables removal of all the excessive complexity that went into maintaining the default table behavior of row height change etc.
truncate
is trueHow to 🎩
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
Copy-paste this code in
playground/Playground.tsx
:🎩 checklist