Skip to content

Commit f9c01b3

Browse files
feat(disabled options for autocomplete): disabled options for autocomplete
1 parent 316b4d4 commit f9c01b3

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,10 @@ export const AutocompleteListbox = component$((props: ListboxProps) => {
433433
);
434434
});
435435

436-
export type OptionProps = { optionValue: string } & QwikIntrinsicElements['li'];
436+
export type OptionProps = {
437+
optionValue: string;
438+
disabled?: boolean;
439+
} & QwikIntrinsicElements['li'];
437440

438441
export const AutocompleteOption = component$((props: OptionProps) => {
439442
const ref = useSignal<HTMLElement>();
@@ -445,16 +448,20 @@ export const AutocompleteOption = component$((props: OptionProps) => {
445448
<li
446449
ref={ref}
447450
role="option"
451+
tabIndex={props.disabled ? -1 : 0}
452+
aria-disabled={props.disabled}
448453
onClick$={[
449454
$(() => {
450-
contextService.inputValue.value = props.optionValue;
451-
contextService.isExpanded.value = false;
455+
if (!props.disabled) {
456+
contextService.inputValue.value = props.optionValue;
457+
contextService.isExpanded.value = false;
458+
}
452459
}),
453460
props.onClick$,
454461
]}
455462
onKeyDown$={[
456463
$((e: QwikKeyboardEvent) => {
457-
if (e.key === 'Enter' || e.key === ' ') {
464+
if ((e.key === 'Enter' || e.key === ' ') && !props.disabled) {
458465
contextService.inputValue.value = props.optionValue;
459466
contextService.isExpanded.value = false;
460467
const inputElement = contextService.triggerRef.value
@@ -464,7 +471,6 @@ export const AutocompleteOption = component$((props: OptionProps) => {
464471
}),
465472
props.onKeyDown$,
466473
]}
467-
tabIndex={0}
468474
{...props}
469475
>
470476
<Slot />

0 commit comments

Comments
 (0)