From acc49099810d2e97468be0bc3bb8b7896d5097de Mon Sep 17 00:00:00 2001 From: Ritesh Patil Date: Tue, 1 Aug 2023 14:21:45 +0530 Subject: [PATCH] fix: embed hides floating button (#9165) * fix: embed - hides floating button on click to prevent overlapping over modal * revert changes on yarn.lock * z-index for Modal wasnt highest --------- Co-authored-by: Peer Richelsen Co-authored-by: Keith Williams Co-authored-by: Hariom Balhara --- .../src/FloatingButton/FloatingButton.ts | 10 +++++++++- .../src/FloatingButton/FloatingButtonHtml.ts | 2 +- .../embeds/embed-core/src/ModalBox/ModalBox.ts | 14 +++++++++++--- .../embeds/embed-core/src/ModalBox/ModalBoxHtml.ts | 2 +- packages/embeds/embed-core/src/embed.ts | 11 +++++++++-- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/packages/embeds/embed-core/src/FloatingButton/FloatingButton.ts b/packages/embeds/embed-core/src/FloatingButton/FloatingButton.ts index b5e8168a10..b1fd6b7446 100644 --- a/packages/embeds/embed-core/src/FloatingButton/FloatingButton.ts +++ b/packages/embeds/embed-core/src/FloatingButton/FloatingButton.ts @@ -23,6 +23,7 @@ const dataAttributes = [ "data-button-position", "data-button-color", "data-button-text-color", + "data-toggle-off", ] as const; type DataAttributes = (typeof dataAttributes)[number]; @@ -42,7 +43,7 @@ export class FloatingButton extends HTMLElement { // Button added here triggers the modal on click. So, it has to have the same data attributes as the modal target as well dataset!: DOMStringMap & FloatingButtonDataset & ModalTargetDatasetProps; - + buttonWrapperStyleDisplay!: HTMLElement["style"]["display"]; // eslint-disable-next-line @typescript-eslint/ban-ts-comment //@ts-ignore static get observedAttributes() { @@ -74,6 +75,13 @@ export class FloatingButton extends HTMLElement { buttonWrapperEl.style.backgroundColor = newValue; } else if (name === "data-button-text-color") { buttonWrapperEl.style.color = newValue; + } else if (name === "data-toggle-off") { + const off = newValue == "true"; + if (off) { + // When toggling off, back up the original display value so that it can be restored when toggled back on + this.buttonWrapperStyleDisplay = buttonWrapperEl.style.display; + } + buttonWrapperEl.style.display = off ? "none" : this.buttonWrapperStyleDisplay; } else { console.log("Unknown attribute changed", name, oldValue, newValue); } diff --git a/packages/embeds/embed-core/src/FloatingButton/FloatingButtonHtml.ts b/packages/embeds/embed-core/src/FloatingButton/FloatingButtonHtml.ts index a1c4da9c2b..b31abce7b0 100644 --- a/packages/embeds/embed-core/src/FloatingButton/FloatingButtonHtml.ts +++ b/packages/embeds/embed-core/src/FloatingButton/FloatingButtonHtml.ts @@ -11,7 +11,7 @@ const getHtml = ({ }) => { // IT IS A REQUIREMENT THAT ALL POSSIBLE CLASSES ARE HERE OTHERWISE TAILWIND WONT GENERATE THE CSS FOR CONDITIONAL CLASSES // To not let all these classes apply and visible, keep it hidden initially - return `