mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-05 11:19:34 +00:00
[fix] TextInput: fix onSubmitEditing when multiline=true
Do not trigger onSubmitEditing when Shift+Enter is pressed in a multiline TextInput. Fix #524 Close #526
This commit is contained in:
committed by
Nicolas Gallagher
parent
bdaeac964c
commit
535a7b7027
@@ -237,6 +237,35 @@ describe('components/TextInput', () => {
|
|||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('multi-line input', () => {
|
||||||
|
const onSubmitEditing = jest.fn();
|
||||||
|
const input = findNativeTextarea(
|
||||||
|
mount(<TextInput defaultValue="12345" multiline onSubmitEditing={onSubmitEditing} />)
|
||||||
|
);
|
||||||
|
input.simulate('keyPress', { which: 13 });
|
||||||
|
expect(onSubmitEditing).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('multi-line input with "blurOnSubmit" triggers onSubmitEditing', () => {
|
||||||
|
const onSubmitEditing = jest.fn();
|
||||||
|
const input = findNativeTextarea(
|
||||||
|
mount(
|
||||||
|
<TextInput
|
||||||
|
blurOnSubmit
|
||||||
|
defaultValue="12345"
|
||||||
|
multiline
|
||||||
|
onSubmitEditing={onSubmitEditing}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// shift+enter should enter newline, not submit
|
||||||
|
input.simulate('keyPress', { which: 13, shiftKey: true });
|
||||||
|
input.simulate('keyPress', { which: 13 });
|
||||||
|
expect(onSubmitEditing).toHaveBeenCalledTimes(1);
|
||||||
|
expect(onSubmitEditing).not.toHaveBeenCalledWith(expect.objectContaining({ shiftKey: true }));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('prop "secureTextEntry"', () => {
|
test('prop "secureTextEntry"', () => {
|
||||||
|
|||||||
@@ -318,8 +318,8 @@ class TextInput extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!e.isDefaultPrevented() && e.which === 13) {
|
if (!e.isDefaultPrevented() && e.which === 13 && !e.shiftKey) {
|
||||||
if (onSubmitEditing) {
|
if ((blurOnSubmit || !multiline) && onSubmitEditing) {
|
||||||
e.nativeEvent = { target: e.target, text: e.target.value };
|
e.nativeEvent = { target: e.target, text: e.target.value };
|
||||||
onSubmitEditing(e);
|
onSubmitEditing(e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user