Skip to content

Commit ef1e1f2

Browse files
feat(accessibility): axe accessibility recommendation changes
1 parent 59cac37 commit ef1e1f2

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

packages/kit-headless/src/components/autocomplete/autocomplete-button.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ export type ButtonProps = QwikIntrinsicElements['button'];
1111

1212
export const AutocompleteButton = component$((props: ButtonProps) => {
1313
const contextService = useContext(AutocompleteContextId);
14+
const buttonId = contextService.buttonId;
15+
const listboxId = contextService.listBoxId;
1416

1517
return (
1618
<button
1719
{...props}
20+
id={buttonId}
1821
aria-expanded={contextService.isExpanded.value}
22+
aria-label="listbox toggle button"
23+
aria-haspopup="listbox"
24+
aria-controls={listboxId}
1925
// add their own custom onClick with our onClick functionality
2026
onClick$={[
2127
$(

packages/kit-headless/src/components/autocomplete/autocomplete-context.type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface AutocompleteContext {
1010
labelRef: Signal<HTMLElement | undefined>;
1111
listBoxId: string;
1212
inputId: string;
13+
buttonId: string;
1314
activeOptionId: Signal<string | null>;
1415
inputValue: Signal<string>;
1516
focusInput$: QRL<(inputId: string) => void>;

packages/kit-headless/src/components/autocomplete/autocomplete-input.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export type InputProps = QwikIntrinsicElements['input'];
1616
export const AutocompleteInput = component$((props: InputProps) => {
1717
const ref = useSignal<HTMLElement>();
1818
const contextService = useContext(AutocompleteContextId);
19+
const listboxId = contextService.listBoxId;
20+
const labelRef = contextService.labelRef;
1921

2022
/*
2123
previously had useTask here, but noticed whenever it first renders,
@@ -67,9 +69,15 @@ export const AutocompleteInput = component$((props: InputProps) => {
6769
data-autocomplete-input-id={contextService.inputId}
6870
ref={ref}
6971
role="combobox"
72+
aria-invalid={props['aria-invalid'] || false}
7073
id={contextService.inputId}
7174
aria-autocomplete="list"
72-
aria-controls={contextService.listBoxId}
75+
aria-haspopup="listbox"
76+
aria-controls={listboxId}
77+
aria-expanded={contextService.isExpanded.value}
78+
aria-disabled={props['aria-disabled'] || false}
79+
aria-label={labelRef.value ? undefined : contextService.inputValue.value}
80+
aria-required={props['aria-required'] || false}
7381
bind:value={contextService.inputValue}
7482
onKeyDown$={[
7583
$((e: QwikKeyboardEvent) => {

packages/kit-headless/src/components/autocomplete/autocomplete-listbox.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ export type ListboxProps = {
1616
export const AutocompleteListbox = component$((props: ListboxProps) => {
1717
const ref = useSignal<HTMLElement>();
1818
const contextService = useContext(AutocompleteContextId);
19+
const listboxId = contextService.listBoxId;
1920
contextService.listBoxRef = ref;
2021

2122
return (
2223
<ul
23-
id={contextService.listBoxId}
24+
id={listboxId}
2425
ref={ref}
2526
style={`
2627
display: ${

packages/kit-headless/src/components/autocomplete/autocomplete-root.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export const AutocompleteRoot = component$(
134134
const inputValue = useSignal(defaultValue ? defaultValue : '');
135135
const listBoxId = useId();
136136
const inputId = useId();
137+
const buttonId = useId();
137138
const activeOptionId = useSignal(null);
138139
const focusInput$ = $((inputId: string) => {
139140
triggerRef.value
@@ -156,6 +157,7 @@ export const AutocompleteRoot = component$(
156157
inputValue,
157158
listBoxId,
158159
inputId,
160+
buttonId,
159161
activeOptionId,
160162
focusInput$,
161163
};

0 commit comments

Comments
 (0)