[fix] TextInput calls onSelectionChange upon user input

Fix #1018
This commit is contained in:
Nicolas Gallagher
2018-07-06 15:00:50 -07:00
parent afd5293172
commit 405a3b79e8
2 changed files with 21 additions and 11 deletions

View File

@@ -330,18 +330,27 @@ describe('components/TextInput', () => {
});
});
test('prop "onSelectionChange"', done => {
const input = findNativeInput(
mount(<TextInput defaultValue="12345" onSelectionChange={onSelectionChange} />)
);
input.simulate('select', {
target: { selectionStart: 0, selectionEnd: 3 }
describe('prop "onSelectionChange"', () => {
test('is called on select', done => {
const input = findNativeInput(
mount(<TextInput defaultValue="12345" onSelectionChange={onSelectionChange} />)
);
input.simulate('select', {
target: { selectionStart: 0, selectionEnd: 3 }
});
function onSelectionChange(e) {
expect(e.nativeEvent.selection.end).toEqual(3);
expect(e.nativeEvent.selection.start).toEqual(0);
done();
}
});
test('is called on change', () => {
const onSelectionChange = jest.fn();
const input = findNativeInput(mount(<TextInput onSelectionChange={onSelectionChange} />));
input.simulate('change');
expect(onSelectionChange).toHaveBeenCalledTimes(1);
});
function onSelectionChange(e) {
expect(e.nativeEvent.selection.end).toEqual(3);
expect(e.nativeEvent.selection.start).toEqual(0);
done();
}
});
describe('prop "onSubmitEditing"', () => {

View File

@@ -282,6 +282,7 @@ class TextInput extends Component<*> {
if (onChangeText) {
onChangeText(text);
}
this._handleSelectionChange(e);
};
_handleFocus = e => {