Add activedescendant to filter input

This commit is contained in:
Andy Smith
2025-08-21 15:30:59 -05:00
parent 2fe9ea44f6
commit 9139c1c56d
2 changed files with 8 additions and 4 deletions
@@ -2,7 +2,7 @@ import { Controller } from "@hotwired/stimulus"
import { nextFrame } from "helpers/timing_helpers"
export default class extends Controller {
static targets = [ "item" ]
static targets = [ "item", "input" ]
static values = {
reverseOrder: { type: Boolean, default: false },
selectionAttribute: { type: String, default: "aria-selected" },
@@ -73,13 +73,17 @@ export default class extends Controller {
async #setCurrentFrom(element) {
const selectedItem = this.#visibleItems.find(item => item.contains(element))
console.log(selectedItem)
const id = selectedItem?.getAttribute("id")
if (selectedItem) {
this.#clearSelection()
selectedItem.setAttribute(this.selectionAttributeValue, "true")
this.currentItem = selectedItem
if (this.hasInputTarget && id) {
this.inputTarget.setAttribute("aria-activedescendant", id)
}
await nextFrame()
if (this.focusOnSelectionValue) { this.currentItem.focus() }
}