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

refactor(popover): use usePreventScroll instead of react-remove-scroll #3307

Open
wants to merge 2 commits into
base: canary
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/real-cows-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/popover": patch
---

Use `usePreventScroll` instead of `react-remove-scroll`
25 changes: 12 additions & 13 deletions packages/components/popover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@
"postpack": "clean-package restore"
},
"peerDependencies": {
"react": ">=18",
"react-dom": ">=18",
"framer-motion": ">=10.17.0",
"@nextui-org/system": ">=2.0.0",
"@nextui-org/theme": ">=2.1.0",
"@nextui-org/system": ">=2.0.0"
"framer-motion": ">=10.17.0",
"react": ">=18",
"react-dom": ">=18"
},
"dependencies": {
"@nextui-org/aria-utils": "workspace:*",
"@nextui-org/framer-utils": "workspace:*",
"@nextui-org/use-aria-button": "workspace:*",
"@nextui-org/button": "workspace:*",
"@nextui-org/shared-utils": "workspace:*",
"@nextui-org/framer-utils": "workspace:*",
"@nextui-org/react-utils": "workspace:*",
"@nextui-org/shared-utils": "workspace:*",
"@nextui-org/use-aria-button": "workspace:*",
"@nextui-org/use-safe-layout-effect": "workspace:*",
"@react-aria/dialog": "3.5.14",
"@react-aria/focus": "3.17.1",
Expand All @@ -55,16 +55,15 @@
"@react-aria/utils": "3.24.1",
"@react-stately/overlays": "3.6.7",
"@react-types/button": "3.9.4",
"@react-types/overlays": "3.8.7",
"react-remove-scroll": "^2.5.6"
"@react-types/overlays": "3.8.7"
},
"devDependencies": {
"@nextui-org/theme": "workspace:*",
"@nextui-org/system": "workspace:*",
"@nextui-org/input": "workspace:*",
"@nextui-org/card": "workspace:*",
"framer-motion": "^11.0.22",
"@nextui-org/input": "workspace:*",
"@nextui-org/system": "workspace:*",
"@nextui-org/theme": "workspace:*",
"clean-package": "2.2.0",
"framer-motion": "^11.0.22",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
Expand Down
41 changes: 17 additions & 24 deletions packages/components/popover/src/popover-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {DismissButton} from "@react-aria/overlays";
import {TRANSITION_VARIANTS} from "@nextui-org/framer-utils";
import {m, domAnimation, LazyMotion} from "framer-motion";
import {HTMLNextUIProps} from "@nextui-org/system";
import {RemoveScroll} from "react-remove-scroll";
import {getTransformOrigins} from "@nextui-org/aria-utils";
import {useDialog} from "@react-aria/dialog";

Expand All @@ -24,12 +23,10 @@ const PopoverContent = forwardRef<"div", PopoverContentProps>((props, _) => {

const {
Component: OverlayComponent,
isOpen,
placement,
backdrop,
motionProps,
disableAnimation,
shouldBlockScroll,
getPopoverProps,
getDialogProps,
getBackdropProps,
Expand Down Expand Up @@ -82,27 +79,23 @@ const PopoverContent = forwardRef<"div", PopoverContentProps>((props, _) => {
);
}, [backdrop, disableAnimation, getBackdropProps]);

const contents = (
<RemoveScroll enabled={shouldBlockScroll && isOpen} removeScrollBar={false}>
{disableAnimation ? (
content
) : (
<LazyMotion features={domAnimation}>
<m.div
animate="enter"
exit="exit"
initial="initial"
style={{
...getTransformOrigins(placement === "center" ? "top" : placement),
}}
variants={TRANSITION_VARIANTS.scaleSpringOpacity}
{...motionProps}
>
{content}
</m.div>
</LazyMotion>
)}
</RemoveScroll>
const contents = disableAnimation ? (
content
) : (
<LazyMotion features={domAnimation}>
<m.div
animate="enter"
exit="exit"
initial="initial"
style={{
...getTransformOrigins(placement === "center" ? "top" : placement),
}}
variants={TRANSITION_VARIANTS.scaleSpringOpacity}
{...motionProps}
>
{content}
</m.div>
</LazyMotion>
);

return (
Expand Down
7 changes: 5 additions & 2 deletions packages/components/popover/src/use-popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {RefObject, Ref, useEffect} from "react";
import {ReactRef, useDOMRef} from "@nextui-org/react-utils";
import {OverlayTriggerState, useOverlayTriggerState} from "@react-stately/overlays";
import {useFocusRing} from "@react-aria/focus";
import {ariaHideOutside, useOverlayTrigger} from "@react-aria/overlays";
import {ariaHideOutside, useOverlayTrigger, usePreventScroll} from "@react-aria/overlays";
import {OverlayTriggerProps} from "@react-types/overlays";
import {
HTMLNextUIProps,
Expand Down Expand Up @@ -305,6 +305,10 @@ export function usePopover(originalProps: UsePopoverProps) {
}
}, [state.isOpen, domRef]);

usePreventScroll({
isDisabled: !(shouldBlockScroll && state.isOpen),
});

return {
state,
Component,
Expand All @@ -319,7 +323,6 @@ export function usePopover(originalProps: UsePopoverProps) {
isOpen: state.isOpen,
onClose: state.close,
disableAnimation,
shouldBlockScroll,
backdrop: originalProps.backdrop ?? "transparent",
motionProps,
getBackdropProps,
Expand Down
5 changes: 5 additions & 0 deletions packages/components/popover/stories/popover.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ export default {
disable: true,
},
},
shouldBlockScroll: {
control: {
type: "boolean",
},
},
},
decorators: [
(Story) => (
Expand Down
26 changes: 15 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading