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

fix: allow for scrolling long menus #3709

Merged
merged 3 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/ninety-penguins-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@twilio-paste/menu": patch
"@twilio-paste/core": patch
---

[Menu]: Adds overflow scrolling behaviour on menus with a large number of items in, currently defaulting to 10 items
Copy link
Contributor

Choose a reason for hiding this comment

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

[misspell] reported by reviewdog 🐶
"behaviour" is a misspelling of "behavior"

3 changes: 3 additions & 0 deletions packages/paste-core/components/menu/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ const StyledMenu = React.forwardRef<HTMLDivElement, BoxElementProps>(({ style, .
borderColor="colorBorderWeaker"
borderRadius="borderRadius30"
boxShadow="shadow"
// scroll at roughly 10 items
maxHeight="size40"
maxWidth="size30"
minWidth="size20"
overflowY="auto"
zIndex="zIndex20"
paddingY="space30"
_focus={{ outline: "none" }}
Expand Down
20 changes: 20 additions & 0 deletions packages/paste-core/components/menu/stories/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { StoryFn } from "@storybook/react";
import { Box } from "@twilio-paste/box";
import { AttachIcon } from "@twilio-paste/icons/esm/AttachIcon";
import { ChevronDownIcon } from "@twilio-paste/icons/esm/ChevronDownIcon";
Expand Down Expand Up @@ -457,3 +458,22 @@ export const AutoPlacementMenuStory = (): React.ReactNode => {
};

AutoPlacementMenuStory.storyName = "auto placed menu";

export const ManyItemsMenu: StoryFn = () => {
const menu = useMenuState({ visible: true });

return (
<>
<MenuButton {...menu} variant="primary">
Many items <ChevronDownIcon decorative />
</MenuButton>
<Menu {...menu} aria-label="Preferences">
{Array.from(new Array(100).keys()).map((item) => (
<MenuItem {...menu} key={item}>
Item {item}
</MenuItem>
))}
</Menu>
</>
);
};
Loading