Skip to content

Conversation

@zoglo
Copy link
Contributor

@zoglo zoglo commented Nov 27, 2025

#1339 introduced the selected option being correctly highlighted when opening the dropdown but did not account for the option also being visible when opening the dropdown, leading to bad UX (unsure if selected or not).

This PR thus introduces the following bug fixes and some other behavior changes to improve UX and make the select act more native:

  1. When opening the select dropdown, we now have a native scroll to the first selected option.

    • I am using the native scrollToElement function here to avoid any smooth scroll or animated scroll.
  2. The selected state will always be visible; the hover (highlighted) state will be additionally visible.

    • Previously when hovering over any item, we lost focus of the checked options. This has now been changed by making use of the yet unused is-selected CSS class. It should now match the same behaviour as other libraries (e.g., SlimSelect). I also made sure to exclude the "Press to select" from the styles on already selected options, as this hint does not make sense here.
  3. When closing the dropdown, the hovered (highlighted) choices will be reset, matching the native <select> behaviour.

    • We previously left the last hovered choices highlighted, which could confuse users when reopening the dropdown not showing the selected option.

Screenshots (if appropriate)

The following video should show all behavioral changes

choices.mp4

Types of changes

  • Chore (tooling change or documentation change)
  • Refactor (non-breaking change which maintains existing functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • My code follows the code style of this project.
  • I have added new tests for the bug I fixed/the new feature I added.
  • I have modified existing tests for the bug I fixed/the new feature I added.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

/**
* Removes any highlighted choice options
*/
_removeHighlightedChoices(): void {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kind of hard to see in this diff but this is simply a refactor of code that I am now using in L543 as well (to reset the highlighted css classes)


if (activeElement !== null && !isScrolledIntoView(activeElement, this.choiceList.element)) {
// We use the native scrollIntoView function instead of choiceList.scrollToChildElement to avoid animated scroll.
activeElement.scrollIntoView();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could make use of the container scrollIntoViewOption once it has been implemented in in all major browsers. Right now it's not supported in FF and Safari.

}
.#{$choices-selector}__item--selectable {
&[data-select-text] {
&.is-highlighted[data-select-text] {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Small change but we only ever want to show the data-select-text when an option has not been selected :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated to this PR but the icons for the windows runner did change, just a chore to make all tests pass:
image

Comment on lines 3673 to 3674
// We use the native scrollIntoView function instead of choiceList.scrollToChildElement to avoid animated scroll.
activeElement.scrollIntoView();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
// We use the native scrollIntoView function instead of choiceList.scrollToChildElement to avoid animated scroll.
activeElement.scrollIntoView();
this.choiceList.scrollToChildElement(activeElement, 1);

We could also go native here, this one however adds a scroll animation and some unnecessary request animation frames 🤔 /cc @Xon

@zoglo
Copy link
Contributor Author

zoglo commented Nov 27, 2025

I removed the built assets in 77de928 and 6cc1b1a to reduce merge conflicts

@Xon
Copy link
Collaborator

Xon commented Nov 29, 2025

I plan to look at this in the following week, once this is in I think I'll cut a v11.2.0 release

@Xon Xon self-requested a review November 29, 2025 15:28
@Xon Xon added the feature Pull request that adds new functionality label Nov 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Pull request that adds new functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants