-
Notifications
You must be signed in to change notification settings - Fork 83
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
feat: add option to always show all chips for selected items #6515
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,14 @@ const multiSelectComboBox = css` | |
flex-basis: 0; | ||
padding: 0; | ||
} | ||
|
||
:host([all-chips-visible]) #chips { | ||
display: contents; | ||
} | ||
|
||
:host([all-chips-visible]) [class$='container'] { | ||
width: fit-content; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ensures the component expands when selecting a new item, until |
||
} | ||
`; | ||
|
||
registerStyles('vaadin-multi-select-combo-box', [inputFieldShared, multiSelectComboBox], { | ||
|
@@ -177,6 +185,7 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El | |
> | ||
<vaadin-multi-select-combo-box-container | ||
part="input-field" | ||
all-chips-visible="[[allChipsVisible]]" | ||
readonly="[[readonly]]" | ||
disabled="[[disabled]]" | ||
invalid="[[invalid]]" | ||
|
@@ -213,6 +222,19 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El | |
|
||
static get properties() { | ||
return { | ||
/** | ||
* Set to true to not collapse selected items chips into the overflow | ||
* chip and instead always show them all, causing input field to grow | ||
* and wrap into multiple lines when width is limited. | ||
* @attr {boolean} all-chips-visible | ||
*/ | ||
allChipsVisible: { | ||
type: Boolean, | ||
value: false, | ||
reflectToAttribute: true, | ||
observer: '_allChipsVisibleChanged', | ||
}, | ||
|
||
/** | ||
* Set true to prevent the overlay from opening automatically. | ||
* @attr {boolean} auto-open-disabled | ||
|
@@ -674,6 +696,13 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El | |
super._delegateAttribute(name, value); | ||
} | ||
|
||
/** @private */ | ||
_allChipsVisibleChanged(visible, oldVisible) { | ||
if (visible || oldVisible) { | ||
this.__updateChips(); | ||
} | ||
} | ||
|
||
/** | ||
* Setting clear button visible reduces total space available | ||
* for rendering chips, and making it hidden increases it. | ||
|
@@ -918,7 +947,8 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El | |
const chip = this.__createChip(items[i]); | ||
this.insertBefore(chip, refNode); | ||
|
||
if (this.$.chips.clientWidth > remainingWidth) { | ||
// If all the chips are visible, no need to measure remaining width | ||
if (!this.allChipsVisible && this.$.chips.clientWidth > remainingWidth) { | ||
chip.remove(); | ||
break; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,16 @@ registerStyles( | |
{ moduleId: 'lumo-multi-select-combo-box-overlay' }, | ||
); | ||
|
||
registerStyles( | ||
'vaadin-multi-select-combo-box-container', | ||
css` | ||
:host([all-chips-visible]) { | ||
padding-block: var(--lumo-space-xs); | ||
} | ||
`, | ||
{ moduleId: 'lumo-multi-select-combo-box-container' }, | ||
); | ||
|
||
const multiSelectComboBox = css` | ||
:host([has-value]) { | ||
padding-inline-start: 0; | ||
|
@@ -67,10 +77,18 @@ const multiSelectComboBox = css` | |
mask-image: none; | ||
} | ||
|
||
:host([all-chips-visible]) ::slotted([slot='chip']) { | ||
margin-block: calc(var(--lumo-space-xs) / 2); | ||
} | ||
|
||
::slotted([slot='chip']:not([readonly]):not([disabled])) { | ||
padding-inline-end: 0; | ||
} | ||
|
||
:host([all-chips-visible]) ::slotted([slot='input']) { | ||
min-height: calc(var(--lumo-text-field-size, var(--lumo-size-m)) - 2 * var(--lumo-space-xs)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reduced |
||
} | ||
|
||
::slotted([slot='chip']:not(:last-of-type)), | ||
::slotted([slot='overflow']:not(:last-of-type)) { | ||
margin-inline-end: var(--lumo-space-xs); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed to get
<input>
element wrapping together with chip elements. In case of Goran's addon, it worked out of the box because there wasn't any additional container around chip elements.