Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions packages/eui/.storybook/loki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export const LOKI_SELECTORS = {
* Portal element content selector
*/
portal: '[data-euiportal="true"]',
/**
* Body selector
* TODO: remove when LOKI_SELECTORS.portal selector works as expected again
*/
body: 'body',
} as const;

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/eui/changelogs/upcoming/7800.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Updated `EuiComboBox` to support output of `option.append` and `option.prepend` for options used as group labels with `isGroupLabel=true`
Comment thread
mgadewoll marked this conversation as resolved.
Outdated

68 changes: 65 additions & 3 deletions packages/eui/src/components/combo_box/combo_box.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import { action } from '@storybook/addon-actions';
import { userEvent, waitFor, within, expect } from '@storybook/test';

import { LOKI_SELECTORS, lokiPlayDecorator } from '../../../.storybook/loki';
import { EuiComboBox, EuiComboBoxProps } from './combo_box';
import { EuiComboBoxOptionMatcher } from './types';
import { EuiCode } from '../code';
import { EuiFlexItem } from '../flex';

import { EuiComboBoxOptionMatcher } from './types';
import { EuiComboBox, EuiComboBoxProps } from './combo_box';

const toolTipProps = {
toolTipContent: 'This is a tooltip!',
Expand Down Expand Up @@ -85,7 +87,8 @@ export const WithTooltip: Story = {
},
loki: {
// popover and tooltip are rendered in a portal
chromeSelector: LOKI_SELECTORS.portal,
// LOKI_SELECTOR.portal currently doesn't work so we use body instead
chromeSelector: LOKI_SELECTORS.body,
},
},
args: {
Expand Down Expand Up @@ -160,6 +163,65 @@ export const CustomMatcher: Story = {
},
};

export const Groups: Story = {
parameters: {
controls: {
include: ['options'],
},
loki: {
chromeSelector: LOKI_SELECTORS.body,
},
},
args: {
options: [
{ label: 'Group 1', isGroupLabelOption: true },
...[...options].splice(0, 3),
{
label: 'Group 2',
isGroupLabelOption: true,
prepend: '#prepend ',
append: (
<EuiFlexItem css={{ alignItems: 'flex-end' }}>(append)</EuiFlexItem>
),
},
...[...options].splice(3, options.length),
],
autoFocus: true,
},
render: (args) => <StatefulComboBox {...args} />,
};

export const NestedOptionsGroups: Story = {
parameters: {
controls: {
include: ['options'],
},
loki: {
chromeSelector: LOKI_SELECTORS.body,
},
},
args: {
options: [
{
label: 'Group 1',
isGroupLabelOption: true,
options: [...options].splice(0, 3),
},
{
label: 'Group 2',
isGroupLabelOption: true,
prepend: '#prepend ',
append: (
<EuiFlexItem css={{ alignItems: 'flex-end' }}>(append)</EuiFlexItem>
),
options: [...options].splice(3, options.length),
},
],
autoFocus: true,
},
render: (args) => <StatefulComboBox {...args} />,
};

const StatefulComboBox = ({
singleSelection,
onCreateOption,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* works.
*/
.euiComboBoxTitle {
font-size: $euiFontSizeXS;
padding: ($euiSizeXS + $euiSizeS - 1px) $euiSizeS $euiSizeXS; /* 1 */
display: flex;
width: 100%;
padding: ($euiSizeXS + $euiSizeS - 1px) $euiSizeS $euiSizeXS; /* 1 */
font-size: $euiFontSizeXS;
Comment thread
mgadewoll marked this conversation as resolved.
font-weight: $euiFontWeightBold;
color: $euiColorFullShade;
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ export class EuiComboBoxOptionsList<T> extends Component<
if (isGroupLabelOption) {
return (
<div key={key ?? label} style={style}>
<EuiComboBoxTitle>{label}</EuiComboBoxTitle>
<EuiComboBoxTitle>
{prepend}
{label}
{append}
</EuiComboBoxTitle>
</div>
);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/eui/src/components/combo_box/matching_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ export const getMatchingOptions = <T>({
key: option.key,
label: option.label,
isGroupLabelOption: true,
append: option.append,
prepend: option.prepend,
});
// Add matching options for group
// use concat over spreading to support large arrays - https://mathiasbynens.be/demo/javascript-argument-count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
* Side Public License, v 1.
*/

import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { action } from '@storybook/addon-actions';

import {
enableFunctionToggleControls,
moveStorybookControlsToCategory,
} from '../../../../.storybook/utils';
import { EuiFlexItem } from '../../flex';
import { EuiSelectableOption } from '../selectable_option';

import { EuiSelectableList, EuiSelectableListProps } from './selectable_list';

const options: EuiSelectableOption[] = [
Expand Down Expand Up @@ -107,3 +110,34 @@ export const Playground: Story = {
},
},
};

export const Groups: Story = {
parameters: {
controls: {
include: ['options'],
},
},
args: {
options: [
{ label: 'Group 1', isGroupLabel: true },
...[...options].splice(0, 4),
{
label: 'Group 2',
isGroupLabel: true,
prepend: '#prepend ',
Comment thread
mgadewoll marked this conversation as resolved.
Outdated
append: (
<EuiFlexItem css={{ alignItems: 'flex-end' }}>(append)</EuiFlexItem>
Comment on lines +134 to +135

@cee-chen cee-chen May 30, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm that's odd, the append nodes shouldn't need extra CSS from consumers to get them to align to the right 🤔 Is this only happening for group labels? We may need to add some extra CSS in EUI if so

@mgadewoll mgadewoll May 30, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, currently this is "needed". The passed append/prepend is output as is. There is no further styling or layout handling added. (code here)

If we only pass the flex item it'll grow but it's left aligned
Screenshot 2024-05-30 at 17 16 58

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh gotcha. I wonder if we should add more OOTB styling for this? Probably an out of scope question for this PR, I'll ponder it more later / during either the Emotion conversion for this component or the EuiComboBox<>Selectable work!

),
},
...[...options].splice(4, options.length),
],
activeOptionIndex: 0,
makeOptionId: (index) => `selectable_list_item-${index}`,
// ensuring that onOptionClick triggers an action as it's
// only called through setActiveOptionIndex callback
setActiveOptionIndex: (index, callback) => {
callback?.();
action('setActiveOptionIndex')(index);
},
},
};