Skip to content

Commit

Permalink
feat(platform): table tree nodes are operable using left and right ar…
Browse files Browse the repository at this point in the history
…row keys (#10482)
  • Loading branch information
g-cheishvili authored Sep 7, 2023
1 parent f77ac1c commit db5e86e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
[focusable]="true"
[attr.role]="column.role"
[headers]="rowId + '__' + column.name"
[ngClass]="'fdp-table__col--' + column.name"
[ngClass]="[
'fdp-table__col--' + column.name,
column._freezed ? 'fd-table__cell--fixed' : '',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/member-ordering */
import { DOWN_ARROW, UP_ARROW } from '@angular/cdk/keycodes';
import { DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW, UP_ARROW } from '@angular/cdk/keycodes';
import {
AfterViewInit,
ChangeDetectionStrategy,
Expand All @@ -8,6 +8,7 @@ import {
ElementRef,
EventEmitter,
HostBinding,
HostListener,
Input,
NgZone,
OnChanges,
Expand Down Expand Up @@ -107,6 +108,10 @@ export class TableRowComponent<T> extends TableRowDirective implements OnInit, A
@Input()
freezeEndColumnsTo: string;

/** Whether the row is tree row. */
@Input()
isTreeRow: boolean;

/**
* Event emitted when keyboard drag performed.
*/
Expand Down Expand Up @@ -206,6 +211,18 @@ export class TableRowComponent<T> extends TableRowDirective implements OnInit, A
});
}

/** @hidden */
@HostListener('keydown.arrowLeft', ['$event'])
@HostListener('keydown.arrowRight', ['$event'])
private _onArrowKeydown($event: KeyboardEvent): void {
if ($event.target === this._elmRef.nativeElement && this.isTreeRow) {
const shouldBeOpen = KeyUtil.isKeyCode($event, this._rtl ? LEFT_ARROW : RIGHT_ARROW);
if (shouldBeOpen !== this.row.expanded) {
this._toggleGroupRow();
}
}
}

/** @hidden */
ngOnInit(): void {
super.ngOnInit();
Expand Down
5 changes: 3 additions & 2 deletions libs/platform/src/lib/table/table.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
[fdkDndItem]="row"
[applyDragItemClass]="isDraggable"
[class]="row | rowClasses : rowsClass"
[tabindex]="rowsActivable || !!row.navigatable ? 0 : -1"
[focusable]="rowsActivable || !!row.navigatable"
[tabindex]="row.isTree || rowsActivable || !!row.navigatable ? 0 : -1"
[focusable]="row.isTree || rowsActivable || !!row.navigatable"
[hoverable]="rowsActivable || _isShownSelectionColumn || !!row.navigatable"
[activable]="rowsActivable || !!row.navigatable"
[active]="rowIndex === _navigatedRowIndex"
Expand All @@ -109,6 +109,7 @@
[main]="true"
[class.fd-table__row--draggable]="isDraggable"
fdp-table-row
[isTreeRow]="row.isTree"
[rowId]="id"
[index]="rowIndex"
[row]="row"
Expand Down

0 comments on commit db5e86e

Please sign in to comment.