Skip to content

Commit d9a2d27

Browse files
authored
fix(module:tabs): aria controls have wrong value (#8237)
1 parent e4d6082 commit d9a2d27

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

components/tabs/style/patch.less

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
position: relative;
55
}
66

7+
.ant-tabs-tab-btn {
8+
border: none;
9+
background-color: unset;
10+
}
11+
712
.ant-tabs-tab a[nz-tab-link] {
813
&::before {
914
position: absolute;
@@ -88,10 +93,12 @@ nz-tabs-nav {
8893
}
8994
}
9095
}
96+
9197
&-tab-disabled a {
9298
pointer-events: none;
9399
color: @disabled-color;
94100
}
101+
95102
> .@{tab-prefix-cls}-nav,
96103
> div > .@{tab-prefix-cls}-nav {
97104
.@{tab-prefix-cls}-nav-add {

components/tabs/tab-nav-bar.component.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { FocusKeyManager } from '@angular/cdk/a11y';
77
import { Direction, Directionality } from '@angular/cdk/bidi';
88
import { coerceNumberProperty } from '@angular/cdk/coercion';
9-
import { DOWN_ARROW, ENTER, LEFT_ARROW, RIGHT_ARROW, SPACE, UP_ARROW, hasModifierKey } from '@angular/cdk/keycodes';
9+
import { DOWN_ARROW, ENTER, hasModifierKey, LEFT_ARROW, RIGHT_ARROW, SPACE, UP_ARROW } from '@angular/cdk/keycodes';
1010
import { ViewportRuler } from '@angular/cdk/overlay';
1111
import { NgIf, NgTemplateOutlet } from '@angular/common';
1212
import {
@@ -30,7 +30,7 @@ import {
3030
ViewChild,
3131
ViewEncapsulation
3232
} from '@angular/core';
33-
import { Subject, animationFrameScheduler, asapScheduler, merge, of } from 'rxjs';
33+
import { animationFrameScheduler, asapScheduler, merge, of, Subject } from 'rxjs';
3434
import { auditTime, takeUntil } from 'rxjs/operators';
3535

3636
import { NzResizeObserver } from 'ng-zorro-antd/cdk/resize-observer';
@@ -68,9 +68,17 @@ const CSS_TRANSFORM_TIME = 150;
6868
nzTabScrollList
6969
(offsetChange)="onOffsetChange($event)"
7070
(tabScroll)="tabScroll.emit($event)"
71+
role="tablist"
7172
>
7273
<ng-content></ng-content>
73-
<button *ngIf="showAddButton" nz-tab-add-button [addIcon]="addIcon" (click)="addClicked.emit()"></button>
74+
<button
75+
role="tab"
76+
[attr.tabindex]="-1"
77+
*ngIf="showAddButton"
78+
nz-tab-add-button
79+
[addIcon]="addIcon"
80+
(click)="addClicked.emit()"
81+
></button>
7482
<div nz-tabs-ink-bar [hidden]="hideBar" [position]="position" [animated]="inkBarAnimated"></div>
7583
</div>
7684
</div>
@@ -86,7 +94,6 @@ const CSS_TRANSFORM_TIME = 150;
8694
</div>
8795
`,
8896
host: {
89-
role: 'tablist',
9097
class: 'ant-tabs-nav',
9198
'(keydown)': 'handleKeydown($event)'
9299
},

components/tabs/tabset.component.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ let nextId = 0;
9494
(contextmenu)="contextmenuNavItem(tab, $event)"
9595
*ngFor="let tab of tabs; let i = index"
9696
>
97-
<div
97+
<button
9898
role="tab"
99+
[id]="getTabContentId(i)"
99100
[attr.tabIndex]="getTabIndex(tab, i)"
100101
[attr.aria-disabled]="tab.nzDisabled"
101102
[attr.aria-selected]="nzSelectedIndex === i && !nzHideAll"
@@ -114,7 +115,7 @@ let nextId = 0;
114115
[closeIcon]="tab.nzCloseIcon"
115116
(click)="onClose(i, $event)"
116117
></button>
117-
</div>
118+
</button>
118119
</div>
119120
</nz-tabs-nav>
120121
<div class="ant-tabs-content-holder">
@@ -129,6 +130,9 @@ let nextId = 0;
129130
[style.margin-right]="getTabContentMarginRight()"
130131
>
131132
<div
133+
role="tabpanel"
134+
[id]="getTabContentId(i)"
135+
[attr.aria-labelledby]="getTabContentId(i)"
132136
nz-tab-body
133137
*ngFor="let tab of tabs; let i = index"
134138
[active]="nzSelectedIndex === i && !nzHideAll"
@@ -495,8 +499,8 @@ export class NzTabSetComponent implements OnInit, AfterContentChecked, OnDestroy
495499
});
496500
}
497501

498-
private isLinkActive(router: Router): (link?: RouterLink | RouterLink) => boolean {
499-
return (link?: RouterLink | RouterLink) =>
502+
private isLinkActive(router: Router): (link?: RouterLink) => boolean {
503+
return (link?: RouterLink) =>
500504
link
501505
? router.isActive(link.urlTree || '', {
502506
paths: this.nzLinkExact ? 'exact' : 'subset',

0 commit comments

Comments
 (0)