Skip to content

Commit

Permalink
Add check mark to singleSelection EuiComboBox (#2890)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreadelrio authored Feb 24, 2020
1 parent 981914e commit dbdf016
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Added `image` glyph to `EuiIcon` ([#2870](https://github.com/elastic/eui/pull/2870))
- Exported TS props from top level `EuiListGroupProps`, `EuiListGroupItemProps`, `EuiSelectableProps`, `EuiSelectableOption`, `EuiSelectableOptionsListProps` ([#2869](https://github.com/elastic/eui/pull/2869))
- Extending `EuiSelectable[options]` type with correct HTML element ([#2869](https://github.com/elastic/eui/pull/2869))
- Added check mark to single selection `EuiComboBox` ([#2890](https://github.com/elastic/eui/pull/2890))

**Bug fixes**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ exports[`props singleSelection selects existing option when opened 1`] = `
},
]
}
singleSelection={true}
updatePosition={[Function]}
width={0}
/>
Expand Down
1 change: 1 addition & 0 deletions src/components/combo_box/combo_box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,7 @@ export class EuiComboBox<T> extends Component<
optionRef={this.optionRefCallback}
options={options}
position={listPosition}
singleSelection={singleSelection}
renderOption={renderOption}
rootId={this.rootId}
rowHeight={rowHeight}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import { EuiText } from '../../text';
import { EuiLoadingSpinner } from '../../loading';
import { EuiComboBoxTitle } from './combo_box_title';
import { EuiI18n } from '../../i18n';
import { EuiFilterSelectItem } from '../../filter_group/filter_select_item';
import {
EuiFilterSelectItem,
FilterChecked,
} from '../../filter_group/filter_select_item';
import { htmlIdGenerator } from '../../../services';
import {
EuiComboBoxOptionOption,
EuiComboBoxOptionsListPosition,
EuiComboBoxSingleSelectionShape,
OptionHandler,
RefCallback,
RefInstance,
Expand Down Expand Up @@ -67,6 +71,7 @@ export type EuiComboBoxOptionsListProps<T> = CommonProps &
selectedOptions: Array<EuiComboBoxOptionOption<T>>;
updatePosition: UpdatePositionHandler;
width: number;
singleSelection?: boolean | EuiComboBoxSingleSelectionShape;
};

export class EuiComboBoxOptionsList<T> extends Component<
Expand Down Expand Up @@ -167,6 +172,7 @@ export class EuiComboBoxOptionsList<T> extends Component<
scrollToIndex,
searchValue,
selectedOptions,
singleSelection,
updatePosition,
width,
...rest
Expand Down Expand Up @@ -271,12 +277,7 @@ export class EuiComboBoxOptionsList<T> extends Component<
onScroll={onScroll}
rowRenderer={({ key, index, style }) => {
const option = matchingOptions[index];
const {
isGroupLabelOption,
label,
value, // eslint-disable-line no-unused-vars
...rest
} = option;
const { isGroupLabelOption, label, value, ...rest } = option;

if (isGroupLabelOption) {
return (
Expand All @@ -286,6 +287,15 @@ export class EuiComboBoxOptionsList<T> extends Component<
);
}

let checked: FilterChecked | undefined = undefined;
if (
singleSelection &&
selectedOptions.length &&
selectedOptions[0].label === label
) {
checked = 'on';
}

return (
<EuiFilterSelectItem
style={style}
Expand All @@ -297,9 +307,10 @@ export class EuiComboBoxOptionsList<T> extends Component<
}}
ref={optionRef.bind(this, index)}
isFocused={activeOptionIndex === index}
checked={checked}
showIcons={singleSelection ? true : false}
id={rootId(`_option-${index}`)}
title={label}
showIcons={false}
{...rest}>
{renderOption ? (
renderOption(option, searchValue, OPTION_CONTENT_CLASSNAME)
Expand Down
10 changes: 8 additions & 2 deletions src/components/filter_group/filter_select_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ const resolveIconAndColor = (checked?: FilterChecked) => {
return { icon: 'empty' };
}
return checked === 'on'
? { icon: 'check', color: 'text' }
: { icon: 'cross', color: 'text' };
? {
icon: 'check',
color: 'text',
}
: {
icon: 'cross',
color: 'text',
};
};

export class EuiFilterSelectItem extends Component<EuiFilterSelectItemProps> {
Expand Down

0 comments on commit dbdf016

Please sign in to comment.