Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JSUI-2821 Fixed Youtube modal's accessibility (#1366)
Created the `AccessibleModal` component and adapted `Quickview` and `YoutubeThumbnail` to use it. https://coveord.atlassian.net/browse/JSUI-2821
- Loading branch information
1 parent
de86bff
commit 9a5daa1
Showing
8 changed files
with
293 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { ModalBox as ModalBoxModule } from '../ExternalModulesShim'; | ||
import { FocusTrap } from '../ui/FocusTrap/FocusTrap'; | ||
import { l } from '../strings/Strings'; | ||
import { $$ } from './Dom'; | ||
import { KeyboardUtils, KEYBOARD } from './KeyboardUtils'; | ||
|
||
export interface IAccessibleModalOptions { | ||
overlayClose?: boolean; | ||
sizeMod: 'small' | 'normal' | 'big'; | ||
} | ||
|
||
export class AccessibleModal { | ||
private focusTrap: FocusTrap; | ||
private activeModal: Coveo.ModalBox.ModalBox; | ||
private options: IAccessibleModalOptions; | ||
|
||
public get isOpen() { | ||
return !!this.focusTrap; | ||
} | ||
|
||
public get element() { | ||
return this.activeModal && this.activeModal.modalBox; | ||
} | ||
|
||
public get content() { | ||
return this.activeModal && this.activeModal.content; | ||
} | ||
|
||
public get wrapper() { | ||
return this.activeModal && this.activeModal.wrapper; | ||
} | ||
|
||
constructor( | ||
private className: string, | ||
private ownerBody: HTMLBodyElement, | ||
private modalboxModule: Coveo.ModalBox.ModalBox = ModalBoxModule, | ||
options: Partial<IAccessibleModalOptions> = {} | ||
) { | ||
this.options = { | ||
...{ | ||
sizeMod: 'big' | ||
}, | ||
...options | ||
}; | ||
} | ||
|
||
public open(title: HTMLElement, content: HTMLElement, validation: () => boolean) { | ||
if (this.isOpen) { | ||
return; | ||
} | ||
this.activeModal = this.modalboxModule.open(content, { | ||
title, | ||
className: this.className, | ||
validation: () => { | ||
this.onModalClose(); | ||
return validation(); | ||
}, | ||
body: this.ownerBody, | ||
sizeMod: this.options.sizeMod, | ||
overlayClose: this.options.overlayClose | ||
}); | ||
this.focusTrap = new FocusTrap(this.element); | ||
this.makeAccessible(); | ||
} | ||
|
||
public close() { | ||
if (!this.isOpen) { | ||
return; | ||
} | ||
this.activeModal.close(); | ||
this.activeModal = null; | ||
} | ||
|
||
private makeAccessible() { | ||
this.element.setAttribute('aria-modal', 'true'); | ||
this.makeCloseButtonAccessible(); | ||
} | ||
|
||
private makeCloseButtonAccessible() { | ||
const closeButton: HTMLElement = this.element.querySelector('.coveo-small-close'); | ||
closeButton.setAttribute('aria-label', l('Close')); | ||
closeButton.tabIndex = 0; | ||
closeButton.focus(); | ||
$$(closeButton).on('keyup', KeyboardUtils.keypressAction(KEYBOARD.ENTER, () => closeButton.click())); | ||
} | ||
|
||
private onModalClose() { | ||
this.focusTrap.disable(); | ||
this.focusTrap = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.