-
Notifications
You must be signed in to change notification settings - Fork 30
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
Carousel container portal navigation #13162
base: main
Are you sure you want to change the base?
Conversation
Hello 👋! When you're ready to run Chromatic, please apply the You will need to reapply the label each time you want to run Chromatic. |
Size Change: -657 B (-0.08%) Total Size: 870 kB
ℹ️ View Unchanged
|
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.
Should we pass sectionId
to scrollable/feature too?
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 don't as scrollable feature is only scrollable on mobile and mobile doesnt have navigation buttons, its just swipe controlled.
61b622f
to
5c72902
Compare
e015978
to
5c72902
Compare
The |
What does this change?
Refactors the carousel navigation buttons to use a React portal.
A portal allows rendering the button elements outside of the normal React component hierarchy, enabling flexibility in their placement within the DOM. This is particularly useful when the buttons need to be positioned outside the visual boundaries of the carousel component itself, such as on the fronts containers.
Why?
Depending on the breakpoint, the carousel front containers have their buttons placed outside of the component, in line with either the section heading or the left column. This had previously been achieved by using negative margins and absolute positioning to move the buttons outside of the container. This however, was quite brittle solution as it had to be calculate using the font size and line height of the container title and it also caused overlapping with the show/hide buttons as they occupied the same space.
By using portals, we can achieve a distinct position in the dom between the containers and there navigation buttons whilst still coupling the code in the carousel component.
The portal dynamically identifies a DOM element by constructing its ID using the
sectionId
prop and appends the suffix-carousel-navigation
. This allows us to create distinct navigation portals per carousel.If the target DOM element is not found, a warning is logged in the console. The buttons will not be rendered if the portal target is unavailable.
As well as refactoring the nav buttons, this pr also hooks up show/hide with the beta containers and add a hidden class to the nav buttons so that they can also be hidden when a containers is closed.
Screenshots
Screen.Recording.2025-01-16.at.09.40.41.mov