Skip to content

Commit 5834e46

Browse files
oestrogenMattias Kesti
andauthored
feat(module:table): add nzLabel to include aria-label in checkboxes (#7903)
Co-authored-by: Mattias Kesti <mattias.kesti@calabrio.com>
1 parent 7819426 commit 5834e46

7 files changed

Lines changed: 25 additions & 1 deletion

File tree

components/table/demo/row-selection-and-operation.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ export interface Data {
3232
>
3333
<thead>
3434
<tr>
35-
<th [nzChecked]="checked" [nzIndeterminate]="indeterminate" (nzCheckedChange)="onAllChecked($event)"></th>
35+
<th
36+
[nzChecked]="checked"
37+
[nzIndeterminate]="indeterminate"
38+
nzLabel="Select all"
39+
(nzCheckedChange)="onAllChecked($event)"
40+
></th>
3641
<th>Name</th>
3742
<th>Age</th>
3843
<th>Address</th>
@@ -43,6 +48,7 @@ export interface Data {
4348
<td
4449
[nzChecked]="setOfCheckedId.has(data.id)"
4550
[nzDisabled]="data.disabled"
51+
[nzLabel]="data.name"
4652
(nzCheckedChange)="onItemChecked(data.id, $event)"
4753
></td>
4854
<td>{{ data.name }}</td>

components/table/doc/index.en-US.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ Checkbox property
111111
| `[nzShowCheckbox]` | Whether `nz-checkbox` should be shown in the header | `boolean` | - |
112112
| `[nzDisabled]` | Whether the `nz-checkbox` is disabled | `boolean` | - |
113113
| `[nzIndeterminate]` | `nz-checkbox` indeterminate status | `boolean` | - |
114+
| `[nzLabel]` | ARIA label for the `nz-checkbox` | `string` | - |
114115
| `[nzChecked]` | Checked status, double binding | `boolean` | - |
115116
| `(nzCheckedChange)` | Callback when checked status changes | `EventEmitter<boolean>` | - |
116117

@@ -173,6 +174,7 @@ Checkbox property
173174
| `[nzShowCheckbox]` | Whether add nz-checkbox | `boolean` | - |
174175
| `[nzDisabled]` | Whether disable checkbox | `boolean` | - |
175176
| `[nzIndeterminate]` | Indeterminate status | `boolean` | - |
177+
| `[nzLabel]` | ARIA label for the `nz-checkbox` | `string` | - |
176178
| `[nzChecked]` | Checked status, double binding | `boolean` | - |
177179
| `(nzCheckedChange)` | Checked status change callback | `EventEmitter<boolean>` | - |
178180
| `[colSpan]` | how many columns the cell extends | `number` | `null` |

components/table/doc/index.zh-CN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ Table 组件同时具备了易用性和高度可定制性
112112
| `[nzShowCheckbox]` | 是否添加checkbox | `boolean` | - |
113113
| `[nzDisabled]` | checkbox 是否禁用 | `boolean` | - |
114114
| `[nzIndeterminate]` | checkbox indeterminate 状态 | `boolean` | - |
115+
| `[nzLabel]` | checkbox 的可访问性标签 | `string` | - |
115116
| `[nzChecked]` | checkbox 是否被选中,可双向绑定 | `boolean` | - |
116117
| `(nzCheckedChange)` | 选中的回调 | `EventEmitter<boolean>` | - |
117118

@@ -173,6 +174,7 @@ Table 组件同时具备了易用性和高度可定制性
173174
| `[nzShowCheckbox]` | 是否添加checkbox | `boolean` | - |
174175
| `[nzDisabled]` | checkbox 是否禁用 | `boolean` | - |
175176
| `[nzIndeterminate]` | checkbox indeterminate 状态 | `boolean` | - |
177+
| `[nzLabel]` | checkbox 的可访问性标签 | `string` | - |
176178
| `[nzChecked]` | checkbox 是否被选中,可双向绑定 | `boolean` | - |
177179
| `(nzCheckedChange)` | 选中的回调 | `EventEmitter<boolean>` | - |
178180
| `[colSpan]` | 单元格可横跨的列数 | `number` | `null` |

components/table/src/addon/selection.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { NzSafeAny } from 'ng-zorro-antd/core/types';
2020
[ngModel]="checked"
2121
[nzDisabled]="disabled"
2222
[nzIndeterminate]="indeterminate"
23+
[attr.aria-label]="label"
2324
(ngModelChange)="onCheckedChange($event)"
2425
></label>
2526
<div class="ant-table-selection-extra" *ngIf="showRowSelection">
@@ -42,6 +43,7 @@ export class NzTableSelectionComponent {
4243
@Input() checked = false;
4344
@Input() disabled = false;
4445
@Input() indeterminate = false;
46+
@Input() label: string | null = null;
4547
@Input() showCheckbox = false;
4648
@Input() showRowSelection = false;
4749
@Output() readonly checkedChange = new EventEmitter<boolean>();

components/table/src/cell/td-addon.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { InputBoolean } from 'ng-zorro-antd/core/util';
4848
[nzDisabled]="nzDisabled"
4949
[ngModel]="nzChecked"
5050
[nzIndeterminate]="nzIndeterminate"
51+
[attr.aria-label]="nzLabel"
5152
(ngModelChange)="onCheckedChange($event)"
5253
></label>
5354
<ng-content></ng-content>
@@ -65,6 +66,7 @@ export class NzTdAddOnComponent implements OnChanges {
6566
@Input() nzChecked = false;
6667
@Input() nzDisabled = false;
6768
@Input() nzIndeterminate = false;
69+
@Input() nzLabel: string | null = null;
6870
@Input() nzIndentSize = 0;
6971
@Input() @InputBoolean() nzShowExpand = false;
7072
@Input() @InputBoolean() nzShowCheckbox = false;

components/table/src/cell/th-selection.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { InputBoolean } from 'ng-zorro-antd/core/util';
2929
[checked]="nzChecked"
3030
[disabled]="nzDisabled"
3131
[indeterminate]="nzIndeterminate"
32+
[label]="nzLabel"
3233
[listOfSelections]="nzSelections"
3334
[showCheckbox]="nzShowCheckbox"
3435
[showRowSelection]="nzShowRowSelection"
@@ -46,6 +47,7 @@ export class NzThSelectionComponent implements OnChanges {
4647
@Input() nzChecked = false;
4748
@Input() nzDisabled = false;
4849
@Input() nzIndeterminate = false;
50+
@Input() nzLabel: string | null = null;
4951
@Input() @InputBoolean() nzShowCheckbox = false;
5052
@Input() @InputBoolean() nzShowRowSelection = false;
5153
@Output() readonly nzCheckedChange = new EventEmitter<boolean>();

components/table/src/testing/td.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ describe('nz-td', () => {
137137
}).createComponent(NzTestDisableTdComponent);
138138
}).toThrow();
139139
});
140+
it('should add aria-label', () => {
141+
testComponent.label = 'test-label';
142+
fixture.detectChanges();
143+
console.log(td.nativeElement.querySelector('label').attributes.getNamedItem('aria-label').value);
144+
expect(td.nativeElement.querySelector('label').attributes.getNamedItem('aria-label').value).toBe('test-label'); //toContain('test-label');
145+
});
140146
});
141147
});
142148

@@ -145,6 +151,7 @@ describe('nz-td', () => {
145151
<td
146152
[(nzChecked)]="checked"
147153
[nzIndeterminate]="indeterminate"
154+
[nzLabel]="label"
148155
(nzCheckedChange)="checkedChange($event)"
149156
[nzDisabled]="disabled"
150157
[(nzExpand)]="expand"
@@ -165,6 +172,7 @@ export class NzTestTdComponent {
165172
indentSize?: number;
166173
left?: string | number;
167174
right?: string | number;
175+
label?: string | null;
168176
}
169177

170178
@Component({

0 commit comments

Comments
 (0)