Skip to content

Commit 8a7678b

Browse files
authored
fix: set max-height on scroller when pre-opened (#4052)
1 parent 5356052 commit 8a7678b

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎packages/combo-box/src/vaadin-combo-box-mixin.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,11 @@ export const ComboBoxMixin = (subclass) =>
442442
// eslint-disable-next-line max-params
443443
_updateScroller(scroller, items, opened, loading, selectedItem, itemIdPath, focusedIndex, renderer, theme) {
444444
if (scroller) {
445+
if (opened) {
446+
scroller.style.maxHeight =
447+
getComputedStyle(this).getPropertyValue(`--${this._tagNamePrefix}-overlay-max-height`) || '65vh';
448+
}
449+
445450
scroller.setProperties({
446451
items: opened ? items : [],
447452
opened,
@@ -849,10 +854,6 @@ export const ComboBoxMixin = (subclass) =>
849854
_onOpened() {
850855
// Defer scroll position adjustment to improve performance.
851856
requestAnimationFrame(() => {
852-
// When opened is set as attribute, this logic needs to be delayed until scroller is created.
853-
this._scroller.style.maxHeight =
854-
getComputedStyle(this).getPropertyValue(`--${this._tagNamePrefix}-overlay-max-height`) || '65vh';
855-
856857
this._scrollIntoView(this._focusedIndex);
857858

858859
// Set attribute after the items are rendered when overlay is opened for the first time.

‎packages/combo-box/test/basic.test.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,4 +569,15 @@ describe('pre-opened', () => {
569569
const actualOverlayWidth = comboBox.$.overlay.$.content.clientWidth;
570570
expect(actualOverlayWidth).to.eq(expectedOverlayWidth);
571571
});
572+
573+
it('should have overlay with correct width', () => {
574+
const comboBox = fixtureSync(`
575+
<vaadin-combo-box
576+
opened
577+
items="[0]"
578+
style="--vaadin-combo-box-overlay-max-height: 200px"
579+
></vaadin-combo-box>`);
580+
const scroller = comboBox.$.overlay.querySelector('vaadin-combo-box-scroller');
581+
expect(scroller.style.maxHeight).to.equal('200px');
582+
});
572583
});

0 commit comments

Comments
 (0)