feat(document-picker): optional inputId prop for external label wiring (#795)

The input always carries an id (generated doc-picker-input-{uid} default,
mirroring the listbox id scheme). When a caller passes inputId it wires a
visible <label for> — the aria-label fallback is dropped then so the
visible label wins. JourneyAddBar stays untouched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-06-11 12:23:45 +02:00
parent d0fc8ce995
commit 4961c74a01
2 changed files with 24 additions and 1 deletions

View File

@@ -10,17 +10,21 @@ import {
interface Props {
alreadyAddedIds?: Set<string>;
placeholder?: string;
/** Set when a visible <label for> is wired externally — replaces the aria-label fallback. */
inputId?: string;
onSelect: (doc: DocumentOption) => void;
}
let {
alreadyAddedIds = new Set(),
placeholder = m.journey_add_document(),
inputId = undefined,
onSelect
}: Props = $props();
const uid = $props.id();
const listboxId = `doc-picker-listbox-${uid}`;
const resolvedInputId = $derived(inputId ?? `doc-picker-input-${uid}`);
const picker = createDocumentTypeahead();
@@ -82,7 +86,8 @@ function handleKeydown(e: KeyboardEvent) {
type="text"
role="combobox"
autocomplete="off"
aria-label={placeholder}
id={resolvedInputId}
aria-label={inputId ? undefined : placeholder}
aria-expanded={picker.isOpen}
aria-controls={picker.isOpen && !picker.loading && !picker.error && picker.results.length > 0
? listboxId