isComposingKey
Tell a key of an IME composition from a plain key, so your Enter and Escape handlers ignore keys that confirm composed text.
An IME (input method editor) is the tool for typing Chinese, Japanese, or Korean. While it composes text, a key such as Enter confirms the text and is not a command. isComposingKey tells the two apart. The function does not depend on the grid.
pnpm dlx shadcn@latest add @gridcn/is-composing-key
The item installs to components/gridcn/is-composing-key.ts.
isComposingKey
function isComposingKey(
event: React.KeyboardEvent | Pick<KeyboardEvent, "isComposing" | "keyCode">,
): boolean;The function returns true while a key belongs to an IME composition. Gate your own Enter and Escape handlers with it:
import { isComposingKey } from "@/components/gridcn/is-composing-key";
export function NameField({ onEnter }: { onEnter: () => void }) {
return (
<input
onKeyDown={(event) => {
if (isComposingKey(event)) return;
if (event.key === "Enter") onEnter();
}}
/>
);
}While an IME composes, Enter confirms the composed text and onEnter does not run.
Arguments
| Argument | Type | Meaning |
|---|---|---|
event | React keyboard event, or { isComposing, keyCode } | The keydown to test. |
Behavior
- If
isComposingistrueorkeyCodeis229, the result istrue. - Safari confirms a composition with
isComposingset tofalseandkeyCodeset to229. A test ofisComposingalone misses that key. - For a React event, the function reads
nativeEvent. - The
data-grid-sdkmodule of the core exports the same function. The grid keyboard,useCellEditor, and the text, number, URL, date, and long text editors use it. useDebouncedInputapplies the same test in itsonKeyDown. The hook carries its own copy, so theuse-debounceitem needs nois-composing-keyitem.
Related
- useDebouncedInput: the input hook that ignores keys of a composition.
- Quick search: a grid input that waits for a composition to end.
useDebouncedInput
Drive a text input that shows each keystroke at once, calls `onCommit` when the typing pauses, and keeps the last keystrokes on blur, Enter, and unmount.
Fill handle options
Look up the options of useDataGridFill, the ProcessFillContext that processFill receives, and the SeriesDescriptor that a custom detectSeries returns.