Skip to content

Commit 552c756

Browse files
committed
refactor(dropdown-item): add default role prop, cleanup
1 parent 9ee24fa commit 552c756

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

projects/coreui-angular/src/lib/dropdown/dropdown-item/dropdown-item.directive.ts

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { booleanAttribute, computed, Directive, ElementRef, inject, input, linkedSignal } from '@angular/core';
21
import { FocusableOption, FocusOrigin } from '@angular/cdk/a11y';
2+
import { booleanAttribute, computed, Directive, ElementRef, inject, input, linkedSignal } from '@angular/core';
33
import { DropdownService } from '../dropdown.service';
44
import { DropdownComponent } from '../dropdown/dropdown.component';
55

@@ -12,6 +12,7 @@ import { DropdownComponent } from '../dropdown/dropdown.component';
1212
'[attr.tabindex]': 'tabIndex()',
1313
'[attr.aria-current]': 'ariaCurrent()',
1414
'[attr.aria-disabled]': 'disabled || null',
15+
'[role]': 'role()',
1516
'(click)': 'onClick($event)',
1617
'(keyup)': 'onKeyUp($event)'
1718
}
@@ -42,19 +43,28 @@ export class DropdownItemDirective implements FocusableOption {
4243
*/
4344
readonly disabledInput = input(false, { transform: booleanAttribute, alias: 'disabled' });
4445

45-
readonly disabledEffect = linkedSignal({
46+
readonly #disabled = linkedSignal({
4647
source: this.disabledInput,
4748
computation: (value) => value
4849
});
4950

5051
set disabled(value) {
51-
this.disabledEffect.set(value);
52+
this.#disabled.set(value);
5253
}
5354

5455
get disabled() {
55-
return this.disabledEffect();
56+
return this.#disabled();
5657
}
5758

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+
5868
focus(origin?: FocusOrigin | undefined): void {
5969
this.#elementRef?.nativeElement?.focus();
6070
}
@@ -75,13 +85,6 @@ export class DropdownItemDirective implements FocusableOption {
7585
} as Record<string, boolean>;
7686
});
7787

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-
8588
onClick($event: MouseEvent): void {
8689
this.handleInteraction();
8790
}

0 commit comments

Comments
 (0)