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

[EuiComboBox] autoFocus behavior #4772

Merged
merged 4 commits into from
Apr 30, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added `autoFocus` prop and functionality to `EuiComboBox` ([#4772](https://github.com/elastic/eui/pull/4772))

**Bug fixes**

- Fixed `initialFocus` prop functionality in `EuiPopover` ([#4768](https://github.com/elastic/eui/pull/4768))
Expand Down
1 change: 1 addition & 0 deletions src-docs/src/views/combo_box/combo_box.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default () => {
onCreateOption={onCreateOption}
isClearable={true}
data-test-subj="demoComboBox"
autoFocus
/>
</DisplayToggles>
);
Expand Down
43 changes: 43 additions & 0 deletions src/components/combo_box/__snapshots__/combo_box.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,49 @@ exports[`EuiComboBox is rendered 1`] = `
</div>
`;

exports[`props autoFocus is rendered 1`] = `
<div
aria-expanded={false}
aria-haspopup="listbox"
className="euiComboBox"
onKeyDown={[Function]}
role="combobox"
>
<EuiComboBoxInput
autoSizeInputRef={[Function]}
compressed={false}
fullWidth={false}
hasSelectedOptions={true}
inputRef={[Function]}
isListOpen={false}
noIcon={false}
onChange={[Function]}
onClear={[Function]}
onClick={[Function]}
onCloseListClick={[Function]}
onFocus={[Function]}
onOpenListClick={[Function]}
onRemoveOption={[Function]}
rootId={[Function]}
searchValue=""
selectedOptions={
Array [
Object {
"label": "Mimas",
},
Object {
"label": "Dione",
},
]
}
singleSelection={false}
toggleButtonRef={[Function]}
updatePosition={[Function]}
value="Mimas, Dione"
/>
</div>
`;

exports[`props delimiter is rendered 1`] = `
<div
aria-expanded={false}
Expand Down
11 changes: 11 additions & 0 deletions src/components/combo_box/combo_box.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@ describe('props', () => {

expect(component).toMatchSnapshot();
});

test('autoFocus is rendered', () => {
const component = shallow(
<EuiComboBox
options={options}
selectedOptions={[options[2], options[3]]}
/>
);

expect(component).toMatchSnapshot();
});
});

test('does not show multiple checkmarks with duplicate labels', () => {
Expand Down
6 changes: 6 additions & 0 deletions src/components/combo_box/combo_box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ export interface _EuiComboBoxProps<T>
* A special character to use as a value separator. Typically a comma `,`
*/
delimiter?: string;
/**
* Specifies that the input should have focus when the component loads
*/
autoFocus?: boolean;
}

/**
Expand Down Expand Up @@ -930,6 +934,7 @@ export class EuiComboBox<T> extends Component<
sortMatchesBy,
delimiter,
append,
autoFocus,
...rest
} = this.props;
const {
Expand Down Expand Up @@ -1060,6 +1065,7 @@ export class EuiComboBox<T> extends Component<
append={singleSelection ? append : undefined}
prepend={singleSelection ? prepend : undefined}
isLoading={isLoading}
autoFocus={autoFocus}
/>
{optionsList}
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/components/combo_box/combo_box_input/combo_box_input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export interface EuiComboBoxInputProps<T> extends CommonProps {
prepend?: EuiFormControlLayoutProps['prepend'];
append?: EuiFormControlLayoutProps['append'];
isLoading?: boolean;
autoFocus?: boolean;
}

interface EuiComboBoxInputState {
Expand Down Expand Up @@ -159,6 +160,7 @@ export class EuiComboBoxInput<T> extends Component<
prepend,
append,
isLoading,
autoFocus,
} = this.props;

const singleSelection = Boolean(singleSelectionProp);
Expand Down Expand Up @@ -300,6 +302,7 @@ export class EuiComboBoxInput<T> extends Component<
role="textbox"
style={{ fontSize: 14 }}
value={searchValue}
autoFocus={autoFocus}
/>
{removeOptionMessage}
</div>
Expand Down