fix(modal): input carry over with IMEs in modal forms (#2709)

* fix(modal): prevent IME input carryover in form fields when tabbing

* chore: add changeset

* chore: chain default onKeyDown
This commit is contained in:
Ryo Matsukawa 2024-04-14 21:51:43 +09:00 committed by GitHub
parent 2829d4afae
commit eb11a7731a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
"@nextui-org/modal": patch
---
Prevent IME input carryover in form fields when tabbing

View File

@ -9,8 +9,9 @@ import {CloseIcon} from "@nextui-org/shared-icons";
import {RemoveScroll} from "react-remove-scroll";
import {domAnimation, LazyMotion, m} from "framer-motion";
import {useDialog} from "@react-aria/dialog";
import {mergeProps} from "@react-aria/utils";
import {chain, mergeProps} from "@react-aria/utils";
import {HTMLNextUIProps} from "@nextui-org/system";
import {KeyboardEvent} from "react";
import {useModalContext} from "./modal-context";
import {scaleInOut} from "./modal-transition";
@ -59,8 +60,17 @@ const ModalContent = forwardRef<"div", ModalContentProps, KeysToOmit>((props, _)
</button>
);
// Handle Tab key during IME composition to prevent input carryover
const onKeyDown = useCallback((e: KeyboardEvent) => {
if (e.key === "Tab" && e.nativeEvent.isComposing) {
e.stopPropagation();
e.preventDefault();
}
}, []);
const contentProps = getDialogProps(mergeProps(dialogProps, otherProps));
const content = (
<Component {...getDialogProps(mergeProps(dialogProps, otherProps))}>
<Component {...contentProps} onKeyDown={chain(contentProps.onKeyDown, onKeyDown)}>
<DismissButton onDismiss={onClose} />
{!hideCloseButton && closeButtonContent}
{typeof children === "function" ? children(onClose) : children}