Skip to content

Commit

Permalink
Adds onFocus prop to EuiComboBox (#1375)
Browse files Browse the repository at this point in the history
* Added onFocus prop to EuiComboBox

* Update src/components/combo_box/index.d.ts

Co-Authored-By: zumwalt <[email protected]>

* Import FocusEventHandler
  • Loading branch information
zumwalt authored Dec 17, 2018
1 parent 2f80577 commit 28e0a1a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added `onFocus` prop to `EuiComboBox` ([#1375](https://github.com/elastic/eui/pull/1375))
- Added `DisambiguateSet` and `ExclusiveUnion` utility types ([#1368](https://github.com/elastic/eui/pull/1368))

**Bug fixes**
Expand Down
8 changes: 6 additions & 2 deletions src/components/combo_box/combo_box.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class EuiComboBox extends Component {
options: PropTypes.array,
selectedOptions: PropTypes.array,
onChange: PropTypes.func,
onFocus: PropTypes.func,
onSearchChange: PropTypes.func,
onCreateOption: PropTypes.func,
renderOption: PropTypes.func,
Expand Down Expand Up @@ -262,7 +263,10 @@ export class EuiComboBox extends Component {
return flattenOptionGroups(options).length === selectedOptions.length;
};

onFocus = () => {
onComboBoxFocus = () => {
if (this.props.onFocus) {
this.props.onFocus();
}
this.openList();
}

Expand Down Expand Up @@ -597,7 +601,7 @@ export class EuiComboBox extends Component {
onRemoveOption={this.onRemoveOption}
onClick={this.onComboBoxClick}
onChange={this.onSearchChange}
onFocus={this.onFocus}
onFocus={this.onComboBoxFocus}
value={value}
searchValue={searchValue}
autoSizeInputRef={this.autoSizeInputRef}
Expand Down
3 changes: 2 additions & 1 deletion src/components/combo_box/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ButtonHTMLAttributes, ReactNode, SFC } from 'react';
import { ButtonHTMLAttributes, ReactNode, SFC, FocusEventHandler } from 'react';
import { ListProps } from 'react-virtualized';
import {
EuiComboBoxOption,
Expand Down Expand Up @@ -64,6 +64,7 @@ declare module '@elastic/eui' {
options?: EuiComboBoxOptionsListProps['options'],
selectedOptions?: EuiComboBoxOptionsListProps['selectedOptions'],
onChange?: (options: Array<EuiComboBoxOptionProps>) => any,
onFocus?: FocusEventHandler<HTMLInputElement>,
onSearchChange?: (searchValue: string) => any,
onCreateOption?: EuiComboBoxOptionsListProps['onCreateOption'],
renderOption?: EuiComboBoxOptionsListProps['renderOption'],
Expand Down

0 comments on commit 28e0a1a

Please sign in to comment.