Skip to content

Commit f098482

Browse files
committed
Set info panel as description of the option in accessibility tree
FIX: Make sure a completion's info panel is associated with that completion in the accessibility tree. Issue codemirror/dev#1625
1 parent 27bbf99 commit f098482

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/tooltip.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ class CompletionTooltip {
159159
this.view.state.facet(completionConfig).maxRenderedOptions)
160160
this.showOptions(open.options, cState.id)
161161
}
162-
if (this.updateSelectedOption(open.selected)) {
162+
let newSel = this.updateSelectedOption(open.selected)
163+
if (newSel) {
163164
this.destroyInfo()
164165
let {completion} = open.options[open.selected]
165166
let {info} = completion
@@ -173,6 +174,7 @@ class CompletionTooltip {
173174
}).catch(e => logException(this.view.state, e, "completion info"))
174175
} else {
175176
this.addInfoPane(infoResult, completion)
177+
newSel.setAttribute("aria-describedby", this.info!.id)
176178
}
177179
}
178180
}
@@ -181,6 +183,7 @@ class CompletionTooltip {
181183
this.destroyInfo()
182184
let wrap = this.info = document.createElement("div")
183185
wrap.className = "cm-tooltip cm-completionInfo"
186+
wrap.id = "cm-completionInfo-" + Math.floor(Math.random() * 0xffff).toString(16)
184187
if ((content as Node).nodeType != null) {
185188
wrap.appendChild(content as Node)
186189
this.infoDestroy = null
@@ -205,7 +208,10 @@ class CompletionTooltip {
205208
set = opt
206209
}
207210
} else {
208-
if (opt.hasAttribute("aria-selected")) opt.removeAttribute("aria-selected")
211+
if (opt.hasAttribute("aria-selected")) {
212+
opt.removeAttribute("aria-selected")
213+
opt.removeAttribute("aria-describedby")
214+
}
209215
}
210216
}
211217
if (set) scrollIntoView(this.list, set)

0 commit comments

Comments
 (0)