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

Added prepend and append to EuiComboBox #3003

Merged
merged 16 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from 9 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
@@ -1,5 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added `prepend` and `append` ability to `EuiComboBox` ([#3003](https://github.com/elastic/eui/pull/3003))
ashikmeerankutty marked this conversation as resolved.
Show resolved Hide resolved
- Added `EuiDataGrid`'s default sort order property ([#2987](https://github.com/elastic/eui/pull/2987))
- Fixed `EuiDataGrid`'s pagination visibility when changing rows per page ([#2978](https://github.com/elastic/eui/pull/2978))
- Added `highlightAll` prop to `EuiHighlight` to highlight all matches ([#2957](https://github.com/elastic/eui/pull/2957))
Expand Down
133 changes: 133 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 @@ -338,6 +338,7 @@ exports[`props singleSelection is rendered 1`] = `
role="combobox"
>
<EuiComboBoxInput
append={null}
autoSizeInputRef={[Function]}
compressed={false}
fullWidth={false}
Expand All @@ -352,6 +353,7 @@ exports[`props singleSelection is rendered 1`] = `
onFocus={[Function]}
onOpenListClick={[Function]}
onRemoveOption={[Function]}
prepend={null}
rootId={[Function]}
searchValue=""
selectedOptions={
Expand All @@ -369,6 +371,135 @@ exports[`props singleSelection is rendered 1`] = `
</div>
`;

exports[`props singleSelection prepend and append is rendered 1`] = `
<div
aria-expanded={true}
aria-haspopup="listbox"
className="euiComboBox euiComboBox-isOpen"
onKeyDown={[Function]}
role="combobox"
>
<EuiComboBoxInput
append="String"
autoSizeInputRef={[Function]}
compressed={false}
fullWidth={false}
hasSelectedOptions={false}
inputRef={[Function]}
isListOpen={true}
noIcon={false}
onChange={[Function]}
onClear={[Function]}
onClick={[Function]}
onCloseListClick={[Function]}
onFocus={[Function]}
onOpenListClick={[Function]}
onRemoveOption={[Function]}
prepend="String"
rootId={[Function]}
searchValue=""
selectedOptions={Array []}
singleSelection={true}
toggleButtonRef={[Function]}
updatePosition={[Function]}
value=""
/>
<EuiPortal>
<EuiComboBoxOptionsList
activeOptionIndex={-1}
areAllOptionsSelected={false}
data-test-subj=""
fullWidth={false}
listRef={[Function]}
matchingOptions={
Array [
Object {
"data-test-subj": "titanOption",
"label": "Titan",
},
Object {
"label": "Enceladus",
},
Object {
"label": "Mimas",
},
Object {
"label": "Dione",
},
Object {
"label": "Iapetus",
},
Object {
"label": "Phoebe",
},
Object {
"label": "Rhea",
},
Object {
"label": "Pandora is one of Saturn's moons, named for a Titaness of Greek mythology",
},
Object {
"label": "Tethys",
},
Object {
"label": "Hyperion",
},
]
}
onCloseList={[Function]}
onOptionClick={[Function]}
onOptionEnterKey={[Function]}
onScroll={[Function]}
optionRef={[Function]}
options={
Array [
Object {
"data-test-subj": "titanOption",
"label": "Titan",
},
Object {
"label": "Enceladus",
},
Object {
"label": "Mimas",
},
Object {
"label": "Dione",
},
Object {
"label": "Iapetus",
},
Object {
"label": "Phoebe",
},
Object {
"label": "Rhea",
},
Object {
"label": "Pandora is one of Saturn's moons, named for a Titaness of Greek mythology",
},
Object {
"label": "Tethys",
},
Object {
"label": "Hyperion",
},
]
}
position="bottom"
rootId={[Function]}
rowHeight={27}
scrollToIndex={-1}
searchValue=""
selectedOptions={Array []}
singleSelection={true}
updatePosition={[Function]}
width={0}
/>
</EuiPortal>
</div>
`;

exports[`props singleSelection selects existing option when opened 1`] = `
<div
aria-expanded={true}
Expand All @@ -378,6 +509,7 @@ exports[`props singleSelection selects existing option when opened 1`] = `
role="combobox"
>
<EuiComboBoxInput
append={null}
autoSizeInputRef={[Function]}
compressed={false}
fullWidth={false}
Expand All @@ -392,6 +524,7 @@ exports[`props singleSelection selects existing option when opened 1`] = `
onFocus={[Function]}
onOpenListClick={[Function]}
onRemoveOption={[Function]}
prepend={null}
rootId={[Function]}
searchValue=""
selectedOptions={
Expand Down
2 changes: 1 addition & 1 deletion src/components/combo_box/_combo_box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@
}
}
}
}
}
13 changes: 13 additions & 0 deletions src/components/combo_box/combo_box.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ describe('props', () => {
/>
);

component.setState({ isListOpen: true });
expect(component).toMatchSnapshot();
});
test('prepend and append is rendered', () => {
const component = shallow(
<EuiComboBox
options={options}
singleSelection={true}
prepend="String"
append="String"
/>
);

component.setState({ isListOpen: true });
expect(component).toMatchSnapshot();
});
Expand Down
10 changes: 9 additions & 1 deletion src/components/combo_box/combo_box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
import { EuiFilterSelectItem } from '../filter_group';
import AutosizeInput from 'react-input-autosize';
import { CommonProps } from '../common';
import { EuiFormControlLayoutProps } from '../form';

type DrillProps<T> = Pick<
EuiComboBoxOptionsListProps<T>,
Expand Down Expand Up @@ -73,6 +74,8 @@ interface _EuiComboBoxProps<T>
placeholder?: string;
rowHeight?: number;
singleSelection: boolean | EuiComboBoxSingleSelectionShape;
prepend?: EuiFormControlLayoutProps['prepend'];
append?: EuiFormControlLayoutProps['append'];
ashikmeerankutty marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -121,6 +124,8 @@ export class EuiComboBox<T> extends Component<
options: [],
selectedOptions: [],
singleSelection: false,
prepend: null,
append: null,
};

state: EuiComboBoxState<T> = {
Expand Down Expand Up @@ -790,6 +795,8 @@ export class EuiComboBox<T> extends Component<
rowHeight,
selectedOptions,
singleSelection,
prepend,
append,
...rest
} = this.props;
const {
Expand Down Expand Up @@ -912,8 +919,9 @@ export class EuiComboBox<T> extends Component<
toggleButtonRef={this.toggleButtonRefCallback}
updatePosition={this.updatePosition}
value={value}
append={singleSelection ? append : undefined}
prepend={singleSelection ? prepend : undefined}
/>

{optionsList}
</div>
);
Expand Down
13 changes: 11 additions & 2 deletions src/components/combo_box/combo_box_input/combo_box_input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import classNames from 'classnames';
import AutosizeInput from 'react-input-autosize';

import { EuiScreenReaderOnly } from '../../accessibility';
import { EuiFormControlLayout } from '../../form/form_control_layout';
import {
EuiFormControlLayout,
EuiFormControlLayoutProps,
} from '../../form/form_control_layout';
import { EuiComboBoxPill } from './combo_box_pill';
import { htmlIdGenerator } from '../../../services';
import { EuiFormControlLayoutIconsProps } from '../../form/form_control_layout/form_control_layout_icons';
Expand Down Expand Up @@ -49,6 +52,8 @@ export interface EuiComboBoxInputProps<T> extends CommonProps {
toggleButtonRef?: RefCallback<HTMLButtonElement | HTMLSpanElement>;
updatePosition: UpdatePositionHandler;
value?: string;
prepend?: EuiFormControlLayoutProps['prepend'];
append?: EuiFormControlLayoutProps['append'];
}

interface EuiComboBoxInputState {
Expand Down Expand Up @@ -133,6 +138,8 @@ export class EuiComboBoxInput<T> extends Component<
singleSelection: singleSelectionProp,
toggleButtonRef,
value,
prepend,
append,
} = this.props;

const singleSelection = Boolean(singleSelectionProp);
Expand Down Expand Up @@ -245,7 +252,9 @@ export class EuiComboBoxInput<T> extends Component<
icon={icon}
{...clickProps}
compressed={compressed}
fullWidth={fullWidth}>
fullWidth={fullWidth}
prepend={prepend}
append={append}>
<div
className={wrapClasses}
data-test-subj="comboBoxInput"
Expand Down