Stop using the native event and use target.value (#16553) (#16578)

This commit is contained in:
Chris Roberson 2018-02-07 13:51:49 -05:00 committed by GitHub
parent 2f26f51748
commit 05f2ab5755
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 1 deletions

View file

@ -63,6 +63,31 @@ exports[`StepIndexPattern should disable the next step if the index pattern exis
</EuiPanel>
`;
exports[`StepIndexPattern should ensure we properly append a wildcard 1`] = `
<EuiPanel
grow={true}
hasShadow={false}
paddingSize="l"
>
<Header
characterList="\\\\, /, ?, \\", <, >, |"
errors={Array []}
goToNextStep={[Function]}
isInputInvalid={false}
isNextStepDisabled={true}
onQueryChanged={[Function]}
query="k*"
/>
<EuiSpacer
size="s"
/>
<LoadingIndices />
<EuiSpacer
size="s"
/>
</EuiPanel>
`;
exports[`StepIndexPattern should properly fetch indices for the initial query 1`] = `
<EuiPanel
grow={true}

View file

@ -144,4 +144,27 @@ describe('StepIndexPattern', () => {
expect(component).toMatchSnapshot();
});
it('should ensure we properly append a wildcard', async () => {
const component = shallow(
<StepIndexPattern
allIndices={allIndices}
isIncludingSystemIndices={false}
esService={esService}
savedObjectsClient={{
find: () => ({ savedObjects: [
{ attributes: { title: 'k*' } }
] })
}}
goToNextStep={goToNextStep}
/>
);
const instance = component.instance();
instance.onQueryChanged({ target: { value: 'k' } });
await component.update();
expect(component).toMatchSnapshot();
});
});

View file

@ -83,7 +83,7 @@ export class StepIndexPattern extends Component {
const { target } = e;
let query = target.value;
if (query.length === 1 && canAppendWildcard(e.nativeEvent.data)) {
if (query.length === 1 && canAppendWildcard(query)) {
query += '*';
this.setState({ appendedWildcard: true });
setTimeout(() => target.setSelectionRange(1, 1));