Skip to content

Commit

Permalink
Fix submitOnEnter for single-line <InputText>
Browse files Browse the repository at this point in the history
• always blur input when submitOnEnter is true
• blurring textual <input> prevents the automatic form submission behavior on enter key, so we handle it manually
  • Loading branch information
acusti committed May 17, 2024
1 parent b54369a commit 74b6e7c
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/input-text/src/InputText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,21 +209,18 @@ export default React.forwardRef<HTMLInputElement, Props>(function InputText(
(event: React.KeyboardEvent<HTMLInputElement>) => {
if (onKeyDown) onKeyDown(event);
if (
multiLine &&
submitOnEnter &&
event.key === 'Enter' &&
!event.shiftKey &&
!event.altKey &&
!event.ctrlKey
// for multi-line inputs, shift/alt/ctrl-Enter should insert newlines
(!multiLine || (!event.shiftKey && !event.altKey && !event.ctrlKey))
) {
event.preventDefault();
const form = event.currentTarget.closest('form');
if (form) {
form.requestSubmit();
} else {
// if no form to submit, trigger input blur
event.currentTarget.blur();
}
// always blur input on Enter when submitOnEnter is true
event.currentTarget.blur();
} else if (doubleClickToEdit && inputRef.current) {
if (readOnlyState) {
if (event.key === 'Enter') {
Expand Down

0 comments on commit 74b6e7c

Please sign in to comment.