Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: checkbox accessibility #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions playwright/e2e/row-group.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ test.describe('row grouping', () => {
{
id: 'aria-required-children',
enabled: false
},
// disable label required with forms elements
{
id: 'label',
enabled: false
}
]);

Expand All @@ -29,10 +24,6 @@ test.describe('row grouping', () => {
{
id: 'aria-required-children',
enabled: false
},
{
id: 'label',
enabled: false
}
]);
});
Expand All @@ -48,10 +39,6 @@ test.describe('row grouping', () => {
{
id: 'aria-required-children',
enabled: false
},
{
id: 'label',
enabled: false
}
]);
groupHeader.click();
Expand All @@ -60,10 +47,6 @@ test.describe('row grouping', () => {
{
id: 'aria-required-children',
enabled: false
},
{
id: 'label',
enabled: false
}
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { AsyncPipe, NgTemplateOutlet } from '@angular/common';
type="checkbox"
[disabled]="disable$ | async"
[checked]="isSelected"
[attr.aria-label]="rowCheckboxAriaLabel"
(click)="onCheckboxChange($event)"
/>
</label>
Expand Down Expand Up @@ -221,6 +222,8 @@ export class DataTableBodyCellComponent<TRow extends { level?: number } = any>

@Input() ghostLoadingIndicator = false;

@Input() rowCheckboxAriaLabel?: string;

@Output() activate: EventEmitter<ActivateEvent<TRow>> = new EventEmitter();

@Output() treeAction: EventEmitter<any> = new EventEmitter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export class DatatableGroupHeaderDirective<TRow = any> {
@Input('template')
_templateInput: TemplateRef<GroupContext<TRow>>;

/**
* aria label text for group header checkbox
* required for accessibility
*/
@Input() headerCheckboxAriaLabel = 'Select row group';

@ContentChild(DatatableGroupHeaderTemplateDirective, { read: TemplateRef, static: true })
_templateQuery: TemplateRef<GroupContext<TRow>>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { DatatableRowDetailDirective } from '../row-detail/row-detail.directive'
<input
#select
type="checkbox"
[attr.aria-label]="groupHeader.headerCheckboxAriaLabel"
[checked]="selectedGroupRows().length === group().value.length"
(change)="onCheckboxChange(select.checked)"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { DataTableBodyCellComponent } from './body-cell.component';
[disable$]="disable$"
[treeStatus]="treeStatus"
[ghostLoadingIndicator]="ghostLoadingIndicator"
[rowCheckboxAriaLabel]="rowCheckboxAriaLabel"
(activate)="onActivate($event, ii)"
(treeAction)="onTreeAction()"
>
Expand Down Expand Up @@ -97,6 +98,7 @@ export class DataTableBodyRowComponent<TRow = any> implements DoCheck, OnChanges
@Input() treeStatus?: TreeStatus = 'collapsed';
@Input() ghostLoadingIndicator = false;
@Input() verticalScrollVisible = false;
@Input() rowCheckboxAriaLabel?: string;

@Input() disable$: BehaviorSubject<boolean>;
@Input()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ import { ProgressBarComponent } from './progress-bar.component';
[ghostLoadingIndicator]="ghostLoadingIndicator"
[draggable]="rowDraggable"
[verticalScrollVisible]="verticalScrollVisible"
[rowCheckboxAriaLabel]="rowCheckboxAriaLabel"
(treeAction)="onTreeAction(group)"
(activate)="selector.onActivate($event, indexes().first + i)"
(drop)="drop($event, group, rowElement)"
Expand Down Expand Up @@ -176,6 +177,7 @@ import { ProgressBarComponent } from './progress-bar.component';
[ghostLoadingIndicator]="ghostLoadingIndicator"
[draggable]="rowDraggable"
[verticalScrollVisible]="verticalScrollVisible"
[rowCheckboxAriaLabel]="rowCheckboxAriaLabel"
(treeAction)="onTreeAction(group)"
(activate)="selector.onActivate($event, indexes().first + i)"
(drop)="drop($event, group, rowElement)"
Expand Down Expand Up @@ -210,6 +212,7 @@ import { ProgressBarComponent } from './progress-bar.component';
[ghostLoadingIndicator]="ghostLoadingIndicator"
[draggable]="rowDraggable"
[verticalScrollVisible]="verticalScrollVisible"
[rowCheckboxAriaLabel]="rowCheckboxAriaLabel"
(activate)="selector.onActivate($event, i)"
(drop)="drop($event, row, rowElement)"
(dragover)="dragOver($event, row)"
Expand Down Expand Up @@ -393,6 +396,7 @@ export class DataTableBodyComponent<TRow extends { treeStatus?: TreeStatus } = a
}

@Input() verticalScrollVisible = false;
@Input() rowCheckboxAriaLabel?: string;

@Output() scroll: EventEmitter<ScrollEvent> = new EventEmitter();
@Output() page: EventEmitter<number> = new EventEmitter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
[selectionType]="selectionType"
[verticalScrollVisible]="verticalScrollVisible"
[enableClearingSortState]="enableClearingSortState"
[headerCheckboxAriaLabel]="headerCheckboxAriaLabel"
(sort)="onColumnSort($event)"
(resize)="onColumnResize($event)"
(resizing)="onColumnResizing($event)"
Expand Down Expand Up @@ -63,6 +64,7 @@
[summaryHeight]="summaryHeight"
[summaryPosition]="summaryPosition"
[verticalScrollVisible]="verticalScrollVisible"
[rowCheckboxAriaLabel]="rowCheckboxAriaLabel"
(page)="onBodyPage($event)"
(activate)="activate.emit($event)"
(rowContextmenu)="onRowContextmenu($event)"
Expand Down
12 changes: 12 additions & 0 deletions projects/ngx-datatable/src/lib/components/datatable.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,18 @@ export class DatatableComponent<TRow = any>
*/
@Input({ transform: booleanAttribute }) enableClearingSortState = false;

/**
* aria label text for header checkbox
* required for accessibility
*/
@Input() headerCheckboxAriaLabel = 'Select all rows';

/**
* aria label text for row selection checkbox
* required for accessibility
*/
@Input() rowCheckboxAriaLabel = 'Select row';

/**
* Body was scrolled typically in a `scrollbarV:true` scenario.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ import { NgTemplateOutlet } from '@angular/common';
}
@if (isCheckboxable) {
<label class="datatable-checkbox">
<input type="checkbox" [checked]="allRowsSelected" (change)="select.emit()" />
<input
type="checkbox"
[attr.aria-label]="headerCheckboxAriaLabel"
[checked]="allRowsSelected"
(change)="select.emit()"
/>
</label>
}
@if (column.headerTemplate) {
Expand Down Expand Up @@ -74,6 +79,7 @@ export class DataTableHeaderCellComponent implements OnInit {
@Input() targetMarkerTemplate: TemplateRef<any>;
@Input() targetMarkerContext: any;
@Input() enableClearingSortState = false;
@Input() headerCheckboxAriaLabel?: string;

_allRowsSelected: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import { OrderableDirective } from '../../directives/orderable.directive';
[sortUnsetIcon]="sortUnsetIcon"
[allRowsSelected]="allRowsSelected"
[enableClearingSortState]="enableClearingSortState"
[headerCheckboxAriaLabel]="headerCheckboxAriaLabel"
(sort)="onSort($event)"
(select)="select.emit($event)"
(columnContextmenu)="columnContextmenu.emit($event)"
Expand Down Expand Up @@ -137,6 +138,7 @@ export class DataTableHeaderComponent implements OnDestroy, OnChanges {
@Input() selectionType: SelectionType;
@Input() reorderable: boolean;
@Input() verticalScrollVisible = false;
@Input() headerCheckboxAriaLabel?: string;

dragEventTarget?: MouseEvent;

Expand Down
Loading