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] Adding hit enter badge #3782

Merged
merged 10 commits into from
Jul 23, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Added `analyzeEvent` glyph in `EuiIcon` ([#3729](https://github.com/elastic/eui/pull/3729))
- Updated `EuiComboBox` to allow the options list to open for single selection custom options ([#3706](https://github.com/elastic/eui/pull/3706))
- Added `useEuiI18n` hook for localization ([#3749](https://github.com/elastic/eui/pull/3749))
- Added a hit enter badge to `EuiComboBox` when focusing an option and for empty states that allow pressing enter ([#3782](https://github.com/elastic/eui/pull/3782))

**Bug fixes**

Expand Down
108 changes: 72 additions & 36 deletions src/components/combo_box/__snapshots__/combo_box.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,15 @@ exports[`props options list is rendered 1`] = `
<div
class="euiFlexItem euiFilterSelectItem__content"
>
<span
class="euiComboBoxOption__content"
<div
class="euiComboBoxOption__contentWrapper"
>
Titan
</span>
<span
class="euiComboBoxOption__content"
>
Titan
</span>
</div>
</div>
</span>
</button>
Expand All @@ -364,11 +368,15 @@ exports[`props options list is rendered 1`] = `
<div
class="euiFlexItem euiFilterSelectItem__content"
>
<span
class="euiComboBoxOption__content"
<div
class="euiComboBoxOption__contentWrapper"
>
Enceladus
</span>
<span
class="euiComboBoxOption__content"
>
Enceladus
</span>
</div>
</div>
</span>
</button>
Expand All @@ -387,11 +395,15 @@ exports[`props options list is rendered 1`] = `
<div
class="euiFlexItem euiFilterSelectItem__content"
>
<span
class="euiComboBoxOption__content"
<div
class="euiComboBoxOption__contentWrapper"
>
Mimas
</span>
<span
class="euiComboBoxOption__content"
>
Mimas
</span>
</div>
</div>
</span>
</button>
Expand All @@ -410,11 +422,15 @@ exports[`props options list is rendered 1`] = `
<div
class="euiFlexItem euiFilterSelectItem__content"
>
<span
class="euiComboBoxOption__content"
<div
class="euiComboBoxOption__contentWrapper"
>
Dione
</span>
<span
class="euiComboBoxOption__content"
>
Dione
</span>
</div>
</div>
</span>
</button>
Expand All @@ -433,11 +449,15 @@ exports[`props options list is rendered 1`] = `
<div
class="euiFlexItem euiFilterSelectItem__content"
>
<span
class="euiComboBoxOption__content"
<div
class="euiComboBoxOption__contentWrapper"
>
Iapetus
</span>
<span
class="euiComboBoxOption__content"
>
Iapetus
</span>
</div>
</div>
</span>
</button>
Expand All @@ -456,11 +476,15 @@ exports[`props options list is rendered 1`] = `
<div
class="euiFlexItem euiFilterSelectItem__content"
>
<span
class="euiComboBoxOption__content"
<div
class="euiComboBoxOption__contentWrapper"
>
Phoebe
</span>
<span
class="euiComboBoxOption__content"
>
Phoebe
</span>
</div>
</div>
</span>
</button>
Expand All @@ -479,11 +503,15 @@ exports[`props options list is rendered 1`] = `
<div
class="euiFlexItem euiFilterSelectItem__content"
>
<span
class="euiComboBoxOption__content"
<div
class="euiComboBoxOption__contentWrapper"
>
Rhea
</span>
<span
class="euiComboBoxOption__content"
>
Rhea
</span>
</div>
</div>
</span>
</button>
Expand All @@ -502,11 +530,15 @@ exports[`props options list is rendered 1`] = `
<div
class="euiFlexItem euiFilterSelectItem__content"
>
<span
class="euiComboBoxOption__content"
<div
class="euiComboBoxOption__contentWrapper"
>
Pandora is one of Saturn's moons, named for a Titaness of Greek mythology
</span>
<span
class="euiComboBoxOption__content"
>
Pandora is one of Saturn's moons, named for a Titaness of Greek mythology
</span>
</div>
</div>
</span>
</button>
Expand All @@ -525,11 +557,15 @@ exports[`props options list is rendered 1`] = `
<div
class="euiFlexItem euiFilterSelectItem__content"
>
<span
class="euiComboBoxOption__content"
<div
class="euiComboBoxOption__contentWrapper"
>
Tethys
</span>
<span
class="euiComboBoxOption__content"
>
Tethys
</span>
</div>
</div>
</span>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,25 @@
}
}

.euiComboBoxOption__contentWrapper {
display: flex;
flex-direction: row;
}

.euiComboBoxOption__enterBadge {
align-self: flex-start;
margin-left: $euiSizeXS;
}

.euiComboBoxOption__content {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
flex: 1;
text-align: left;
}

.euiComboBoxOption__emptyStateText {
flex: 1;
text-align: left;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
ListChildComponentProps,
} from 'react-window';

import { EuiCode } from '../../../components/code';
import { EuiFlexGroup, EuiFlexItem } from '../../flex';
import { EuiHighlight } from '../../highlight';
import { EuiPanel } from '../../panel';
Expand All @@ -52,6 +51,7 @@ import {
UpdatePositionHandler,
} from '../types';
import { CommonProps } from '../../common';
import { EuiBadge } from '../../badge/';

const positionToClassNameMap: {
[position in EuiComboBoxOptionsListPosition]: string
Expand Down Expand Up @@ -103,6 +103,13 @@ export type EuiComboBoxOptionsListProps<T> = CommonProps &
zIndex?: number;
};

const hitEnterBadge = (
<EuiBadge className="euiComboBoxOption__enterBadge" color="hollow">
miukimiu marked this conversation as resolved.
Show resolved Hide resolved
<EuiI18n token="euiComboBoxOptionsList.hitEnter" default="Hit enter" />{' '}
miukimiu marked this conversation as resolved.
Show resolved Hide resolved
&#x021A9;
miukimiu marked this conversation as resolved.
Show resolved Hide resolved
</EuiBadge>
);

export class EuiComboBoxOptionsList<T> extends Component<
EuiComboBoxOptionsListProps<T>
> {
Expand Down Expand Up @@ -228,6 +235,8 @@ export class EuiComboBoxOptionsList<T> extends Component<
checked = 'on';
}

const optionIsFocused = activeOptionIndex === index;

return (
<EuiFilterSelectItem
style={style}
Expand All @@ -238,21 +247,30 @@ export class EuiComboBoxOptionsList<T> extends Component<
}
}}
ref={optionRef.bind(this, index)}
isFocused={activeOptionIndex === index}
isFocused={optionIsFocused}
checked={checked}
showIcons={singleSelection ? true : false}
id={rootId(`_option-${index}`)}
title={label}
{...rest}>
{renderOption ? (
renderOption(option, searchValue, OPTION_CONTENT_CLASSNAME)
) : (
<EuiHighlight
search={searchValue}
className={OPTION_CONTENT_CLASSNAME}>
{label}
</EuiHighlight>
)}
<div className="euiComboBoxOption__contentWrapper">
{renderOption ? (
<div className={OPTION_CONTENT_CLASSNAME}>
miukimiu marked this conversation as resolved.
Show resolved Hide resolved
{renderOption(
option,
searchValue,
'euiComboBoxOption__renderOption'
)}
</div>
) : (
<EuiHighlight
search={searchValue}
className={OPTION_CONTENT_CLASSNAME}>
{label}
</EuiHighlight>
)}
{optionIsFocused ? hitEnterBadge : null}
</div>
</EuiFilterSelectItem>
);
};
Expand Down Expand Up @@ -327,28 +345,33 @@ export class EuiComboBoxOptionsList<T> extends Component<
);
} else {
emptyStateContent = (
<p>
<EuiI18n
token="euiComboBoxOptionsList.createCustomOption"
default="Hit {key} to add {searchValue} as a custom option"
values={{
key: <EuiCode>ENTER</EuiCode>,
searchValue: <strong>{searchValue}</strong>,
}}
/>
</p>
<div className="euiComboBoxOption__contentWrapper">
<p className="euiComboBoxOption__emptyStateText">
<EuiI18n
token="euiComboBoxOptionsList.createCustomOption"
default="Add {searchValue} as a custom option"
values={{
searchValue: <strong>{searchValue}</strong>,
}}
/>
</p>
{hitEnterBadge}
</div>
);
}
} else {
if (delimiter && searchValue.includes(delimiter)) {
emptyStateContent = (
<p>
<EuiI18n
token="euiComboBoxOptionsList.delimiterMessage"
default="Hit enter to add each item separated by {delimiter}"
values={{ delimiter: <strong>{delimiter}</strong> }}
/>
</p>
<div className="euiComboBoxOption__contentWrapper">
<p className="euiComboBoxOption__emptyStateText">
<EuiI18n
token="euiComboBoxOptionsList.delimiterMessage"
default="Add each item separated by {delimiter}"
values={{ delimiter: <strong>{delimiter}</strong> }}
/>
</p>
{hitEnterBadge}
</div>
);
} else {
emptyStateContent = (
Expand Down