Skip to content

Commit 5a09b64

Browse files
fix(input): allow Enter key to work when allowMultilinePaste is enabled
The bug was in `TextInput`: with `allowMultilinePaste` enabled, a standalone Enter key could match the newline-paste fallback before submit handling. Change: - Only treat newline input as paste fallback when `input.length > 1`. - Added regression test: multiline value + `allowMultilinePaste` + Enter submits and does not call `onChange`.
1 parent 7fe2749 commit 5a09b64

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/components/TextInput/TextInput.test.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,25 @@ describe('TextInput', () => {
136136
expect(onSubmit).toHaveBeenCalledWith('test');
137137
});
138138

139+
it('submits on Enter when multiline paste is enabled', async () => {
140+
const onChange = vi.fn();
141+
const onSubmit = vi.fn();
142+
const { stdin } = render(
143+
<TextInput
144+
value={'one\ntwo'}
145+
allowMultilinePaste
146+
onChange={onChange}
147+
onSubmit={onSubmit}
148+
/>,
149+
);
150+
151+
stdin.write(KEY.ENTER);
152+
await time.tick();
153+
154+
expect(onSubmit).toHaveBeenCalledWith('one\ntwo');
155+
expect(onChange).not.toHaveBeenCalled();
156+
});
157+
139158
it('inserts bracketed pasted text with newlines without submitting', async () => {
140159
const onChange = vi.fn();
141160
const onSubmit = vi.fn();

src/components/TextInput/TextInput.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ export function TextInput({
150150
return;
151151
}
152152

153-
const hasPastedNewlines = allowMultilinePaste && /[\r\n]/.test(input);
153+
const hasPastedNewlines =
154+
allowMultilinePaste && input.length > 1 && /[\r\n]/.test(input);
154155

155156
if (hasPastedNewlines) {
156157
insertText(normalizePastedText(input));

0 commit comments

Comments
 (0)