diff --git a/app/javascript/controllers/navigable_list_controller.js b/app/javascript/controllers/navigable_list_controller.js index 78a7e2176..e7af08134 100644 --- a/app/javascript/controllers/navigable_list_controller.js +++ b/app/javascript/controllers/navigable_list_controller.js @@ -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() } } diff --git a/app/views/cards/index/_header.html.erb b/app/views/cards/index/_header.html.erb index dfb1224cd..61fdc3bcd 100644 --- a/app/views/cards/index/_header.html.erb +++ b/app/views/cards/index/_header.html.erb @@ -30,7 +30,7 @@ navigable_list_actionable_items_value: true } do %>