Skip to content

Commit 6ab54be

Browse files
authored
[ACS-10324]: checkbox enter key handling (#11271)
* [ACS-10324]: prevents bubbling of enter key * [ACS-10324]: adds test * [ACS-10324]: migrates to testUtils instead of direct query use
1 parent 2d68cf9 commit 6ab54be

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/core/src/lib/datatable/components/datatable/datatable.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@
253253
[aria-label]="'ADF-DATATABLE.ACCESSIBILITY.SELECT_FILE' | translate"
254254
data-adf-datatable-row-checkbox
255255
(change)="onCheckboxChange(row, $event)"
256-
class="adf-checkbox-sr-only">
256+
(keydown.enter)="$event.stopPropagation()"
257+
class="adf-checkbox-sr-only"
258+
>
257259
{{ 'ADF-DATATABLE.ACCESSIBILITY.SELECT_FILE' | translate }}
258260
</mat-checkbox>
259261
</label>

lib/core/src/lib/datatable/components/datatable/datatable.component.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,33 @@ describe('DataTable', () => {
13951395
expect(rows[1].isSelected).toBeTrue();
13961396
});
13971397

1398+
it('should call stopPropagation on checkbox keydown enter event', () => {
1399+
const petRows = [{ pet: 'dog' }, { pet: 'cat' }];
1400+
dataTable.multiselect = true;
1401+
dataTable.data = new ObjectDataTableAdapter(petRows, [new ObjectDataColumn({ key: 'pet' })]);
1402+
dataTable.ngOnChanges({ rows: new SimpleChange(null, petRows, false) });
1403+
fixture.detectChanges();
1404+
1405+
const checkboxElement = testingUtils.getByCSS('[data-adf-datatable-row-checkbox]').nativeElement as HTMLElement;
1406+
1407+
const enterEvent = new KeyboardEvent('keydown', {
1408+
key: 'Enter',
1409+
code: 'Enter',
1410+
bubbles: true,
1411+
cancelable: true
1412+
});
1413+
1414+
const stopPropagationSpy = jasmine.createSpy('stopPropagationSpy');
1415+
1416+
Object.assign(enterEvent, {
1417+
stopPropagation: stopPropagationSpy
1418+
});
1419+
1420+
checkboxElement.dispatchEvent(enterEvent);
1421+
1422+
expect(stopPropagationSpy).toHaveBeenCalled();
1423+
});
1424+
13981425
it('should be able to display column of type boolean', () => {
13991426
dataTable.data = new ObjectDataTableAdapter(mockCarsData, mockCarsSchemaDefinition);
14001427

0 commit comments

Comments
 (0)