Skip to content
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

fix: do not reset opened state when set to open initially #8401

Closed
wants to merge 1 commit into from
Closed
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
26 changes: 13 additions & 13 deletions packages/select/src/vaadin-select-base-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export const SelectBaseMixin = (superClass) =>
value: false,
notify: true,
reflectToAttribute: true,
observer: '_openedChanged',
},

/**
Expand Down Expand Up @@ -160,7 +159,11 @@ export const SelectBaseMixin = (superClass) =>
}

static get observers() {
return ['_updateAriaExpanded(opened, focusElement)', '_updateSelectedItem(value, _items, placeholder)'];
return [
'_updateAriaExpanded(opened, focusElement)',
'_updateSelectedItem(value, _items, placeholder)',
'_openedChanged(opened, _overlayElement, _menuElement, focusElement)',
];
}

constructor() {
Expand Down Expand Up @@ -361,20 +364,16 @@ export const SelectBaseMixin = (superClass) =>
}

/** @private */
_openedChanged(opened, wasOpened) {
_openedChanged(opened, overlayElement, menuElement, focusElement) {
if (!overlayElement || !menuElement || !focusElement) {
return;
}

if (opened) {
// Avoid multiple announcements when a value gets selected from the dropdown
this._updateAriaLive(false);

if (!this._overlayElement || !this._menuElement || !this.focusElement || this.disabled || this.readonly) {
this.opened = false;
return;
}

this._overlayElement.style.setProperty(
'--vaadin-select-text-field-width',
`${this._inputContainer.offsetWidth}px`,
);
overlayElement.style.setProperty('--vaadin-select-text-field-width', `${this._inputContainer.offsetWidth}px`);

// Preserve focus-ring to restore it later
const hasFocusRing = this.hasAttribute('focus-ring');
Expand All @@ -384,7 +383,7 @@ export const SelectBaseMixin = (superClass) =>
if (hasFocusRing) {
this.removeAttribute('focus-ring');
}
} else if (wasOpened) {
} else if (this.__oldOpened) {
if (this._openedWithFocusRing) {
this.setAttribute('focus-ring', '');
}
Expand All @@ -396,6 +395,7 @@ export const SelectBaseMixin = (superClass) =>
this._requestValidation();
}
}
this.__oldOpened = opened;
}

/** @private */
Expand Down
2 changes: 1 addition & 1 deletion packages/select/test/lit-renderer-directives.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('lit renderer directives', () => {
describe('basic', () => {
beforeEach(async () => {
select = await renderOpenedSelect(container, { content: 'Content' });
overlay = select.shadowRoot.querySelector('vaadin-select-overlay');
overlay = select.$.overlay;
});

it('should set `renderer` property when the directive is attached', () => {
Expand Down
15 changes: 15 additions & 0 deletions packages/select/test/select.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,21 @@ describe('vaadin-select', () => {
});
});

describe('initially opened', () => {
beforeEach(async () => {
select = fixtureSync(`<vaadin-select opened></vaadin-select>`);
select.items = [
{ label: 'Option 0', value: 'option-0' },
{ label: 'Option 1', value: 'option-1' },
];
await nextRender();
});

it('should open the overlay when opened attribute is set initially', () => {
expect(select.$.overlay.opened).to.be.true;
});
});

describe('with value', () => {
let menu, valueButton;

Expand Down