Skip to content

Commit 1c5fdc6

Browse files
committed
fix(platform): move implementation to ts and narrow scenario to when cell is focused
1 parent 3a78bcc commit 1c5fdc6

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

libs/core/table/directives/table-cell.directive.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import {
22
AfterContentInit,
3+
booleanAttribute,
34
ContentChildren,
45
Directive,
6+
EventEmitter,
57
HostBinding,
68
HostListener,
79
Input,
8-
QueryList,
9-
booleanAttribute
10+
Output,
11+
QueryList
1012
} from '@angular/core';
1113
import { FDK_FOCUSABLE_ITEM_DIRECTIVE, FocusableItemDirective } from '@fundamental-ngx/cdk/utils';
1214
import { CheckboxComponent, FD_CHECKBOX_COMPONENT } from '@fundamental-ngx/core/checkbox';
@@ -76,6 +78,10 @@ export class TableCellDirective extends FocusableItemDirective implements AfterC
7678
@Input()
7779
key: string;
7880

81+
/** Event emitted when a cell is focused out. */
82+
@Output()
83+
readonly cellFocusedOut = new EventEmitter<void>();
84+
7985
/** @hidden */
8086
@ContentChildren(FD_CHECKBOX_COMPONENT)
8187
_checkboxes: QueryList<CheckboxComponent>;
@@ -108,6 +114,7 @@ export class TableCellDirective extends FocusableItemDirective implements AfterC
108114
if (this._parentPreviousTabIndex) {
109115
parentEl?.setAttribute('tabindex', this._parentPreviousTabIndex.toString());
110116
}
117+
this.cellFocusedOut.emit();
111118
}
112119

113120
/** @hidden */

libs/platform/table/components/table-row/table-row.component.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@
136136
"
137137
[attr.aria-expanded]="_isTreeRowFirstCell($index, row) ? row.expanded : null"
138138
[attr.data-nesting-level]="$index === 0 ? row.level + 1 : null"
139-
(cellFocused)="_tableRowService.cellFocused($event); _tableRowService.cellActivate($index, row)"
139+
(cellFocused)="_handleCellFocused($event, $index, row, column, tableTextContainer)"
140+
(cellFocusedOut)="_enableEmptyCellScreenReader = false"
140141
(click)="_tableRowService.cellClicked({ index: $index, row })"
141142
(keydown.enter)="_isTreeRowFirstCell($index, row, $event) && _toggleGroupRow()"
142143
(keydown.arrowLeft)="_tableRowService.scrollToOverlappedCell()"
@@ -163,7 +164,7 @@
163164
></span>
164165
}
165166
@if (row.state === 'readonly') {
166-
@if (tableTextContainer.innerText?.trim() === '') {
167+
@if (_enableEmptyCellScreenReader) {
167168
<span
168169
[ngStyle]="{
169170
position: 'absolute',

libs/platform/table/components/table-row/table-row.component.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import {
6363
isTreeRow,
6464
isTreeRowFirstCell
6565
} from '@fundamental-ngx/platform/table-helpers';
66+
import { get } from 'lodash-es';
6667
import { Subject, fromEvent, merge } from 'rxjs';
6768
import { filter, startWith, switchMap, takeUntil } from 'rxjs/operators';
6869
import { TableEditableCellComponent } from '../table-editable-cell/table-editable-cell.component';
@@ -180,6 +181,9 @@ export class TableRowComponent<T> extends TableRowDirective implements OnInit, A
180181
/** @hidden */
181182
_rowSelectionHelperTextId = `rowSelectionHelper-${uuidv4()}`;
182183

184+
/** @hidden */
185+
_enableEmptyCellScreenReader: boolean;
186+
183187
/** @hidden */
184188
readonly _isTreeRowFirstCell = isTreeRowFirstCell;
185189

@@ -324,6 +328,26 @@ export class TableRowComponent<T> extends TableRowDirective implements OnInit, A
324328
return retVal;
325329
};
326330

331+
/** @hidden */
332+
_handleCellFocused(
333+
event: FocusableItemPosition,
334+
index: number,
335+
row: TableRow<T>,
336+
column: TableColumn,
337+
tableContainer: HTMLElement
338+
): void {
339+
if (
340+
(row.state === 'readonly' &&
341+
!column.columnCellTemplate &&
342+
(get(row.value, column.key) === '' || !get(row.value, column.key))) ||
343+
(column.columnCellTemplate && tableContainer?.textContent?.trim() === '')
344+
) {
345+
this._enableEmptyCellScreenReader = true;
346+
}
347+
this._tableRowService.cellFocused(event);
348+
this._tableRowService.cellActivate(index, row);
349+
}
350+
327351
/** @hidden */
328352
protected _handleCellSpaceKey(colIdx: number, tableCellElement: HTMLTableCellElement, $event: Event): void {
329353
if ($event.target === tableCellElement && isTreeRowFirstCell(colIdx, this.row, $event)) {

0 commit comments

Comments
 (0)