Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/stupid-sheep-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@siemens/ix": minor
---

**ix-select** in multiple-mode now displays "+<number>" for the number of items that are select after more than two items have been selected.
21 changes: 20 additions & 1 deletion packages/core/src/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,25 @@ export class Select implements IxInputFieldComponent<string | string[]> {
);
}

private renderOverflowChip(overflowCount: number) {
return (
<ix-filter-chip disabled={this.disabled} readonly={true} key="overflow">
{`+${overflowCount}`}
</ix-filter-chip>
);
}

private renderChips() {
const maxVisibleChips = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The maximum number of visible chips is hardcoded to 2. This 'magic number' makes the component less flexible and harder to maintain. Consider exposing this as a prop to allow consumers to configure this value. This would make the component more reusable.

For example:

  /**
   * The maximum number of visible chips in multiple mode.
   * If more items are selected, an overflow chip will be displayed.
   */
  @Prop() maxVisibleChips = 2;

Then you can use this.maxVisibleChips in the renderChips method.

const visibleItems = this.selectedItems.slice(0, maxVisibleChips);
const overflowCount = this.selectedItems.length - maxVisibleChips;

return [
...visibleItems.map((item) => this.renderChip(item)),
overflowCount > 0 ? this.renderOverflowChip(overflowCount) : null,
];
}

@HookValidationLifecycle()
onValidationChange({
isInvalid,
Expand Down Expand Up @@ -926,7 +945,7 @@ export class Select implements IxInputFieldComponent<string | string[]> {
this.items.length !== 0 &&
(this.shouldDisplayAllChip()
? this.renderAllChip()
: this.selectedItems?.map((item) => this.renderChip(item)))}
: this.renderChips())}
<div class="trigger">
<input
autocomplete="off"
Expand Down
Loading