From 91c79d528edd1c0b4bb7429a11c7adeaa4881f4a Mon Sep 17 00:00:00 2001 From: Brandon Date: Tue, 5 Dec 2023 14:04:56 -0500 Subject: [PATCH] fix: ChipTextField cursor resetting position in Safari (#978) --- src/inputs/ChipTextField.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/inputs/ChipTextField.tsx b/src/inputs/ChipTextField.tsx index 18bf02127..c866642d2 100644 --- a/src/inputs/ChipTextField.tsx +++ b/src/inputs/ChipTextField.tsx @@ -80,9 +80,11 @@ export function ChipTextField(props: ChipTextFieldProps) { } }} onInput={(e: KeyboardEvent) => { - // Prevent user from pasting content that has new line characters and replace with empty space. const target = e.target as HTMLElement; - target.textContent = target.textContent?.replace(/[\n\r]/g, " ") ?? ""; + if ("inputType" in e.nativeEvent && e.nativeEvent.inputType === "insertFromPaste") { + // Clean up any formatting from pasted text + target.innerHTML = target.textContent?.replace(/[A\n\r]/g, " ") ?? ""; + } onChange(target.textContent ?? ""); }} {...focusProps}