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

Fix EuiFieldSearch's onChange call so it is always called with the Event #2764

Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `18.2.0`.
**Bug fixes**

- Fixed `EuiFieldSearch`'s trigger of `onChange` when clearing the field value ([#2764](https://github.com/elastic/eui/pull/2764))

## [`18.2.0`](https://github.com/elastic/eui/tree/v18.2.0)

Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/form_controls/field_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class extends Component {

onChange = e => {
this.setState({
value: e === '' ? '' : e.target.value,
value: e.target.value,
});
};

Expand Down
14 changes: 13 additions & 1 deletion src/components/form/field_search/field_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,19 @@ export class EuiFieldSearch extends Component {
}

onClear = () => {
this.props.onChange('');
// clear the field's value
this.inputElement.value = '';

// dispatch onChange event, with IE11 support/fallback
if ('createEvent' in document) {
const evt = document.createEvent('HTMLEvents');
evt.initEvent('change', true, false);
this.inputElement.dispatchEvent(evt);
} else {
this.inputElement.fireEvent('onchange');
}

// set focus on the search field
this.inputElement.focus();
};

Expand Down