Skip to content

Commit

Permalink
Fix bug where clicking the combo box caret would focus on the button.
Browse files Browse the repository at this point in the history
- Set focus on searchInput when you click the caret to open the combo box.
- Once open, clicking it again is a no-op.
  • Loading branch information
cjcenizal committed May 23, 2018
1 parent 9c5dcf6 commit b014a1d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
21 changes: 7 additions & 14 deletions src/components/combo_box/__snapshots__/combo_box.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ exports[`EuiComboBox is rendered 1`] = `
onChange={[Function]}
onClear={[Function]}
onClick={[Function]}
onClose={[Function]}
onFocus={[Function]}
onOpen={[Function]}
onOpenListClick={[Function]}
onRemoveOption={[Function]}
searchValue=""
selectedOptions={Array []}
Expand All @@ -44,9 +43,8 @@ exports[`props isClearable is false with selectedOptions 1`] = `
isListOpen={false}
onChange={[Function]}
onClick={[Function]}
onClose={[Function]}
onFocus={[Function]}
onOpen={[Function]}
onOpenListClick={[Function]}
onRemoveOption={[Function]}
searchValue=""
selectedOptions={
Expand Down Expand Up @@ -81,9 +79,8 @@ exports[`props isClearable is false without selectedOptions 1`] = `
isListOpen={false}
onChange={[Function]}
onClick={[Function]}
onClose={[Function]}
onFocus={[Function]}
onOpen={[Function]}
onOpenListClick={[Function]}
onRemoveOption={[Function]}
searchValue=""
selectedOptions={Array []}
Expand All @@ -110,9 +107,8 @@ exports[`props isDisabled 1`] = `
isListOpen={false}
onChange={[Function]}
onClick={[Function]}
onClose={[Function]}
onFocus={[Function]}
onOpen={[Function]}
onOpenListClick={[Function]}
onRemoveOption={[Function]}
searchValue=""
selectedOptions={
Expand Down Expand Up @@ -145,9 +141,8 @@ exports[`props options 1`] = `
onChange={[Function]}
onClear={[Function]}
onClick={[Function]}
onClose={[Function]}
onFocus={[Function]}
onOpen={[Function]}
onOpenListClick={[Function]}
onRemoveOption={[Function]}
searchValue=""
selectedOptions={Array []}
Expand All @@ -174,9 +169,8 @@ exports[`props selectedOptions 1`] = `
onChange={[Function]}
onClear={[Function]}
onClick={[Function]}
onClose={[Function]}
onFocus={[Function]}
onOpen={[Function]}
onOpenListClick={[Function]}
onRemoveOption={[Function]}
searchValue=""
selectedOptions={
Expand Down Expand Up @@ -212,9 +206,8 @@ exports[`props singleSelection 1`] = `
onChange={[Function]}
onClear={[Function]}
onClick={[Function]}
onClose={[Function]}
onFocus={[Function]}
onOpen={[Function]}
onOpenListClick={[Function]}
onRemoveOption={[Function]}
searchValue=""
selectedOptions={
Expand Down
7 changes: 5 additions & 2 deletions src/components/combo_box/combo_box.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,10 @@ export class EuiComboBox extends Component {
}
};

onOpenListClick = () => {
this.searchInput.focus();
};

onSearchChange = (searchValue) => {
if (this.props.onSearchChange) {
this.props.onSearchChange(searchValue);
Expand Down Expand Up @@ -586,8 +590,7 @@ export class EuiComboBox extends Component {
onClear={isClearable && !isDisabled ? this.clearSelectedOptions : undefined}
hasSelectedOptions={selectedOptions.length > 0}
isListOpen={isListOpen}
onOpen={this.openList}
onClose={this.closeList}
onOpenListClick={this.onOpenListClick}
singleSelection={singleSelection}
isDisabled={isDisabled}
/>
Expand Down
8 changes: 3 additions & 5 deletions src/components/combo_box/combo_box_input/combo_box_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export class EuiComboBoxInput extends Component {
onClear: PropTypes.func,
hasSelectedOptions: PropTypes.bool.isRequired,
isListOpen: PropTypes.bool.isRequired,
onOpen: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
onOpenListClick: PropTypes.func.isRequired,
singleSelection: PropTypes.bool,
isDisabled: PropTypes.bool,
}
Expand Down Expand Up @@ -86,8 +85,7 @@ export class EuiComboBoxInput extends Component {
onClear,
hasSelectedOptions,
isListOpen,
onOpen,
onClose,
onOpenListClick,
singleSelection,
isDisabled,
} = this.props;
Expand Down Expand Up @@ -150,7 +148,7 @@ export class EuiComboBoxInput extends Component {

if (!isDisabled) {
clickProps.onClear = hasSelectedOptions ? onClear : undefined;
clickProps.onIconClick = isListOpen ? onClose : onOpen;
clickProps.onIconClick = isListOpen ? undefined : onOpenListClick;
}

return (
Expand Down

0 comments on commit b014a1d

Please sign in to comment.