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

Add check mark to singleSelection EuiComboBox #2890

Merged
merged 8 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from 6 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
Expand Up @@ -11,6 +11,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 @@ -517,6 +517,7 @@ exports[`props singleSelection selects existing option when opened 1`] = `
},
]
}
singleSelection={true}
updatePosition={[Function]}
/>
</EuiPortal>
Expand Down
1 change: 1 addition & 0 deletions src/components/combo_box/combo_box.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ export class EuiComboBox extends Component {
getSelectedOptionForSearchValue={getSelectedOptionForSearchValue}
updatePosition={this.updateListPosition}
position={listPosition}
singleSelection={singleSelection}
renderOption={renderOption}
width={width}
scrollToIndex={activeOptionIndex}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export class EuiComboBoxOptionsList extends Component {
listRef,
updatePosition,
width,
singleSelection,
scrollToIndex,
onScroll,
rowHeight,
Expand Down Expand Up @@ -263,6 +264,14 @@ export class EuiComboBoxOptionsList extends Component {
);
}

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

return (
<EuiFilterSelectItem
style={style}
Expand All @@ -271,9 +280,10 @@ export class EuiComboBoxOptionsList extends Component {
// onEnterKey={onOptionEnterKey}
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