Skip to content

Commit 5c80d96

Browse files
authored
refactor!: update multi-select-combo-box to use native popover (#9814)
1 parent 71d59b8 commit 5c80d96

File tree

8 files changed

+191
-52
lines changed

8 files changed

+191
-52
lines changed

packages/multi-select-combo-box/src/vaadin-multi-select-combo-box-mixin.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,18 @@ export const MultiSelectComboBoxMixin = (superClass) =>
418418
});
419419
}
420420

421+
/**
422+
* Override method from `ComboBoxBaseMixin` to render scroller in the slot.
423+
* @protected
424+
* @override
425+
*/
426+
_renderScroller(scroller) {
427+
scroller.setAttribute('slot', 'overlay');
428+
// Prevent focusing scroller on input Tab
429+
scroller.setAttribute('tabindex', '-1');
430+
this.appendChild(scroller);
431+
}
432+
421433
/**
422434
* Override method from `ComboBoxBaseMixin` to implement clearing logic.
423435
* @protected
@@ -487,6 +499,7 @@ export const MultiSelectComboBoxMixin = (superClass) =>
487499
// Do not commit focused item on not blur / outside click
488500
if (this._ignoreCommitValue) {
489501
this._inputElementValue = '';
502+
this._focusedIndex = -1;
490503
this._ignoreCommitValue = false;
491504
} else {
492505
this.__commitUserInput();

packages/multi-select-combo-box/src/vaadin-multi-select-combo-box-overlay.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ class MultiSelectComboBoxOverlay extends ComboBoxOverlayMixin(
4545
</div>
4646
`;
4747
}
48+
49+
/**
50+
* @protected
51+
* @override
52+
*/
53+
_attachOverlay() {
54+
this.showPopover();
55+
}
56+
57+
/**
58+
* @protected
59+
* @override
60+
*/
61+
_detachOverlay() {
62+
this.hidePopover();
63+
}
4864
}
4965

5066
defineCustomElement(MultiSelectComboBoxOverlay);

packages/multi-select-combo-box/src/vaadin-multi-select-combo-box.d.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ export interface MultiSelectComboBoxEventMap<TItem> extends HTMLElementEventMap
110110
* `helper-text` | The helper text element wrapper
111111
* `required-indicator` | The `required` state indicator element
112112
* `toggle-button` | The toggle button
113+
* `overlay` | The overlay container
114+
* `content` | The overlay content
115+
* `loader` | The loading indicator shown while loading items
113116
*
114117
* The following state attributes are available for styling:
115118
*
@@ -141,12 +144,8 @@ export interface MultiSelectComboBoxEventMap<TItem> extends HTMLElementEventMap
141144
* In addition to `<vaadin-multi-select-combo-box>` itself, the following internal
142145
* components are themable:
143146
*
144-
* - `<vaadin-multi-select-combo-box-overlay>` - has the same API as `<vaadin-overlay>`.
147+
* - `<vaadin-multi-select-combo-box-chip>`
145148
* - `<vaadin-multi-select-combo-box-item>` - has the same API as `<vaadin-item>`.
146-
* - `<vaadin-multi-select-combo-box-container>` - has the same API as `<vaadin-input-container>`.
147-
*
148-
* Note: the `theme` attribute value set on `<vaadin-multi-select-combo-box>` is
149-
* propagated to these components.
150149
*
151150
* See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
152151
*

packages/multi-select-combo-box/src/vaadin-multi-select-combo-box.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ import { MultiSelectComboBoxMixin } from './vaadin-multi-select-combo-box-mixin.
4747
* `helper-text` | The helper text element wrapper
4848
* `required-indicator` | The `required` state indicator element
4949
* `toggle-button` | The toggle button
50+
* `overlay` | The overlay container
51+
* `content` | The overlay content
52+
* `loader` | The loading indicator shown while loading items
5053
*
5154
* The following state attributes are available for styling:
5255
*
@@ -78,12 +81,8 @@ import { MultiSelectComboBoxMixin } from './vaadin-multi-select-combo-box-mixin.
7881
* In addition to `<vaadin-multi-select-combo-box>` itself, the following internal
7982
* components are themable:
8083
*
81-
* - `<vaadin-multi-select-combo-box-overlay>` - has the same API as `<vaadin-overlay>`.
84+
* - `<vaadin-multi-select-combo-box-chip>`
8285
* - `<vaadin-multi-select-combo-box-item>` - has the same API as `<vaadin-item>`.
83-
* - `<vaadin-multi-select-combo-box-container>` - has the same API as `<vaadin-input-container>`.
84-
*
85-
* Note: the `theme` attribute value set on `<vaadin-multi-select-combo-box>` is
86-
* propagated to these components.
8786
*
8887
* See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
8988
*
@@ -149,13 +148,17 @@ class MultiSelectComboBox extends MultiSelectComboBoxMixin(
149148
150149
<vaadin-multi-select-combo-box-overlay
151150
id="overlay"
151+
popover="manual"
152+
exportparts="overlay, content, loader"
152153
.owner="${this}"
153154
.opened="${this._overlayOpened}"
154155
?loading="${this.loading}"
155156
theme="${ifDefined(this._theme)}"
156157
.positionTarget="${this._inputField}"
157158
no-vertical-overlap
158-
></vaadin-multi-select-combo-box-overlay>
159+
>
160+
<slot name="overlay"></slot>
161+
</vaadin-multi-select-combo-box-overlay>
159162
160163
<slot name="tooltip"></slot>
161164
`;

packages/multi-select-combo-box/test/basic.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,4 +407,23 @@ describe('basic', () => {
407407
expect(item.textContent).to.equal('');
408408
});
409409
});
410+
411+
describe('exportparts', () => {
412+
let overlay;
413+
414+
beforeEach(() => {
415+
overlay = comboBox.$.overlay;
416+
});
417+
418+
it('should export overlay parts for styling', () => {
419+
const parts = [...overlay.shadowRoot.querySelectorAll('[part]')]
420+
.map((el) => el.getAttribute('part'))
421+
.filter((part) => part !== 'backdrop');
422+
const exportParts = overlay.getAttribute('exportparts').split(', ');
423+
424+
parts.forEach((part) => {
425+
expect(exportParts).to.include(part);
426+
});
427+
});
428+
});
410429
});

packages/multi-select-combo-box/test/chips.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ describe('chips', () => {
556556
it('should adapt overlay width to the input field width while opened', async () => {
557557
comboBox.opened = true;
558558

559-
const overlay = document.querySelector('vaadin-multi-select-combo-box-overlay');
559+
const overlay = comboBox.$.overlay;
560560
const overlayPart = overlay.$.overlay;
561561
const width = overlayPart.offsetWidth;
562562
expect(width).to.equal(comboBox.clientWidth);

0 commit comments

Comments
 (0)