From 7e8cfcd440d6ad97debcc25e2dcc7658de61f3e0 Mon Sep 17 00:00:00 2001 From: Manon Carbonnel Date: Wed, 4 Oct 2023 17:57:55 +0200 Subject: [PATCH] fix(modal): fix reviewed changes --- .../src/components/osds-modal/osds-modal.tsx | 54 +++++++------------ .../modal/modal.web-components.stories.ts | 42 +++++++-------- 2 files changed, 37 insertions(+), 59 deletions(-) diff --git a/packages/components/modal/src/components/osds-modal/osds-modal.tsx b/packages/components/modal/src/components/osds-modal/osds-modal.tsx index 88c2bf53ae..40ae51a408 100644 --- a/packages/components/modal/src/components/osds-modal/osds-modal.tsx +++ b/packages/components/modal/src/components/osds-modal/osds-modal.tsx @@ -12,7 +12,7 @@ import { OdsModalMethod } from './interfaces/methods'; @Component({ tag: 'osds-modal', styleUrl: 'osds-modal.scss', - shadow: true + shadow: true, }) export class OsdsModal implements OdsModalAttribute, OdsModalMethod { @Element() el!: HTMLElement; @@ -48,13 +48,13 @@ export class OsdsModal implements OdsModalAttribute, OdsModalMethod { @Watch('masked') watchOpenedStateHandler(masked: boolean) { const directChildren = Array.from(document.body.children); - const filteredChildren = directChildren.filter(child => child !== this.el && child.nodeName !== 'SCRIPT'); - - for (const child of filteredChildren) { - if (!masked) { - child.setAttribute('inert', ''); - } else { - child.removeAttribute('inert'); + for (const child of directChildren) { + if (child !== this.el && child.nodeName !== 'SCRIPT') { + if (!masked) { + child.setAttribute('inert', ''); + } else { + child.removeAttribute('inert'); + } } } } @@ -64,13 +64,7 @@ export class OsdsModal implements OdsModalAttribute, OdsModalMethod { } render() { - - const { - color, - headline, - dismissible, - masked - } = this; + const { color, headline, dismissible, masked } = this; return ( @@ -78,33 +72,21 @@ export class OsdsModal implements OdsModalAttribute, OdsModalMethod {
- { dismissible && - this.close()} - color={color} - circle={true} - ghost={true} - > - + {dismissible && ( + this.close()} color={color} circle={true} ghost={true}> + - } + )}
- {headline && headline.length > 0 && + {headline && headline.length > 0 && (
- {headline} + + {headline} +
- } + )}
diff --git a/packages/storybook/stories/components/modal/modal.web-components.stories.ts b/packages/storybook/stories/components/modal/modal.web-components.stories.ts index f04b2585f7..bc40efdd41 100644 --- a/packages/storybook/stories/components/modal/modal.web-components.stories.ts +++ b/packages/storybook/stories/components/modal/modal.web-components.stories.ts @@ -51,55 +51,51 @@ export default { }, docs: { page }, }, - argTypes: extractArgTypes(storyParams) + argTypes: extractArgTypes(storyParams), }; -const TemplateDefault = (args:any) => { +const TemplateDefault = (args: any) => { const handleOpenModal = () => { const modal = document.querySelector('osds-modal'); if (modal) { modal.open(); - locationChangeTrigger(); } - } + }; const handleCloseModal = () => { const modal = document.querySelector('osds-modal'); if (modal) { modal.close(); } - } + }; -const locationChangeTrigger = () => { - let prevUrl = document.location.href; - const body = document.querySelector("body"); + const locationChangeTrigger = () => { + let prevUrl = document.location.href; + const body = document.querySelector('body'); - const observer = new MutationObserver(() => { - if (prevUrl !== document.location.href) { - prevUrl = document.location.href; + const observer = new MutationObserver(() => { + if (prevUrl !== document.location.href) { + prevUrl = document.location.href; - const modals = document.getElementsByTagName('osds-modal'); + const modals = document.getElementsByTagName('osds-modal'); for (let i = 0; i < modals.length; i++) { modals[i].close(); } - } - }); - observer.observe(body, { childList: true, subtree: true }); -}; + } + }); + observer.observe(body, { childList: true, subtree: true }); + }; -window.onload = locationChangeTrigger; + window.onload = locationChangeTrigger; return html` ${locationChangeTrigger()} - - ${unsafeHTML(args.content)} - ${unsafeHTML(args.actions)} - - ` -} + ${unsafeHTML(args.content)} ${unsafeHTML(args.actions)} + `; +}; export const Default = TemplateDefault.bind({}); Default.args = {