Skip to content

Commit 6ce5770

Browse files
committed
[ACS-10280]: removes selected state; UTs
1 parent 4391619 commit 6ce5770

File tree

5 files changed

+35
-35
lines changed

5 files changed

+35
-35
lines changed

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,34 @@ describe('DataTableRowComponent', () => {
6161
expect(fixture.debugElement.nativeElement.classList.contains('adf-is-selected')).not.toBe(true);
6262
});
6363

64-
it('should set aria selected to true when row is selected', () => {
64+
it('should not set aria selected when row is selected', () => {
6565
row.isSelected = true;
6666
component.row = row;
6767
fixture.detectChanges();
6868

69-
expect(fixture.debugElement.nativeElement.getAttribute('aria-selected')).toBe('true');
69+
expect(fixture.debugElement.nativeElement.getAttribute('aria-selected')).toBeNull();
7070
});
7171

72-
it('should set aria selected to false when row is not selected', () => {
72+
it('should not set aria selected when row is not selected', () => {
7373
row.isSelected = false;
7474
component.row = row;
7575
fixture.detectChanges();
7676

77-
expect(fixture.debugElement.nativeElement.getAttribute('aria-selected')).toBe('false');
77+
expect(fixture.debugElement.nativeElement.getAttribute('aria-selected')).toBeNull();
7878
});
7979

80-
it('should set aria selected to false when row is null', () => {
80+
it('should not set aria selected when row is null', () => {
8181
fixture.detectChanges();
82-
expect(fixture.debugElement.nativeElement.getAttribute('aria-selected')).toBe('false');
82+
expect(fixture.debugElement.nativeElement.getAttribute('aria-selected')).toBeNull();
83+
});
84+
85+
it('should keep aria label static when row is selected', () => {
86+
row.isSelected = true;
87+
row.getValue = (key: string) => (key === 'name' ? 'test row' : null);
88+
component.row = row;
89+
fixture.detectChanges();
90+
91+
expect(fixture.debugElement.nativeElement.getAttribute('aria-label')).toBe('test row');
8392
});
8493

8594
it('should set tabindex as non focusable by default (disabled propery is not passed)', () => {
@@ -141,22 +150,22 @@ describe('DataTableRowComponent', () => {
141150
expect(component.ariaLabel).toBe('document-title');
142151
});
143152

144-
it('should return empty string when row has neither name nor title', () => {
153+
it('should return null when row has neither name nor title', () => {
145154
spyOn(row, 'getValue').and.returnValue(null);
146155
component.row = row;
147156

148157
expect(component.ariaLabel).toBe('');
149158
});
150159

151-
it('should append "selected" when row is selected and has name', () => {
160+
it('should return name when row is selected and has name', () => {
152161
row.isSelected = true;
153162
spyOn(row, 'getValue').and.returnValue('document-name');
154163
component.row = row;
155164

156-
expect(component.ariaLabel).toBe('document-name selected');
165+
expect(component.ariaLabel).toBe('document-name');
157166
});
158167

159-
it('should append "selected" when row is selected and has title', () => {
168+
it('should return title when row is selected and has title', () => {
160169
row.isSelected = true;
161170
spyOn(row, 'getValue').and.callFake((key: string) => {
162171
if (key === 'name') {
@@ -169,10 +178,10 @@ describe('DataTableRowComponent', () => {
169178
});
170179
component.row = row;
171180

172-
expect(component.ariaLabel).toBe('document-title selected');
181+
expect(component.ariaLabel).toBe('document-title');
173182
});
174183

175-
it('should return empty string when row is selected but has no name or title', () => {
184+
it('should return null when row is selected but has no name or title', () => {
176185
row.isSelected = true;
177186
spyOn(row, 'getValue').and.returnValue(null);
178187
component.row = row;

lib/core/src/lib/datatable/components/datatable-row/datatable-row.component.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,13 @@ export class DataTableRowComponent implements FocusableOption {
4646
return this.row.isSelected;
4747
}
4848

49-
@HostBinding('attr.aria-selected')
50-
get isAriaSelected(): boolean {
51-
if (!this.row) {
52-
return false;
53-
}
54-
return this.row.isSelected;
55-
}
56-
5749
@HostBinding('attr.aria-label')
5850
get ariaLabel(): string | null {
5951
if (!this.row) {
6052
return null;
6153
}
6254
const label = this.row.getValue('name') || this.row.getValue('title') || '';
63-
return this.row.isSelected && label ? `${label} selected` : label;
55+
return label;
6456
}
6557

6658
@HostBinding('attr.tabindex')

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,6 @@ $data-table-cell-min-width-file-size: $data-table-cell-min-width-1 !default;
204204
}
205205
}
206206

207-
&:focus-within {
208-
.adf-datatable-hover-only {
209-
visibility: visible;
210-
}
211-
}
212-
213207
.adf-datatable-hover-only {
214208
visibility: hidden;
215209

@@ -231,12 +225,6 @@ $data-table-cell-min-width-file-size: $data-table-cell-min-width-1 !default;
231225
}
232226
}
233227

234-
@at-root .adf-datatable-list:focus-within {
235-
.adf-datatable-row .adf-datatable-hover-only {
236-
visibility: visible;
237-
}
238-
}
239-
240228
.adf-datatable-cell,
241229
.adf-datatable-cell-header {
242230
text-align: left;
@@ -546,6 +534,12 @@ $data-table-cell-min-width-file-size: $data-table-cell-min-width-1 !default;
546534
}
547535
}
548536

537+
.adf-datatable-list:focus-within {
538+
.adf-datatable-row .adf-datatable-hover-only {
539+
visibility: visible;
540+
}
541+
}
542+
549543
.adf-datatable-cell-header {
550544
@include mixins.adf-no-select;
551545

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,7 @@ describe('Accessibility', () => {
17081708
} as KeyboardEventInit);
17091709
dataRows = [{ name: 'test1' }, { name: 'test2' }];
17101710
dataTable.data = new ObjectDataTableAdapter([], [new ObjectDataColumn({ key: 'name' })]);
1711+
dataTable.enableDragRows = true;
17111712
});
17121713

17131714
it('should focus next row on ArrowDown event', () => {
@@ -1726,7 +1727,7 @@ describe('Accessibility', () => {
17261727

17271728
const rowElement = testingUtils.getAllByCSS('.adf-datatable-body .adf-datatable-row')[0];
17281729
testingUtils.setDebugElement(rowElement);
1729-
testingUtils.clickByCSS('.adf-datatable-cell');
1730+
testingUtils.clickByCSS('.adf-datatable-cell-data');
17301731

17311732
fixture.debugElement.nativeElement.dispatchEvent(event);
17321733

@@ -1743,7 +1744,7 @@ describe('Accessibility', () => {
17431744

17441745
const rowElement = testingUtils.getAllByCSS('.adf-datatable-body .adf-datatable-row')[1];
17451746
testingUtils.setDebugElement(rowElement);
1746-
testingUtils.clickByCSS('.adf-datatable-cell');
1747+
testingUtils.clickByCSS('.adf-datatable-cell-data');
17471748

17481749
fixture.debugElement.nativeElement.dispatchEvent(event);
17491750

lib/core/src/lib/i18n/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@
398398
"ACTIONS": "Actions",
399399
"SELECT_ALL": "Select all",
400400
"SELECT_FILE": "Select file",
401+
"SELECTED": "Selected",
402+
"NOT_SELECTED": "Not selected",
403+
"ROW_SELECTION": "Press Space to toggle row selection",
401404
"SORT_ASCENDING": "Ascending",
402405
"SORT_DESCENDING": "Descending",
403406
"SORT_NONE": "None",
@@ -408,6 +411,7 @@
408411
"ICON_DISABLED": "Disabled",
409412
"ROW_OPTION_BUTTON": "Actions",
410413
"DRAG": "Drag button",
414+
"DRAGGABLE": "Draggable",
411415
"EMPTY_HEADER": "Empty header",
412416
"RESIZE_COLUMN": "Resize {{ column }} column. Use arrow keys to adjust width, Shift for larger steps.",
413417
"COLUMN_WIDTH_CHANGED": "{{ column }} column width: {{ width }} pixels"

0 commit comments

Comments
 (0)