-
Notifications
You must be signed in to change notification settings - Fork 16
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
table: frozen columns #1720
base: develop
Are you sure you want to change the base?
table: frozen columns #1720
Conversation
🦋 Changeset detectedLatest commit: 5d533df The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
import { TableContext } from './TableContext'; | ||
import { useScrollerContext } from './ScrollerContext'; | ||
|
||
const MAX_FIXED_COLUMNS_FROM_LEFT = 1; |
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.
This allows us to use a future-proof API of frozenColumns?: number[];
instead of something like isFirstColFrozen
, isLastColFrozen
.
return { | ||
[minContainerBreakpointForFrozenColumns]: { | ||
...acc[minContainerBreakpointForFrozenColumns], | ||
[`& :nth-child(${columnNumber}):where(td, th)`]: { |
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.
Emotion complains about nth-child
but it seems fine as no style
tags are inserted and the component can't be customised.
css={{ | ||
position: 'relative', | ||
width: '100%', | ||
<ScrollerContext.Provider |
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.
A lot of the changes in this file are just due to this context wrapper.
|
…xtra stories for single frozen columns
throw Error( | ||
'ScrollerContext not found. If using a Table, ensure it is wrapped with <TableWrapper>.' | ||
); |
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.
I'm a little concerned by this because I'm not confident that all consumers are currently using the <TableWrapper>
🤔
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.
Yep, have just checked and it's not always used…
@@ -23,6 +32,8 @@ export function TableScroller({ children }: TableScrollerProps) { | |||
const [thumbPosition, setThumbPosition] = useState(0); | |||
const [thumbWidthRatio, setThumbWidthRatio] = useState(0); |
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.
Not your doing, but just noticed lots of flash of scrollbars disappearing on mount, so we should assume that it doesn't have scrollbars until it does. Might even be worth adding a comment to that effect
const [thumbWidthRatio, setThumbWidthRatio] = useState(0); | |
const [thumbWidthRatio, setThumbWidthRatio] = useState(1); |
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.
Yeah ok, I'll look into this. Knowing not everyone has the TableWrapper
, I think we'll need a different approach to this scrollbar + overlay with frozen columns functionality.
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.
I was thinking that scrollbar should still just be in TableWrapper, so that way, people who use it get the benefits of the scrollbar and those that don't, don't, but they may have their own solution or none is needed.
The other stuff should be moved out though.
If this isn't technically possible, then we'll have to revert TableWrapper to what it used to be and move the scroller elsehwere
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.
Yeah, the scrollbar needs the overlay according to our designs. The overlay doesn't need x-axis offsets if there's no frozen columns. So, I think it'll be all fine to do that part. If we can put the scroller inside the Table
, then we don't need the extra context I added. Just need to look into it more.
background: boxPalette.borderMuted, | ||
width: '1px', |
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.
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.
Why is that? Doesn't it signify the hard edge of scroll, as opposed to the frozen column?
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.
I don't think so. I think it only signifies the edge of a fixed column that isn't scrolled. The table should keep its "blank" edges in its normal 0 or fully scrolled states
background: boxPalette.borderMuted, | ||
width: '1px', |
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.
...(scrollerHeight && { height: `${scrollerHeight / 16}rem` }), | ||
|
||
// Switch between single line at full scroll and overlay shadow at partial scroll | ||
...(scrollerRef.current?.scrollLeft === 0 |
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 should transition these shadows so they don't appear abruptly
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.
- transition overlays
I haven't reviewed the code yet, but it does all seem to function remarkably well 💪 |
Quality Gate failedFailed conditions |
Adds support for frozen columns in tables. Also fixes the caption so that it doesn't scroll horizontally as the table is scrolled.
View preview
Scroll far left:
Scroll middle:
Scroll far right:
Small screens (below medium breakpoint using container queries):
Checklist
Preflight
accordion: Updated padding
ordocs: Updated header links
yarn changeset
. Learn more about change management.Testing
yarn test
to ensure tests are passing. If required, runyarn test -u
to update any generated snapshots.Documentation