Hello! This is a notification.
-
@@ -234,7 +239,7 @@ storiesOf('Overlay System | Overlay as a WC', module)
Hello! You can close this notification here:
e.target.dispatchEvent(new Event('hide', { bubbles: true }))}
+ @click=${e => e.target.dispatchEvent(new Event('close-overlay', { bubbles: true }))}
>
⨯
@@ -299,7 +304,7 @@ storiesOf('Overlay System | Overlay as a WC', module)
Hello! You can close this notification here:
e.target.dispatchEvent(new Event('hide', { bubbles: true }))}
+ @click=${e => e.target.dispatchEvent(new Event('close-overlay', { bubbles: true }))}
>
⨯
@@ -355,7 +360,7 @@ storiesOf('Overlay System | Overlay as a WC', module)
Close and open it again on a small screen (< 600px) and it will be a bottom sheet
{
+ @before-opened=${e => {
if (window.innerWidth >= 600) {
e.target.config = { ...withModalDialogConfig() };
} else {
@@ -368,7 +373,7 @@ storiesOf('Overlay System | Overlay as a WC', module)
Hello! You can close this notification here:
e.target.dispatchEvent(new Event('hide', { bubbles: true }))}
+ @click=${e => e.target.dispatchEvent(new Event('close-overlay', { bubbles: true }))}
>
⨯
@@ -450,6 +455,87 @@ storiesOf('Overlay System | Overlay as a WC', module)
${popup}
`;
+ })
+ .add('Sync application state', () => {
+ const appState = {
+ opened: true,
+ };
+ const openedStateNode = renderOffline(
+ html`
+
${appState.opened}
+ `,
+ );
+ function onOpenClosed(ev) {
+ appState.opened = ev.target.opened;
+ openedStateNode.innerText = appState.opened;
+ }
+ const popup = renderOffline(html`
+
+ Overlay
+
+ Hello! You can close this notification here:
+ e.target.dispatchEvent(new Event('close-overlay', { bubbles: true }))}
+ >
+ ⨯
+
+
+
+ `);
+
+ return html`
+
+ appState.opened: ${openedStateNode}
+
+ ${popup}
+
+ `;
+ })
+ .add('Intercept open/close', () => {
+ let shouldIntercept = true;
+ let shouldInterceptButton;
+ function toggleIntercept() {
+ shouldIntercept = !shouldIntercept;
+ shouldInterceptButton.textContent = shouldIntercept;
+ }
+ function intercept(ev) {
+ if (shouldIntercept) {
+ ev.preventDefault();
+ }
+ }
+ shouldInterceptButton = renderOffline(
+ html`
+
${shouldIntercept}
+ `,
+ );
+
+ const popup = renderOffline(html`
+
+ Overlay
+
+ Hello! You can close this notification here:
+ e.target.dispatchEvent(new Event('close-overlay', { bubbles: true }))}
+ >
+ ⨯
+
+
+
+ `);
+
+ return html`
+
+ toggle shouldIntercept:${shouldInterceptButton}
+
+ ${popup}
+
+ `;
});
/* .add('Toggle placement with knobs', () => {
@@ -467,7 +553,7 @@ storiesOf('Overlay System | Overlay as a WC', module)
Hello! You can close this notification here:
e.target.dispatchEvent(new Event('hide', { bubbles: true }))}
+ @click=${e => e.target.dispatchEvent(new Event('close-overlay', { bubbles: true }))}
>⨯
diff --git a/packages/overlays/test-suites/OverlayMixin.suite.js b/packages/overlays/test-suites/OverlayMixin.suite.js
index cf95dff83..15b75ca4c 100644
--- a/packages/overlays/test-suites/OverlayMixin.suite.js
+++ b/packages/overlays/test-suites/OverlayMixin.suite.js
@@ -1,4 +1,5 @@
import { expect, fixture, html, aTimeout } from '@open-wc/testing';
+import sinon from 'sinon';
export function runOverlayMixinSuite({ /* tagString, */ tag, suffix = '' }) {
describe(`OverlayMixin${suffix}`, () => {
@@ -53,5 +54,87 @@ export function runOverlayMixinSuite({ /* tagString, */ tag, suffix = '' }) {
itEl.config = { viewportConfig: { placement: 'left' } };
expect(itEl._overlayCtrl.viewportConfig.placement).to.equal('left');
});
+
+ it('fires "opened-changed" event on hide', async () => {
+ const spy = sinon.spy();
+ el = await fixture(html`
+ <${tag} @opened-changed="${spy}">
+