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

Tabs (future): add carousel functionality when tabs overflow container #5355

Merged
merged 20 commits into from
Dec 12, 2024

Conversation

dougmacknz
Copy link
Contributor

@dougmacknz dougmacknz commented Dec 5, 2024

What

Add carousel to Future Tabs when tabs start overflowing the width of the viewport

Screen.Recording.2024-12-09.at.5.15.33.PM.mov

Why

Nicer than having heaps of tabs wrap to a new line

Copy link

changeset-bot bot commented Dec 5, 2024

🦋 Changeset detected

Latest commit: ea78314

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kaizen/components Patch

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

@dougmacknz dougmacknz force-pushed the KZN-2752/responsive-tabs-no-library branch 5 times, most recently from 628e223 to 2bef8d3 Compare December 9, 2024 06:07
@dougmacknz dougmacknz marked this pull request as ready for review December 9, 2024 06:10
@dougmacknz dougmacknz requested a review from a team as a code owner December 9, 2024 06:10
@dougmacknz
Copy link
Contributor Author

(putting in review for chromatic)

Copy link
Contributor

github-actions bot commented Dec 9, 2024

✨ Here is your branch preview! ✨

Last updated for commit ea78314: Add a show/hide arrow SB test for RTL

@dougmacknz dougmacknz force-pushed the KZN-2752/responsive-tabs-no-library branch 3 times, most recently from a45fed0 to 3af91bd Compare December 11, 2024 05:21
Copy link
Contributor

@HeartSquared HeartSquared left a comment

Choose a reason for hiding this comment

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

Main thing to fix that we found - we need to scroll the active tab into view if an external event changes the active tab.

const rightArrow = await canvas.findByTestId('kz-tablist-right-arrow')

await userEvent.click(rightArrow)
await new Promise((r) => setTimeout(r, 500))
Copy link
Contributor

Choose a reason for hiding this comment

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

await waitFor the left arrow should hopefully allow you to not need a timeout :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the first one yes, but then I'll still need the timeout when there's no arrow appearance/disappearance to hook into. So is it worth doing it, or just keep it consistent with the timeout

Copy link
Contributor

Choose a reason for hiding this comment

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

Checking that the element is not in the dom when you expect it to disappear probably should work?
I'd just try to avoid timeouts when you have an explicit result you're waiting for, because it's still potentially flaky. It only makes sense to use it when the thing you're testing has functionality that relies on timeouts. It's okay as a last resort if nothing else works though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The timeout is actually more robust than that. Your idea works okay when it's testing for disappearance, but hooking into appearance actually breaks this.

The problem with testing for appearance/disappearance is that that doesn't mean the animation is done. The sequence goes:

  • Press right -> animation starts -> left arrow appears -> animation finishes.

Even with disappearance, it's closer, but it still doesn't mean the animation is done because of the threshold of 75% (it disappears before the element is completely out of view).

So testing for left arrow appearing ends up trying to press right again before the animation is done and it breaks.

There's another issue as well as mentioned in my last comment: if the example had more tabs in it, or if we reduce the scroll amount, there's not always an arrow appearing or disappearing on each press (only the first and last presses). There would be times where both arrows are showing before the press, and continuing to show after press.

The main thing I don't love at the moment is the magical number on the timeout.

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 we want to go deep on this, we could see if there's a way to hook into/run a callback when the scrolling is finished.

e.g.
https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollend_event

Not supported on Safari tho :(

@dougmacknz dougmacknz force-pushed the KZN-2752/responsive-tabs-no-library branch from 3af91bd to ea78314 Compare December 12, 2024 02:09
Copy link
Contributor

@HeartSquared HeartSquared left a comment

Choose a reason for hiding this comment

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

Just some nits. Feel free to merge if you wish :)

@@ -0,0 +1 @@
export const SCROLL_AMOUNT = 120
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Haha, probably didn't need to make a separate file for this since we only use it in the one place. But no matter.

import { TabList as RACTabList, TabListProps as RACTabListProps } from 'react-aria-components'
import {
TabList as RACTabList,
TabListProps as RACTabListProps,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
TabListProps as RACTabListProps,
type TabListProps as RACTabListProps,

@dougmacknz dougmacknz merged commit f6bd88c into main Dec 12, 2024
17 of 19 checks passed
@dougmacknz dougmacknz deleted the KZN-2752/responsive-tabs-no-library branch December 12, 2024 22:35
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.

2 participants