-
Notifications
You must be signed in to change notification settings - Fork 21
Automatically set an ID on active combobox options #99
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -126,11 +126,17 @@ export default class Combobox { | |||||||||||||||||||||||||||||||||||||||||||||||
| el.removeAttribute('data-combobox-option-default') | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| if (target === el) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| if (!target.id) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| target.id = `${this.list.id}-selected` | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| this.input.setAttribute('aria-activedescendant', target.id) | ||||||||||||||||||||||||||||||||||||||||||||||||
| target.setAttribute('aria-selected', 'true') | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+129
to
133
|
||||||||||||||||||||||||||||||||||||||||||||||||
| fireSelectEvent(target) | ||||||||||||||||||||||||||||||||||||||||||||||||
| target.scrollIntoView(this.scrollIntoViewOptions) | ||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| if (el.id === `${this.list.id}-selected`) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| el.removeAttribute('id'); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
| el.removeAttribute('id'); | |
| el.removeAttribute('id') |
Copilot
AI
Mar 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cleanup logic removes the id from any non-target option whose id matches ${this.list.id}-selected. This can inadvertently delete a user-supplied id if their markup already uses that value. Consider marking ids that were auto-assigned (e.g., via a data-* flag or instance state) and only removing the id when it was generated by this library.
| } | |
| this.input.setAttribute('aria-activedescendant', target.id) | |
| target.setAttribute('aria-selected', 'true') | |
| fireSelectEvent(target) | |
| target.scrollIntoView(this.scrollIntoViewOptions) | |
| } else { | |
| if (el.id === `${this.list.id}-selected`) { | |
| el.removeAttribute('id'); | |
| target.setAttribute('data-combobox-generated-id', 'true') | |
| } | |
| this.input.setAttribute('aria-activedescendant', target.id) | |
| target.setAttribute('aria-selected', 'true') | |
| fireSelectEvent(target) | |
| target.scrollIntoView(this.scrollIntoViewOptions) | |
| } else { | |
| if ( | |
| el.id === `${this.list.id}-selected` && | |
| el.getAttribute('data-combobox-generated-id') === 'true' | |
| ) { | |
| el.removeAttribute('id') | |
| el.removeAttribute('data-combobox-generated-id') |
Copilot
AI
Mar 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this for loop, it's possible to remove the old ${this.list.id}-selected id (in the else branch) before reaching the new target and updating aria-activedescendant, creating a transient state where aria-activedescendant references a non-existent id. Consider setting the new aria-activedescendant / id first, then clearing the old generated id (e.g., clear-after or two-pass).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change introduces new behavior for options without ids (auto-assigning and moving
${list.id}-selected). There are existing tests foraria-activedescendantbehavior intest/test.js, but none cover the missing-id path; please add tests to validate id assignment, id movement across options, and cleanup when selection is cleared/stopped.