From a7e9e58293fa2bd95899baa6c26aeb8a9d021aaf Mon Sep 17 00:00:00 2001 From: Liam Tarpey Date: Wed, 21 Oct 2020 13:00:23 +0100 Subject: [PATCH 1/2] Allow adding multiple space-separated classes for `openClass` --- lib/src/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/src/index.js b/lib/src/index.js index 83fdfff..aa29e93 100644 --- a/lib/src/index.js +++ b/lib/src/index.js @@ -56,9 +56,10 @@ const MicroModal = (() => { } showModal (event = null) { + const openClass = this.config.openClass.split(' ') this.activeElement = document.activeElement this.modal.setAttribute('aria-hidden', 'false') - this.modal.classList.add(this.config.openClass) + this.modal.classList.add(...openClass) this.scrollBehaviour('disable') this.addEventListeners() @@ -85,14 +86,14 @@ const MicroModal = (() => { } this.config.onClose(this.modal, this.activeElement, event) + let openClass = this.config.openClass.split(' ') // <- old school ftw if (this.config.awaitCloseAnimation) { - let openClass = this.config.openClass // <- old school ftw this.modal.addEventListener('animationend', function handler () { - modal.classList.remove(openClass) + modal.classList.remove(...openClass) modal.removeEventListener('animationend', handler, false) }, false) } else { - modal.classList.remove(this.config.openClass) + modal.classList.remove(...openClass) } } From d1dc76917d0feea0e7c3c88a46fc2feb8b0cb97a Mon Sep 17 00:00:00 2001 From: Liam Tarpey Date: Wed, 21 Oct 2020 13:26:49 +0100 Subject: [PATCH 2/2] Trim end of string as breaks if extra space --- lib/src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/index.js b/lib/src/index.js index aa29e93..7bebb3c 100644 --- a/lib/src/index.js +++ b/lib/src/index.js @@ -56,7 +56,7 @@ const MicroModal = (() => { } showModal (event = null) { - const openClass = this.config.openClass.split(' ') + const openClass = this.config.openClass.trim().split(' ') this.activeElement = document.activeElement this.modal.setAttribute('aria-hidden', 'false') this.modal.classList.add(...openClass) @@ -86,7 +86,7 @@ const MicroModal = (() => { } this.config.onClose(this.modal, this.activeElement, event) - let openClass = this.config.openClass.split(' ') // <- old school ftw + let openClass = this.config.openClass.trim().split(' ') // <- old school ftw if (this.config.awaitCloseAnimation) { this.modal.addEventListener('animationend', function handler () { modal.classList.remove(...openClass)