-
Notifications
You must be signed in to change notification settings - Fork 25
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
Fix DropdownMenu
component issues
#2804
Conversation
🦋 Changeset detectedLatest commit: 9dbc6c6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 96 packages
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 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
</Section> | ||
)) | ||
.add('DropdownMenu - List menu content', () => { | ||
const optionsCount = number('Options count', 5); |
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 is to allow having long lists in the dropdown menu so the height and scrollability can be tested.
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.
💯
@@ -40,6 +47,48 @@ export type TDropdownMenuProps = { | |||
children: ReactNode; | |||
}; | |||
|
|||
function getScrollableParent(element: HTMLElement | null): HTMLElement | null { |
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 want to block the scroll of the nearest ancestor with scrolling enabled, if any.
return getScrollableParent(element.parentElement); | ||
} | ||
|
||
function useScrollBlock(isOpen: boolean, triggerRef: RefObject<HTMLElement>) { |
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.
Just to extract a bit of logic from the component itself.
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.
Works as expected 🙇🏽♂️
Thank you
</Section> | ||
)) | ||
.add('DropdownMenu - List menu content', () => { | ||
const optionsCount = number('Options count', 5); |
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.
Thanks for fixing it! 🙏
Summary
Fix
DropdownMenu
component issues related to floating menu size and scrolling.Closes #2786
Description
This PR tries to fix two problems:
This is how we tackle those issues:
body
scroll, but this component might be rendered in a scrollable container, so now we look for its first scrollable ancestor to block it while the dropdown is opened. It can be the case of multiple scroll containers in the page which might lead to potential issues, but we want to have a quick fix released for the majority of the use cases.menuMaxHeight
) which consumers can use to limit the height of the floating menu however they want.Something that we intentionally left out of the scope of this PR is how to deal with dropdown menus opening the floating menu always downwards, which is not convenient when the triggering element is at the bottom of the page.
We will work on that as a follow up so we can release these fixes to make the component usable.