fix(overlays): keep hide/show hooks

This commit is contained in:
Thomas Allmer 2020-12-01 14:12:13 +01:00
parent 0f41bf20c2
commit 2eeace23d5
4 changed files with 41 additions and 6 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/overlays': patch
---
Keep transitionShow and transitionHide as user hooks

View file

@ -302,8 +302,8 @@ describe('lion-combobox', () => {
expect(document.activeElement).to.equal(el._inputNode); expect(document.activeElement).to.equal(el._inputNode);
// step [4] // step [4]
el._inputNode.value = ''; await el.updateComplete;
el._inputNode.dispatchEvent(new KeyboardEvent('keydown', { key: 'c' })); mimicUserTyping(el, 'c');
await el.updateComplete; await el.updateComplete;
expect(el.opened).to.equal(true); expect(el.opened).to.equal(true);
}); });

View file

@ -26,6 +26,7 @@ export class DatepickerInputObject {
async closeCalendar() { async closeCalendar() {
this.overlayCloseButtonEl.click(); this.overlayCloseButtonEl.click();
await this.overlayEl.updateComplete;
} }
/** /**

View file

@ -681,7 +681,10 @@ export class OverlayController extends EventTargetShim {
await this._handlePosition({ phase: 'show' }); await this._handlePosition({ phase: 'show' });
this.__elementToFocusAfterHide = elementToFocusAfterHide; this.__elementToFocusAfterHide = elementToFocusAfterHide;
this.dispatchEvent(new Event('show')); this.dispatchEvent(new Event('show'));
await this.transitionShow({ backdropNode: this.backdropNode, contentNode: this.contentNode }); await this._transitionShow({
backdropNode: this.backdropNode,
contentNode: this.contentNode,
});
} }
/** @type {function} */ /** @type {function} */
(this._showResolve)(); (this._showResolve)();
@ -787,7 +790,11 @@ export class OverlayController extends EventTargetShim {
const event = new CustomEvent('before-hide', { cancelable: true }); const event = new CustomEvent('before-hide', { cancelable: true });
this.dispatchEvent(event); this.dispatchEvent(event);
if (!event.defaultPrevented) { if (!event.defaultPrevented) {
await this.transitionHide({ backdropNode: this.backdropNode, contentNode: this.contentNode }); await this._transitionHide({
backdropNode: this.backdropNode,
contentNode: this.contentNode,
});
this.contentWrapperNode.style.display = 'none'; this.contentWrapperNode.style.display = 'none';
this._handleFeatures({ phase: 'hide' }); this._handleFeatures({ phase: 'hide' });
this._keepBodySize({ phase: 'hide' }); this._keepBodySize({ phase: 'hide' });
@ -798,10 +805,21 @@ export class OverlayController extends EventTargetShim {
} }
/** /**
* Method to be overriden by subclassers
*
* @param {{backdropNode:HTMLElement, contentNode:HTMLElement}} hideConfig * @param {{backdropNode:HTMLElement, contentNode:HTMLElement}} hideConfig
*/ */
// eslint-disable-next-line class-methods-use-this, no-empty-function, no-unused-vars // eslint-disable-next-line class-methods-use-this, no-empty-function, no-unused-vars
async transitionHide(hideConfig) { async transitionHide(hideConfig) {}
/**
* @param {{backdropNode:HTMLElement, contentNode:HTMLElement}} hideConfig
*/
// eslint-disable-next-line class-methods-use-this, no-empty-function, no-unused-vars
async _transitionHide(hideConfig) {
// `this.transitionHide` is a hook for our users
await this.transitionHide({ backdropNode: this.backdropNode, contentNode: this.contentNode });
if (hideConfig.backdropNode) { if (hideConfig.backdropNode) {
hideConfig.backdropNode.classList.remove( hideConfig.backdropNode.classList.remove(
`${this.placementMode}-overlays__backdrop--animation-in`, `${this.placementMode}-overlays__backdrop--animation-in`,
@ -831,10 +849,21 @@ export class OverlayController extends EventTargetShim {
} }
/** /**
* To be overridden by subclassers
*
* @param {{backdropNode:HTMLElement, contentNode:HTMLElement}} showConfig * @param {{backdropNode:HTMLElement, contentNode:HTMLElement}} showConfig
*/ */
// eslint-disable-next-line class-methods-use-this, no-empty-function, no-unused-vars // eslint-disable-next-line class-methods-use-this, no-empty-function, no-unused-vars
async transitionShow(showConfig) { async transitionShow(showConfig) {}
/**
* @param {{backdropNode:HTMLElement, contentNode:HTMLElement}} showConfig
*/
// eslint-disable-next-line class-methods-use-this, no-empty-function, no-unused-vars
async _transitionShow(showConfig) {
// `this.transitionShow` is a hook for our users
await this.transitionShow({ backdropNode: this.backdropNode, contentNode: this.contentNode });
if (showConfig.backdropNode) { if (showConfig.backdropNode) {
showConfig.backdropNode.classList.add( showConfig.backdropNode.classList.add(
`${this.placementMode}-overlays__backdrop--animation-in`, `${this.placementMode}-overlays__backdrop--animation-in`,