diff --git a/.changeset/seven-apricots-happen.md b/.changeset/seven-apricots-happen.md new file mode 100644 index 0000000000..feb0d79df8 --- /dev/null +++ b/.changeset/seven-apricots-happen.md @@ -0,0 +1,6 @@ +--- +"@nextui-org/modal": patch +"@nextui-org/theme": patch +--- + +adjust modal position when keyboard appears (#2837) diff --git a/packages/components/modal/src/modal-content.tsx b/packages/components/modal/src/modal-content.tsx index 23fec3da48..f9be88207a 100644 --- a/packages/components/modal/src/modal-content.tsx +++ b/packages/components/modal/src/modal-content.tsx @@ -8,7 +8,7 @@ import {TRANSITION_VARIANTS} from "@nextui-org/framer-utils"; import {CloseIcon} from "@nextui-org/shared-icons"; import {domAnimation, LazyMotion, m} from "framer-motion"; import {useDialog} from "@react-aria/dialog"; -import {chain, mergeProps} from "@react-aria/utils"; +import {chain, mergeProps, useViewportSize} from "@react-aria/utils"; import {HTMLNextUIProps} from "@nextui-org/system"; import {KeyboardEvent} from "react"; @@ -42,6 +42,8 @@ const ModalContent = forwardRef<"div", ModalContentProps, KeysToOmit>((props, _) const Component = as || DialogComponent || "div"; + const viewport = useViewportSize(); + const {dialogProps} = useDialog( { role, @@ -97,8 +99,18 @@ const ModalContent = forwardRef<"div", ModalContentProps, KeysToOmit>((props, _) ); }, [backdrop, disableAnimation, getBackdropProps]); + // set the height dynamically to avoid keyboard covering the bottom modal + const viewportStyle = { + "--visual-viewport-height": viewport.height + "px", + }; + const contents = disableAnimation ? ( -