Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed double search issue with [EuiFieldSearch] #3425

Merged
merged 4 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

**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