Skip to content

Commit

Permalink
fix: prevent scroll element (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3m01 authored Feb 26, 2024
1 parent 55e0432 commit 95fec3b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/core/src/combobox/combobox-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export function ComboboxContent(props: ComboboxContentProps) {
});

createPreventScroll({
element: () => ref ?? null,
enabled: () => context.isOpen() && context.preventScroll(),
});

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/date-picker/date-picker-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export function DatePickerContent(props: DatePickerContentProps) {
});

createPreventScroll({
element: () => ref ?? null,
enabled: () => context.isModal() && context.isOpen(),
});

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/dialog/dialog-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export function DialogContent(props: DialogContentProps) {
});

createPreventScroll({
element: () => ref ?? null,
enabled: () => context.isOpen() && context.preventScroll(),
});

Expand Down
14 changes: 13 additions & 1 deletion packages/core/src/menu/menu-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,24 @@ export interface MenuContentProps
extends OverrideComponentProps<"div", MenuContentOptions> {}

export function MenuContent(props: MenuContentProps) {
let ref: HTMLElement | undefined;

const rootContext = useMenuRootContext();
const context = useMenuContext();

const [local, others] = splitProps(props, ["ref"]);

createPreventScroll({
element: () => ref ?? null,
enabled: () => context.isOpen() && rootContext.preventScroll(),
});

return <MenuContentBase {...props} />;
return (
<MenuContentBase
ref={mergeRefs((el) => {
ref = el;
}, local.ref)}
{...others}
/>
);
}
1 change: 1 addition & 0 deletions packages/core/src/popover/popover-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export function PopoverContent(props: PopoverContentProps) {
});

createPreventScroll({
element: () => ref ?? null,
enabled: () => context.isOpen() && context.preventScroll(),
});

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/select/select-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export function SelectContent(props: SelectContentProps) {
});

createPreventScroll({
element: () => ref ?? null,
enabled: () => context.isOpen() && context.preventScroll(),
});

Expand Down

0 comments on commit 95fec3b

Please sign in to comment.