Skip to content

Commit

Permalink
fix: ChipTextField cursor resetting position in Safari (#978)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon authored Dec 5, 2023
1 parent 6aa3ae7 commit 91c79d5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/inputs/ChipTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ export function ChipTextField(props: ChipTextFieldProps) {
}
}}
onInput={(e: KeyboardEvent<HTMLElement>) => {
// 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}
Expand Down

0 comments on commit 91c79d5

Please sign in to comment.