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: ensure aria-selected attribute is removed from the item clone #8275

Merged
merged 2 commits into from
Dec 5, 2024

Conversation

web-padawan
Copy link
Member

@web-padawan web-padawan commented Dec 4, 2024

Description

  • Updated selected property in ItemMixin to use sync: true so it triggers observer synchronously
  • Added call to performUpdate() on the item clone in vaadin-select to remove aria-selected
  • Added missing unit test to ensure aria-selected attribute is removed (in Lit version it was not)

Note: there was an error in the "keyboard selection" test apparently caused by the fact that "append value item" was called too late. Added await nextUpdate() to this test helped to remove the error so I think it was a test issue.

        at SelectItem.update (node_modules/lit-element/src/lit-element.ts:163:23)
        at SelectItem.performUpdate (node_modules/@lit/reactive-element/src/reactive-element.ts:1440:13)
        at Select.__appendValueItemElement (packages/select/src/vaadin-select-base-mixin.js:467:21)
        at Select.__attachSelectedItem (packages/select/src/vaadin-select-base-mixin.js:430:12)

Type of change

  • Bugfix

@vursen
Copy link
Contributor

vursen commented Dec 5, 2024

Issue: The aria-selected attribute is still not removed when the select is populated with items that have a label attribute.

<vaadin-select></vaadin-select>

<script type="module">
  import '@vaadin/select';
  import '@vaadin/list-box';
  import '@vaadin/item';
  import { render, html } from 'lit';

  const select = document.querySelector('vaadin-select');
  select.renderer = (root) => {
    render(
      html`
        <vaadin-list-box>
          <vaadin-item label="Label 0" value="value-0">Option 0</vaadin-item>
          <vaadin-item label="Label 1" value="value-1">Option 1</vaadin-item>
        </vaadin-list-box>
      `,
      root,
    );
  };
</script>

UPD: This issue is actually reproducible with both Lit and Polymer.

@web-padawan
Copy link
Member Author

This issue is actually reproducible with both Lit and Polymer.

Good catch, this seems to be caused by setting selected to true after attaching the item which is done to prevent resetting selected to false when setting select value to an item that is also disabled: vaadin/vaadin-select#106

Note, we most probably don't need selected attribute on the clone since the original issue mentions style adjustments related to padding vaadin/vaadin-select#103 - in V14 they are defined here, but in V22 we use different selector:

::slotted(*) {
padding-left: 0;
padding-right: 0;
flex: auto;
}

So IMO can remove selected from the item clone. I'd prefer to change that in a separate PR though.

@vursen
Copy link
Contributor

vursen commented Dec 5, 2024

So IMO can remove selected from the item clone. I'd prefer to change that in a separate PR though.

I'm just wondering if both issues could be resolved by ensuring the selected property is false before attaching the element. This should make it unnecessary to manually remove the aria-selected attribute and consequently enforce a sync update.

@web-padawan web-padawan changed the title fix: make selected property sync to handle value item clone refactor: remove selected attribute from value item clone Dec 5, 2024
@web-padawan web-padawan force-pushed the fix/select-lit-item-clone branch from 2d33561 to d468854 Compare December 5, 2024 11:58
@web-padawan
Copy link
Member Author

Could both issues be resolved by ensuring the selected property is false before attaching the element?

Makes sense, thanks. Updated and renamed the PR accordingly.

@web-padawan
Copy link
Member Author

UPD: unfortunately we still would need to remove aria-selected attribute with selected set to false.

@web-padawan web-padawan force-pushed the fix/select-lit-item-clone branch from d468854 to ce58212 Compare December 5, 2024 12:02
@web-padawan web-padawan changed the title refactor: remove selected attribute from value item clone fix: ensure aria-selected attribute is removed from the item clone Dec 5, 2024
Copy link

sonarqubecloud bot commented Dec 5, 2024

@web-padawan web-padawan merged commit 77d3ddf into main Dec 5, 2024
17 checks passed
@web-padawan web-padawan deleted the fix/select-lit-item-clone branch December 5, 2024 12:48
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 24.6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants