Skip to content

Commit 51f159b

Browse files
Automatically set an ID on active combobox options
1 parent ce22bbc commit 51f159b

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,17 @@ export default class Combobox {
126126
el.removeAttribute('data-combobox-option-default')
127127

128128
if (target === el) {
129+
if (!target.id) {
130+
target.id = `${this.list.id}-selected`
131+
}
129132
this.input.setAttribute('aria-activedescendant', target.id)
130133
target.setAttribute('aria-selected', 'true')
131134
fireSelectEvent(target)
132135
target.scrollIntoView(this.scrollIntoViewOptions)
133136
} else {
137+
if (el.id === `${this.list.id}-selected`) {
138+
el.removeAttribute('id');
139+
}
134140
el.removeAttribute('aria-selected')
135141
}
136142
}

0 commit comments

Comments
 (0)