diff --git a/.changeset/forty-taxis-lay.md b/.changeset/forty-taxis-lay.md new file mode 100644 index 000000000..878ac845c --- /dev/null +++ b/.changeset/forty-taxis-lay.md @@ -0,0 +1,5 @@ +--- +'@lion/overlays': patch +--- + +fix: only close an overlay if both mousedown and mousep events are outside (for hidesOnOutsideClick) diff --git a/docs/docs/systems/overlays/configuration.md b/docs/docs/systems/overlays/configuration.md index 9061a191d..db3db7776 100644 --- a/docs/docs/systems/overlays/configuration.md +++ b/docs/docs/systems/overlays/configuration.md @@ -167,7 +167,8 @@ export const hidesOnOutsideClick = () => {
- Hello! You can close this notification here: + + ')); const contentNode = /** @type {HTMLElement} */ (await fixture('
Content
')); @@ -548,22 +596,14 @@ describe('OverlayController', () => { contentNode, invokerNode, }); + const stopProp = (/** @type {Event} */ e) => e.stopPropagation(); const dom = await fixture( - /** - * @param {{ stopPropagation: () => any; }} e - */ `
-
- +
This element prevents our handlers from reaching the document click handler. - +
`, ); @@ -571,8 +611,9 @@ describe('OverlayController', () => { await ctrl.show(); expect(ctrl.isShown).to.equal(true); - /** @type {HTMLElement} */ - (dom.querySelector('third-party-noise')).click(); + const noiseEl = /** @type {HTMLElement} */ (dom.querySelector('#third-party-noise')); + + mimicClick(noiseEl); await aTimeout(0); expect(ctrl.isShown).to.equal(false); @@ -592,35 +633,26 @@ describe('OverlayController', () => { contentNode, invokerNode, }); + const stopProp = (/** @type {Event} */ e) => e.stopPropagation(); const dom = /** @type {HTMLElement} */ (await fixture(`
-
- +
This element prevents our handlers from reaching the document click handler. - +
`)); - /** @type {HTMLElement} */ - (dom.querySelector('third-party-noise')).addEventListener( - 'click', - (/** @type {Event} */ event) => { - event.stopPropagation(); - }, - true, - ); + const noiseEl = /** @type {HTMLElement} */ (dom.querySelector('#third-party-noise')); + + noiseEl.addEventListener('click', stopProp, true); + noiseEl.addEventListener('mousedown', stopProp, true); + noiseEl.addEventListener('mouseup', stopProp, true); await ctrl.show(); expect(ctrl.isShown).to.equal(true); - /** @type {HTMLElement} */ - (dom.querySelector('third-party-noise')).click(); + mimicClick(noiseEl); await aTimeout(0); expect(ctrl.isShown).to.equal(false); diff --git a/packages/select-rich/test/lion-select-rich.test.js b/packages/select-rich/test/lion-select-rich.test.js index 000e236f5..33c2c3fb0 100644 --- a/packages/select-rich/test/lion-select-rich.test.js +++ b/packages/select-rich/test/lion-select-rich.test.js @@ -2,6 +2,7 @@ import { LitElement } from '@lion/core'; import { renderLitAsNode } from '@lion/helpers'; import { OverlayController } from '@lion/overlays'; import { LionOption } from '@lion/listbox'; +import { mimicClick } from '@lion/overlays/test-helpers'; import { aTimeout, defineCE, @@ -253,9 +254,8 @@ describe('lion-select-rich', () => { )); expect(el.opened).to.be.true; - // a click on the button will trigger hide on outside click - // which we then need to sync back to "opened" - outerEl.click(); + + mimicClick(outerEl); await aTimeout(0); expect(el.opened).to.be.false; });