Skip to content

Commit d35ebef

Browse files
committed
fix(nav-link): cNavLink directive loosing tabindex attribute, refactor;
1 parent f1592f3 commit d35ebef

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

projects/coreui-angular/src/lib/nav/nav-link.directive.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { booleanAttribute, computed, Directive, effect, input } from '@angular/core';
1+
import { booleanAttribute, computed, Directive, effect, input, numberAttribute } from '@angular/core';
2+
import { BooleanInput } from '../coreui.types';
23

34
@Directive({
45
selector: '[cNavLink]',
@@ -12,6 +13,8 @@ import { booleanAttribute, computed, Directive, effect, input } from '@angular/c
1213
}
1314
})
1415
export class NavLinkDirective {
16+
static ngAcceptInputType_disabled: BooleanInput;
17+
1518
/**
1619
* Sets .nav-link class to the host. [docs]
1720
* @default true
@@ -30,20 +33,25 @@ export class NavLinkDirective {
3033
*/
3134
readonly disabled = input(false, { transform: booleanAttribute });
3235

36+
/**
37+
* The tabindex attribute specifies the tab order of an element (when the "tab" button is used for navigating).
38+
*/
39+
readonly tabindex = input(undefined, { transform: numberAttribute });
40+
3341
readonly ariaCurrent = computed(() => {
3442
return this.active() ? 'page' : null;
3543
});
3644

3745
ariaDisabled: boolean | null = null;
3846
attrDisabled: boolean | string | null = null;
39-
attrTabindex: '-1' | null = null;
47+
attrTabindex: number | null = null;
4048
styleCursor: 'pointer' | null = null;
4149

4250
readonly #disabledEffect = effect(() => {
4351
const disabled = this.disabled();
4452
this.ariaDisabled = disabled || null;
4553
this.attrDisabled = disabled ? '' : null;
46-
this.attrTabindex = disabled ? '-1' : null;
54+
this.attrTabindex = disabled ? -1 : (this.tabindex() ?? null);
4755
this.styleCursor = disabled ? null : 'pointer';
4856
});
4957

0 commit comments

Comments
 (0)