TagsInput: Do not trigger submit on Enter (#48743)

* TagsInput: Do not trigger submit on Enter

* Comment
This commit is contained in:
Alex Khomenko 2022-05-05 13:37:04 +03:00 committed by GitHub
parent 3cade2f669
commit 9b8cdab123
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -85,6 +85,13 @@ export const TagsInput: FC<Props> = ({
onChange={onNameChange} onChange={onNameChange}
value={newTagName} value={newTagName}
onKeyUp={onKeyboardAdd} onKeyUp={onKeyboardAdd}
onKeyDown={(e) => {
// onKeyDown is triggered before onKeyUp, triggering submit behaviour on Enter press if this component
// is used inside forms. Moving onKeyboardAdd callback here doesn't work since text input is not captured in onKeyDown
if (e.key === 'Enter') {
e.preventDefault();
}
}}
onBlur={onBlur} onBlur={onBlur}
invalid={invalid} invalid={invalid}
suffix={ suffix={