1
- import { booleanAttribute , computed , Directive , ElementRef , inject , input , linkedSignal } from '@angular/core' ;
2
1
import { FocusableOption , FocusOrigin } from '@angular/cdk/a11y' ;
2
+ import { booleanAttribute , computed , Directive , ElementRef , inject , input , linkedSignal } from '@angular/core' ;
3
3
import { DropdownService } from '../dropdown.service' ;
4
4
import { DropdownComponent } from '../dropdown/dropdown.component' ;
5
5
@@ -12,6 +12,7 @@ import { DropdownComponent } from '../dropdown/dropdown.component';
12
12
'[attr.tabindex]' : 'tabIndex()' ,
13
13
'[attr.aria-current]' : 'ariaCurrent()' ,
14
14
'[attr.aria-disabled]' : 'disabled || null' ,
15
+ '[role]' : 'role()' ,
15
16
'(click)' : 'onClick($event)' ,
16
17
'(keyup)' : 'onKeyUp($event)'
17
18
}
@@ -42,19 +43,28 @@ export class DropdownItemDirective implements FocusableOption {
42
43
*/
43
44
readonly disabledInput = input ( false , { transform : booleanAttribute , alias : 'disabled' } ) ;
44
45
45
- readonly disabledEffect = linkedSignal ( {
46
+ readonly #disabled = linkedSignal ( {
46
47
source : this . disabledInput ,
47
48
computation : ( value ) => value
48
49
} ) ;
49
50
50
51
set disabled ( value ) {
51
- this . disabledEffect . set ( value ) ;
52
+ this . #disabled . set ( value ) ;
52
53
}
53
54
54
55
get disabled ( ) {
55
- return this . disabledEffect ( ) ;
56
+ return this . #disabled ( ) ;
56
57
}
57
58
59
+ readonly role = input < string > ( 'list-item' ) ;
60
+
61
+ readonly tabIndexInput = input < string | number | null > ( '0' , { alias : 'tabIndex' } ) ;
62
+
63
+ readonly tabIndex = linkedSignal ( {
64
+ source : this . tabIndexInput ,
65
+ computation : ( value ) => ( this . disabled ? '-1' : value )
66
+ } ) ;
67
+
58
68
focus ( origin ?: FocusOrigin | undefined ) : void {
59
69
this . #elementRef?. nativeElement ?. focus ( ) ;
60
70
}
@@ -75,13 +85,6 @@ export class DropdownItemDirective implements FocusableOption {
75
85
} as Record < string , boolean > ;
76
86
} ) ;
77
87
78
- readonly tabIndexInput = input < string | number | null > ( null , { alias : 'tabIndex' } ) ;
79
-
80
- readonly tabIndex = linkedSignal ( {
81
- source : this . tabIndexInput ,
82
- computation : ( value ) => ( this . disabled ? '-1' : value )
83
- } ) ;
84
-
85
88
onClick ( $event : MouseEvent ) : void {
86
89
this . handleInteraction ( ) ;
87
90
}
0 commit comments