Skip to content

Commit

Permalink
feat: added support for aria-hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandrshy committed Jul 8, 2020
1 parent 84f0a23 commit b0052bb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<button class="modal__button" data-keukenhof-open="#modal">
Open modal
</button>
<div id="modal" class="modal" role="dialog">
<div id="modal" class="modal" role="dialog" aria-hidden="true">
<div class="modal__overlay" data-keukenhof-close>
</div>
<div class="modal__container">
Expand Down
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const Keukenhof = ((): KeukenhofType => {
open(event?: Event) {
const isContinue = this.beforeOpen(event);
if (!isContinue) return;
this.setAriaHidden(false);
this.$modal?.classList.add(this.openClass);
this.changeScrollBehavior(SCROLL_STATE.DISABLE);
this.addEventListeners();
Expand Down Expand Up @@ -117,6 +118,7 @@ export const Keukenhof = ((): KeukenhofType => {
close(event?: Event) {
const isContinue = this.beforeClose(event);
if (!isContinue) return;
this.setAriaHidden(true);
this.changeScrollBehavior(SCROLL_STATE.ENABLE);
this.removeEventListeners();
this.preparationClosingModal(event);
Expand Down Expand Up @@ -204,6 +206,15 @@ export const Keukenhof = ((): KeukenhofType => {
element.style.overflow = this.scrollBehavior.defaultValue;
else if (value === SCROLL_STATE.DISABLE) element.style.overflow = 'hidden';
}

/**
* Set value for aria-hidden
*
* @param {boolean} value - aria-hidden value
*/
setAriaHidden(value: boolean) {
this.$modal?.setAttribute('aria-hidden', String(value));
}
}

let modal: ModalType;
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type ConfigType = {
onClose?: (event?: Event) => void;
beforeOpen?: (event?: Event) => boolean;
beforeClose?: (event?: Event) => boolean;
setAriaHidden?: (value: boolean) => void;
};

export type ModalType = {
Expand Down

0 comments on commit b0052bb

Please sign in to comment.