Skip to content

Commit b1580c7

Browse files
authored
fix(combobox): add space after grouped items (#7302)
**Related Issue:** #6412 ## Summary Adding space at the bottom of grouped items to provide visual separation between the group and any following content. - Bottom padding added to combobox-item-group at all scales. - Added padding would not be present if the group has no items, allowing for the use of only the group heading (with no extra padding) when nesting groups. <img width="375" alt="CleanShot 2023-07-10 at 09 19 44@2x" src="https://github.com/Esri/calcite-design-system/assets/19231036/192e1b23-53c0-4a09-8d78-8322d26b99e0">
1 parent 60a4683 commit b1580c7

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

packages/calcite-components/src/components/combobox-item-group/combobox-item-group.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@
4949
padding-inline: var(--calcite-combobox-item-spacing-unit-s);
5050
margin-inline-start: var(--calcite-combobox-item-indent-value);
5151
}
52+
53+
::slotted(calcite-combobox-item-group:not([after-empty-group])) {
54+
padding-block-start: var(--calcite-combobox-item-spacing-unit-l);
55+
}

packages/calcite-components/src/components/combobox-item-group/combobox-item-group.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ export class ComboboxItemGroup {
2121
//
2222
// --------------------------------------------------------------------------
2323

24+
/**
25+
* When `true`, signifies that the group comes after another group without any children (items or sub-groups), otherwise indicates that the group comes after another group that has children. Used for styling.
26+
*
27+
* @internal
28+
*/
29+
@Prop({ reflect: true }) afterEmptyGroup = false;
30+
2431
/** Specifies the parent and grandparent `calcite-combobox-item`s, which are set on `calcite-combobox`. */
2532
@Prop({ mutable: true }) ancestors: ComboboxChildElement[];
2633

packages/calcite-components/src/components/combobox/combobox.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,7 @@
209209

210210
@include hidden-form-input();
211211
@include base-component();
212+
213+
::slotted(calcite-combobox-item-group:not(:first-child)) {
214+
padding-block-start: var(--calcite-combobox-item-spacing-unit-l);
215+
}

packages/calcite-components/src/components/combobox/combobox.stories.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -449,17 +449,31 @@ export const withSelectorIndicatorAndIcons_TestOnly = (): string => html`
449449
</calcite-combobox>
450450
`;
451451

452-
export const nestedGroups_TestOnly =
453-
(): string => html`<calcite-combobox open selection-mode="single" style="width:400px" placeholder="Type to filter">
454-
<calcite-combobox-item-group label="Level 1">
455-
<calcite-combobox-item-group label="Level 2">
456-
<calcite-combobox-item-group label="Level 3">
457-
<calcite-combobox-item value="Item 1" text-label="Item 1">
458-
</calcite-combobox-item>
459-
<calcite-combobox-item value="Item 2" text-label="Item 2">
452+
export const nestedGroups_TestOnly = (): string => html`
453+
<calcite-combobox label="test" placeholder="placeholder" max-items="10" scale="m" open>
454+
<calcite-combobox-item-group label="First item group">
455+
<calcite-combobox-item value="Pikachu" text-label="Pikachu"></calcite-combobox-item>
456+
<calcite-combobox-item value="Charizard" text-label="Charizard"></calcite-combobox-item>
457+
458+
<calcite-combobox-item-group label="Cutest Pokémon">
459+
<calcite-combobox-item value="Bulbasaur" text-label="Bulbasaur"></calcite-combobox-item>
460+
<calcite-combobox-item-group label="No Pokémon 🙃"></calcite-combobox-item-group>
461+
462+
<calcite-combobox-item-group label="Cutest Pokémon">
463+
<calcite-combobox-item value="Squirtle" text-label="Squirtle">
464+
<calcite-combobox-item value="Charizard" text-label="Charizard"></calcite-combobox-item>
465+
</calcite-combobox-item>
466+
</calcite-combobox-item-group>
467+
</calcite-combobox-item-group>
468+
</calcite-combobox-item-group>
469+
470+
<calcite-combobox-item-group label="Last item group">
471+
<calcite-combobox-item value="Squirtle" text-label="Squirtle">
472+
<calcite-combobox-item value="Charizard" text-label="Charizard"></calcite-combobox-item>
460473
</calcite-combobox-item>
461474
</calcite-combobox-item-group>
462-
</calcite-combobox>`;
475+
</calcite-combobox>
476+
`;
463477

464478
export const clearDisabled_TestOnly = (): string => html`
465479
<calcite-combobox clear-disabled selection-mode="single" style="width:400px">

packages/calcite-components/src/components/combobox/combobox.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,18 @@ export class Combobox
967967
if (!this.allowCustomValues) {
968968
this.setMaxScrollerHeight();
969969
}
970+
971+
this.groupItems.forEach((groupItem, index, items) => {
972+
if (index === 0) {
973+
groupItem.afterEmptyGroup = false;
974+
}
975+
976+
const nextGroupItem = items[index + 1];
977+
978+
if (nextGroupItem) {
979+
nextGroupItem.afterEmptyGroup = groupItem.children.length === 0;
980+
}
981+
});
970982
};
971983

972984
getData(): ItemData[] {

0 commit comments

Comments
 (0)