Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@if ((dataSource.loading$ | async) && !loadingNode) {
<ds-loading class="ds-themed-loading"></ds-loading>
}
<cdk-tree [dataSource]="dataSource" [treeControl]="treeControl" [trackBy]="trackBy">
<cdk-tree [dataSource]="dataSource" [treeControl]="treeControl" [trackBy]="trackBy" [expansionKey]="expansionKey">
<!-- This is the tree node template for show more node -->
<cdk-tree-node *cdkTreeNodeDef="let node; when: isShowMore" cdkTreeNodePadding
class="example-tree-node show-more-node">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,4 +611,46 @@ describe('CommunityListComponent', () => {
});
});
});

describe('aria-level, aria-posinset and aria-setsize after the tree reloads', () => {
const rowFor = (name: string): HTMLElement => fixture.debugElement.queryAll(By.css('cdk-tree-node'))
.find((node: DebugElement) => node.query(By.css('a.lead'))?.nativeElement.textContent.trim() === name)
.nativeElement;

const aria = (name: string): string[] => ['aria-level', 'aria-posinset', 'aria-setsize']
.map((attribute: string) => rowFor(name).getAttribute(attribute));

const click = (button: HTMLElement): void => {
button.click();
tick();
fixture.detectChanges();
};

const toggle = (name: string): HTMLElement => rowFor(name).querySelector('button[data-test="expand-button"]');

it('stay right on rows that were on screen before another community expanded', fakeAsync(() => {
click(toggle('community1'));
expect(aria('subcommunity1')).toEqual(['2', '1', '2']);

click(toggle('community2'));

expect(aria('community1')).toEqual(['1', '1', '3']);
expect(aria('subcommunity1')).toEqual(['2', '1', '2']);
expect(aria('subcommunity2')).toEqual(['2', '2', '2']);
expect(aria('community2')).toEqual(['1', '2', '3']);
expect(aria('collection1')).toEqual(['2', '1', '3']);
}));

it('stay right on collections that were on screen before Show more', fakeAsync(() => {
click(toggle('community2'));
expect(aria('collection1')).toEqual(['2', '1', '3']);

click(fixture.debugElement.query(By.css('.show-more-node [data-test="show-more-button"]')).nativeElement);

expect(aria('collection1')).toEqual(['2', '1', '4']);
expect(aria('collection2')).toEqual(['2', '2', '4']);
expect(aria('collection3')).toEqual(['2', '3', '4']);
expect(aria('collection4')).toEqual(['2', '4', '4']);
}));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export class CommunityListComponent implements OnInit, OnDestroy {
dataSource: CommunityListDatasource;
paginationConfig: FindListOptions;
trackBy = (index, node: FlatNode) => node.id;
// Every reload builds new node objects while kept rows hold their first one, so the tree
// must look up levels and positions by id too, or kept rows report aria-level 1.
expansionKey = (node: FlatNode) => node.id;

constructor(
protected communityListService: CommunityListService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</span>
<span class="ps-1">
@if (couldPreview()) {
<a class="preview-btn" role="button" tabindex="0"
<a #previewButton class="preview-btn" role="button" tabindex="0"
(click)="togglePreview()"
(keyup.enter)="togglePreview()"
(keydown.space)="$event.preventDefault()"
Expand All @@ -73,10 +73,10 @@
<i class="fa fa-eye">&nbsp;</i>
{{'item.file.description.file.preview' | translate}}
<a class="pull-right cursor-pointer" role="button" tabindex="0"
(click)="togglePreview()"
(keyup.enter)="togglePreview()"
(click)="closePreview()"
(keyup.enter)="closePreview()"
(keydown.space)="$event.preventDefault()"
(keyup.space)="togglePreview()"
(keyup.space)="closePreview()"
[attr.aria-expanded]="!previewCollapsed"
attr.aria-controls="file_file_{{ fileInput.id }}"
[attr.aria-label]="'item.file.description.preview.close' | translate">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,23 @@ describe('FileDescriptionComponent', () => {
expect(previewButton().getAttribute('aria-expanded')).toEqual('false');
});

it('moves focus back to Preview when the close control closes the panel', () => {
['Enter', ' '].forEach((key: string) => {
previewButton().click();
fixture.detectChanges();
closeButton().focus();
expect(document.activeElement).withContext('the close control cannot take focus').toBe(closeButton());

closeButton().dispatchEvent(new KeyboardEvent('keyup', { key, bubbles: true }));
fixture.detectChanges();

expect(isVisible(panel())).toBeFalse();
expect(document.activeElement)
.withContext(`after closing with "${key}" focus is on ${document.activeElement?.tagName}, not on Preview`)
.toBe(previewButton());
});
});

it('does not scroll the page when Space is pressed on Preview', () => {
expect(dispatchSpaceKey(previewButton(), 'keydown').defaultPrevented).toBeTrue();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export class FileDescriptionComponent implements OnInit, OnDestroy, AfterViewIni

@ViewChild('videoPreview') videoElement: ElementRef;

@ViewChild('previewButton') previewButton: ElementRef<HTMLElement>;

previewCollapsed = true;

emailToContact: string;
Expand Down Expand Up @@ -287,6 +289,15 @@ export class FileDescriptionComponent implements OnInit, OnDestroy, AfterViewIni
this.previewCollapsed = !this.previewCollapsed;
}

/**
* Closes the preview from the control inside the panel. That control is hidden with the panel,
* so focus goes back to the Preview control instead of falling to the page body.
*/
public closePreview() {
this.previewCollapsed = true;
this.previewButton?.nativeElement.focus();
}

public isTxt() {
return this.fileInput?.format === 'text/plain';
}
Expand Down
Loading