Skip to content

Commit

Permalink
Fixed double search issue with [EuiFieldSearch] (#3425)
Browse files Browse the repository at this point in the history
* fixed double search issue

* CL

* used isSearchSupported

* covered edge case of conflict with incremental and enter key
  • Loading branch information
anishagg17 authored May 6, 2020
1 parent 84bbe8d commit 81080bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ No public interface changes since `23.2.0`.

**Bug Fixes**

- Fixed `EuiFieldSearch` to trigger `onSearch` single time instead of two times ([#3425](https://github.com/elastic/eui/pull/3425))
- Fixed `EuiBasicTable` item selection when `id` is `0` ([#3417](https://github.com/elastic/eui/pull/3417))
- Fixed `EuiNavDrawer` not closing on outside click after being unlocked ([#3415](https://github.com/elastic/eui/pull/3415))
- Fixed `EuiBadge` `iconOnClick` props makes badge text clickable ([#3392](https://github.com/elastic/eui/pull/3392))
Expand Down
16 changes: 12 additions & 4 deletions src/components/form/field_search/field_search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import React, { Component, InputHTMLAttributes, KeyboardEvent } from 'react';
import classNames from 'classnames';
import { Browser } from '../../../services/browser';
import { ENTER } from '../../../services/key_codes';
import { CommonProps } from '../../common';
import { ENTER } from '../../../services/key_codes';

import {
EuiFormControlLayout,
Expand Down Expand Up @@ -76,6 +76,8 @@ interface EuiFieldSearchState {
value: string;
}

let isSearchSupported: boolean = false;

export class EuiFieldSearch extends Component<
EuiFieldSearchProps,
EuiFieldSearchState
Expand All @@ -97,10 +99,11 @@ export class EuiFieldSearch extends Component<

componentDidMount() {
if (!this.inputElement) return;
if (Browser.isEventSupported('search', this.inputElement)) {
isSearchSupported = Browser.isEventSupported('search', this.inputElement);
if (isSearchSupported) {
const onSearch = (event?: Event) => {
if (this.props.onSearch) {
if (!event || !event.target) return;
if (!event || !event.target || event.defaultPrevented) return;
this.props.onSearch((event.target as HTMLInputElement).value);
}
};
Expand Down Expand Up @@ -187,7 +190,12 @@ export class EuiFieldSearch extends Component<
return;
}
}
if (onSearch && (incremental || event.keyCode === ENTER)) {

if (
onSearch &&
((event.keyCode !== ENTER && incremental) ||
(event.keyCode === ENTER && !isSearchSupported))
) {
onSearch((event.target as HTMLInputElement).value);
}
};
Expand Down

0 comments on commit 81080bf

Please sign in to comment.