Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +129 to 132
Copy link

Copilot AI Mar 29, 2026

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 for aria-activedescendant behavior in test/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.

Copilot uses AI. Check for mistakes.
target.setAttribute('aria-selected', 'true')
Comment on lines +129 to 133
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

When selection is cleared via clearSelection() / stop() / destroy(), the auto-assigned ${this.list.id}-selected id is not removed from the last selected option, leaving a stale "selected" id in the DOM. To keep the ARIA example pattern consistent (id only on the active option) and avoid confusing consumers that query for that id, consider removing the generated id as part of clearSelection() (and only if it was generated by this library).

Copilot uses AI. Check for mistakes.
fireSelectEvent(target)
target.scrollIntoView(this.scrollIntoViewOptions)
} else {
if (el.id === `${this.list.id}-selected`) {
el.removeAttribute('id');
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

el.removeAttribute('id'); introduces a stray semicolon; the rest of this file uses a no-semicolons style. Please drop the semicolon for consistency.

Suggested change
el.removeAttribute('id');
el.removeAttribute('id')

Copilot uses AI. Check for mistakes.
Comment on lines +131 to +138
Copy link

Copilot AI Mar 29, 2026

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.

Suggested change
}
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 uses AI. Check for mistakes.
}
el.removeAttribute('aria-selected')
Comment on lines 136 to 140
Copy link

Copilot AI Mar 29, 2026

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).

Copilot uses AI. Check for mistakes.
}
}
Expand Down
Loading