Skip to content

Commit

Permalink
fix: do not throw when opened is set before adding to DOM (#7335)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Apr 15, 2024
1 parent 8e5223b commit a5ac705
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
9 changes: 9 additions & 0 deletions packages/select/src/vaadin-lit-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ class Select extends SelectBaseMixin(ElementMixin(ThemableMixin(PolylitMixin(Lit
`;
}

/** @protected */
ready() {
super.ready();

const overlay = this.shadowRoot.querySelector('vaadin-select-overlay');
overlay.owner = this;
this._overlayElement = overlay;
}

/** @private */
_onOpenedChanged(event) {
this.opened = event.detail.value;
Expand Down
4 changes: 0 additions & 4 deletions packages/select/src/vaadin-select-base-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ export const SelectBaseMixin = (superClass) =>
ready() {
super.ready();

const overlay = this.shadowRoot.querySelector('vaadin-select-overlay');
overlay.owner = this;
this._overlayElement = overlay;

this._inputContainer = this.shadowRoot.querySelector('[part~="input-field"]');

this._valueButtonController = new ButtonController(this);
Expand Down
11 changes: 11 additions & 0 deletions packages/select/src/vaadin-select-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ export class SelectOverlay extends PositionMixin(OverlayMixin(DirMixin(ThemableM
`;
}

/** @protected */
ready() {
super.ready();

// When setting `opened` as an attribute, the overlay is already teleported to body
// by the time when `ready()` callback of the `vaadin-select` is executed by Polymer,
// so querySelector() would return null. So we use this workaround to set properties.
this.owner = this.__dataHost;
this.owner._overlayElement = this;
}

requestContentUpdate() {
super.requestContentUpdate();

Expand Down
15 changes: 15 additions & 0 deletions packages/select/test/pre-opened-polymer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect } from '@esm-bundle/chai';
import { fixtureSync } from '@vaadin/testing-helpers';
import '../vaadin-select.js';

// NOTE: this test is Polymer only as it checks for Polymer specific bug.
// Do not import `not-animated-styles.js` in this test intentionally, as
// otherwise the immediately closed overlay would make it false positive.

describe('pre-opened', () => {
it('should not throw error when adding a pre-opened select', () => {
expect(() => {
fixtureSync('<vaadin-select opened></vaadin-select>');
}).to.not.throw(Error);
});
});

0 comments on commit a5ac705

Please sign in to comment.