File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed
packages/kit-headless/src/components/Autocomplete Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff 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
438441export 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 />
You can’t perform that action at this time.
0 commit comments