Skip to content

Commit

Permalink
refactor: remove selected attribute from value item clone
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Dec 5, 2024
1 parent ce58212 commit 2d33561
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
13 changes: 4 additions & 9 deletions packages/select/src/vaadin-select-base-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,10 @@ export const SelectBaseMixin = (superClass) =>
// Store reference to the original item
labelItem._sourceItem = selected;

this.__appendValueItemElement(labelItem, this.focusElement);
// Cleanup selected and aria-selected
labelItem.selected = false;

// Ensure the item gets proper styles
labelItem.selected = true;
this.__appendValueItemElement(labelItem, this.focusElement);
}

/**
Expand Down Expand Up @@ -461,13 +461,8 @@ export const SelectBaseMixin = (superClass) =>
*/
__appendValueItemElement(itemElement, parent) {
parent.appendChild(itemElement);
// Trigger observer that sets aria-selected attribute
// so that we can then synchronously remove it below.
if (itemElement.performUpdate) {
itemElement.performUpdate();
}
itemElement.removeAttribute('tabindex');
itemElement.removeAttribute('aria-selected');

itemElement.removeAttribute('role');
itemElement.removeAttribute('focused');
itemElement.removeAttribute('focus-ring');
Expand Down
2 changes: 1 addition & 1 deletion packages/select/test/keyboard.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe('keyboard', () => {
expect(clone.textContent).to.be.equal(item.textContent);
});

['active', 'focused', 'focus-ring', 'role', 'tabindex', 'aria-selected'].forEach((attr) => {
['active', 'focused', 'focus-ring', 'role', 'tabindex', 'selected'].forEach((attr) => {
it(`should remove ${attr} attribute from the item clone`, async () => {
await sendKeys({ press: 'Tab' });

Expand Down
12 changes: 2 additions & 10 deletions packages/select/test/select.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,6 @@ describe('vaadin-select', () => {
expect(select._overlayElement.opened).to.be.false;
});

it('should preserve the selected attribute when selecting the disabled item', async () => {
menu.selected = 5;
await nextUpdate(select);
const valueElement = valueButton.firstChild;
expect(valueElement.selected).to.be.true;
expect(valueElement.disabled).to.be.true;
});

it('should not update value if the selected item does not have a value', async () => {
menu.selected = 2;
await nextUpdate(select);
Expand All @@ -180,13 +172,13 @@ describe('vaadin-select', () => {
expect(valueButton.textContent.trim()).to.be.equal('o2');
});

it('should wrap the selected item `label` string in selected vaadin item', async () => {
it('should wrap the selected item `label` string in vaadin-select-item', async () => {
menu.selected = 1;
await nextUpdate(select);
const item = valueButton.firstElementChild;
expect(item.localName).to.equal('vaadin-select-item');
expect(item.textContent).to.equal('o2');
expect(item.selected).to.be.true;
expect(item.selected).to.be.false;
expect(item.getAttribute('tabindex')).to.be.null;
});

Expand Down

0 comments on commit 2d33561

Please sign in to comment.