Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACA-4692] fixed focus for create and upload modals #3146

Merged
merged 2 commits into from
Apr 25, 2023
Merged
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
Expand Up @@ -85,7 +85,7 @@ interface RestoredNode {
providedIn: 'root'
})
export class ContentManagementService {
private readonly createMenuButtonSelector = 'app-create-menu button';
private readonly createMenuButtonSelector = 'app-toolbar-menu button[id="app.toolbar.create"]';
AleksanderSklorz marked this conversation as resolved.
Show resolved Hide resolved

constructor(
private nodesApiService: NodesApiService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,6 @@ export class NodeTemplateService {
}

private static focusCreateMenuButton(): void {
document.querySelector<HTMLElement>('app-create-menu button').focus();
document.querySelector<HTMLElement>('app-toolbar-menu button[id="app.toolbar.create"]').focus();
}
}
64 changes: 32 additions & 32 deletions projects/aca-content/src/lib/store/effects/upload.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,76 +59,76 @@ describe('UploadEffects', () => {
});

describe('uploadFiles$', () => {
let createMenuButton: HTMLButtonElement;
let uploadMenuButton: HTMLButtonElement;
const focusedClass = 'cdk-program-focused';

beforeEach(() => {
createMenuButton = document.createElement('button');
document.body.appendChild(createMenuButton);
uploadMenuButton = document.createElement('button');
document.body.appendChild(uploadMenuButton);
store.dispatch(new UploadFilesAction({}));
spyOn(document, 'querySelector').withArgs('app-create-menu button').and.returnValue(createMenuButton);
spyOn(document, 'querySelector').withArgs('app-toolbar-menu button[id="app.toolbar.upload"]').and.returnValue(uploadMenuButton);
});

it('should call focus function on create menu button', () => {
spyOn(createMenuButton, 'focus');
it('should call focus function on upload menu button', () => {
spyOn(uploadMenuButton, 'focus');
window.dispatchEvent(new FocusEvent('focus'));
expect(createMenuButton.focus).toHaveBeenCalledWith();
expect(uploadMenuButton.focus).toHaveBeenCalledWith();
});

it('should not call focus function on create menu button if handler for focus of window is not fired', () => {
spyOn(createMenuButton, 'focus');
expect(createMenuButton.focus).not.toHaveBeenCalled();
it('should not call focus function on upload menu button if handler for focus of window is not fired', () => {
spyOn(uploadMenuButton, 'focus');
expect(uploadMenuButton.focus).not.toHaveBeenCalled();
});

it('should add cdk-program-focused class to create menu button', () => {
it('should add cdk-program-focused class to upload menu button', () => {
window.dispatchEvent(new FocusEvent('focus'));
createMenuButton.dispatchEvent(new FocusEvent('focus'));
expect(createMenuButton).toHaveClass(focusedClass);
uploadMenuButton.dispatchEvent(new FocusEvent('focus'));
expect(uploadMenuButton).toHaveClass(focusedClass);
});

it('should not add cdk-program-focused class to create menu button if handler for focus of window is not fired', () => {
expect(createMenuButton).not.toHaveClass(focusedClass);
it('should not add cdk-program-focused class to upload menu button if handler for focus of window is not fired', () => {
expect(uploadMenuButton).not.toHaveClass(focusedClass);
});

afterEach(() => {
createMenuButton.remove();
uploadMenuButton.remove();
});
});

describe('uploadFolder$', () => {
let createMenuButton: HTMLButtonElement;
let uploadMenuButton: HTMLButtonElement;
const focusedClass = 'cdk-program-focused';

beforeEach(() => {
createMenuButton = document.createElement('button');
document.body.appendChild(createMenuButton);
uploadMenuButton = document.createElement('button');
document.body.appendChild(uploadMenuButton);
store.dispatch(new UploadFolderAction({}));
spyOn(document, 'querySelector').withArgs('app-create-menu button').and.returnValue(createMenuButton);
spyOn(document, 'querySelector').withArgs('app-toolbar-menu button[id="app.toolbar.upload"]').and.returnValue(uploadMenuButton);
});

it('should call focus function on create menu button', () => {
spyOn(createMenuButton, 'focus');
it('should call focus function on upload menu button', () => {
spyOn(uploadMenuButton, 'focus');
window.dispatchEvent(new FocusEvent('focus'));
expect(createMenuButton.focus).toHaveBeenCalledWith();
expect(uploadMenuButton.focus).toHaveBeenCalledWith();
});

it('should not call focus function on create menu button if handler for focus of window is not fired', () => {
spyOn(createMenuButton, 'focus');
expect(createMenuButton.focus).not.toHaveBeenCalled();
it('should not call focus function on upload menu button if handler for focus of window is not fired', () => {
spyOn(uploadMenuButton, 'focus');
expect(uploadMenuButton.focus).not.toHaveBeenCalled();
});

it('should add cdk-program-focused class to create menu button', () => {
it('should add cdk-program-focused class to upload menu button', () => {
window.dispatchEvent(new FocusEvent('focus'));
createMenuButton.dispatchEvent(new FocusEvent('focus'));
expect(createMenuButton).toHaveClass(focusedClass);
uploadMenuButton.dispatchEvent(new FocusEvent('focus'));
expect(uploadMenuButton).toHaveClass(focusedClass);
});

it('should not add cdk-program-focused class to create menu button if handler for focus of window is not fired', () => {
expect(createMenuButton).not.toHaveClass(focusedClass);
it('should not add cdk-program-focused class to upload menu button if handler for focus of window is not fired', () => {
expect(uploadMenuButton).not.toHaveClass(focusedClass);
});

afterEach(() => {
createMenuButton.remove();
uploadMenuButton.remove();
});
});

Expand Down
6 changes: 3 additions & 3 deletions projects/aca-content/src/lib/store/effects/upload.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class UploadEffects {
private fileInput: HTMLInputElement;
private folderInput: HTMLInputElement;
private fileVersionInput: HTMLInputElement;
private readonly createMenuButtonSelector = 'app-create-menu button';
private readonly uploadMenuButtonSelector = 'app-toolbar-menu button[id="app.toolbar.upload"]';

constructor(
private store: Store<AppStore>,
Expand Down Expand Up @@ -91,7 +91,7 @@ export class UploadEffects {
this.actions$.pipe(
ofType<UploadFilesAction>(UploadActionTypes.UploadFiles),
map(() => {
this.registerFocusingElementAfterModalClose(this.fileInput, this.createMenuButtonSelector);
this.registerFocusingElementAfterModalClose(this.fileInput, this.uploadMenuButtonSelector);
this.fileInput.click();
})
),
Expand All @@ -103,7 +103,7 @@ export class UploadEffects {
this.actions$.pipe(
ofType<UploadFolderAction>(UploadActionTypes.UploadFolder),
map(() => {
this.registerFocusingElementAfterModalClose(this.folderInput, this.createMenuButtonSelector);
this.registerFocusingElementAfterModalClose(this.folderInput, this.uploadMenuButtonSelector);
this.folderInput.click();
})
),
Expand Down