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

Refactor select #1794

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Refactor select #1794

wants to merge 20 commits into from

Conversation

jpzwarte
Copy link
Member

@jpzwarte jpzwarte commented Feb 17, 2025

  • Use <sl-listbox>, <sl-option> and <sl-option-group> components instead of custom ones
  • Add clearable property for clearing the selection
  • Add aria-hidden="true" to the placeholder content
  • Add aria-placeholder to the <sl-select-button> when the placeholder is shown
  • Hide the listbox popover when focus leaves the <sl-select> component
  • Show the listbox popover immediately; only animate it when closing

Fixes #1783
Fixes #1761

Copy link

changeset-bot bot commented Feb 17, 2025

🦋 Changeset detected

Latest commit: 20e547a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 33 packages
Name Type
@sl-design-system/select Major
@sl-design-system/search-field Minor
@sl-design-system/shared Minor
@sl-design-system/angular Minor
@sl-design-system/paginator Minor
@sl-design-system/grid Minor
@sl-design-system/accordion Patch
@sl-design-system/announcer Patch
@sl-design-system/avatar Patch
@sl-design-system/button Patch
@sl-design-system/checkbox Patch
@sl-design-system/data-source Patch
@sl-design-system/dialog Patch
@sl-design-system/editor Patch
@sl-design-system/emoji Patch
@sl-design-system/form Patch
@sl-design-system/format-date Patch
@sl-design-system/inline-message Patch
@sl-design-system/menu Patch
@sl-design-system/panel Patch
@sl-design-system/popover Patch
@sl-design-system/radio-group Patch
@sl-design-system/switch Patch
@sl-design-system/tabs Patch
@sl-design-system/tag Patch
@sl-design-system/text-area Patch
@sl-design-system/text-field Patch
@sl-design-system/toggle-button Patch
@sl-design-system/toggle-group Patch
@sl-design-system/tooltip Patch
@sl-design-system/tree Patch
@sl-design-system/combobox Patch
@sl-design-system/tool-bar Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Feb 17, 2025

🕸 Website preview

You can view a preview here (commit 20e547ab9c9d0ae7496ef103e54c58a2a6abcc32).

Copy link
Contributor

github-actions bot commented Feb 18, 2025

🕸 Storybook preview

You can view a preview here (commit 20e547ab9c9d0ae7496ef103e54c58a2a6abcc32).

@jpzwarte jpzwarte marked this pull request as ready for review February 18, 2025 15:47
this.tabIndex = this.disabled ? -1 : 0;
if (changes.has('placeholder') || changes.has('selected')) {
if (this.placeholder && !this.selected) {
this.setAttribute('aria-placeholder', this.placeholder);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The placeholder is not being read by NVDA.

@@ -24,20 +33,29 @@ export class SelectButton extends ScopedElementsMixin(LitElement) {
/** @internal */
static override styles: CSSResultGroup = styles;

// eslint-disable-next-line no-unused-private-class-members
#events = new EventsController(this, { keydown: this.#onKeydown });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now I cannot open the select with space key, but opening select with space is possible in the native HTML select element, so I guess it should be possible here as well?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe it should be also possible to open it with enter?
https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/

@@ -249,9 +253,9 @@ export class Select<T = unknown> extends ObserveAttributesMixin(FormControlMixin
super.firstUpdated(changes);

requestAnimationFrame(() => {
this.button.setAttribute('aria-controls', this.listbox.id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why there is no aria-controls?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we really want to remove aria-controls, please remove it as well from the documentation, from the accessibility WAI ARIA description. :)

Various improvements:
- Add `clearable` property for clearing the selection
- Add `aria-hidden="true"` to the placeholder content
- Add `aria-placeholder` to the `<sl-select-button>` when the placeholder is shown
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please describe it in the documentation, in the accessibility tab (WAI-ARIA part) as well.

@@ -13,6 +19,9 @@ declare global {
}
}

Icon.register(faCircleXmark, fasCircleXmark);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe those icons need to be added to the core.json file instead of registering them here?

image

@@ -49,39 +51,40 @@ export default {
${slot?.() ??
html`
<sl-select
?clearable=${clearable}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clicking on the label in the form-field should focus the select component (select-button), right?
Just like it works with other form fields.
Right now it's not working.

${anchor({
element: this.button,
offset: Select.offset,
position: 'bottom-start',
viewportMargin: Select.viewportMargin,
rootMarginTop: this.rootMarginTop
rootMarginTop: this.rootMarginTop,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current version of the select, when we scroll down and the select is opened, when it's not visible, the dropdown is closing and when we scroll up and the select is visible again, the dropdown is visible again as well (when the select was not closed explicitly by the user):

https://storybook.sanomalearning.design/?path=/story/form-select--hide-when-out-of-view

In the version from this PR it's not working the same, the listbox is not being shown again, when I scroll up:

https://kind-plant-088739303-1794.westeurope.1.azurestaticapps.net/?path=/story/form-select--hide-when-out-of-view

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