Add activedescendant to filter input
This commit is contained in:
@@ -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() }
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
navigable_list_actionable_items_value: true } do %>
|
||||
<div class="flex gap">
|
||||
<%= text_field_tag :search, nil, placeholder: "Filter…", class: "input input--transparent txt-small", autofocus: true,
|
||||
type: "search", autocorrect: "off", autocomplete: "off", data: { "1p-ignore": "true", filter_target: "input", action: "input->filter#filter" } %>
|
||||
type: "search", autocorrect: "off", autocomplete: "off", data: { "1p-ignore": "true", filter_target: "input", navigable_list_target: "input", action: "input->filter#filter" }, aria: { activedescendant: "filter-hotkey-1" } %>
|
||||
<button class="fizzy-dialog__close btn borderless txt-small" data-action="dialog#close">
|
||||
<%= icon_tag "close" %>
|
||||
<span class="for-screen-reader">Close menu</span>
|
||||
|
||||
Reference in New Issue
Block a user