From 626e05d0c40d1213d4b538a9cc35bf4b312ce6d1 Mon Sep 17 00:00:00 2001 From: Christian Swinehart Date: Mon, 4 Sep 2023 13:55:19 -0400 Subject: [PATCH] :bug: harmonize full-screen modal & controls drawer - their dismiss-on-click behaviors now work together --- .../grapher/src/controls/Controls.scss | 13 +++++-------- .../grapher/src/controls/Controls.tsx | 3 ++- .../@ourworldindata/grapher/src/core/grapher.scss | 4 +++- .../grapher/src/fullScreen/FullScreen.tsx | 5 ++--- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/@ourworldindata/grapher/src/controls/Controls.scss b/packages/@ourworldindata/grapher/src/controls/Controls.scss index 2f78a64d37c..5d6cba7b664 100644 --- a/packages/@ourworldindata/grapher/src/controls/Controls.scss +++ b/packages/@ourworldindata/grapher/src/controls/Controls.scss @@ -1,6 +1,3 @@ -$zindex-ControlsDrawer: 105; // needs to be higher than .site-tools -$zindex-ControlsBackdrop: 104; - $light-stroke: #e7e7e7; $dark-stroke: #2d2d2d; @@ -63,7 +60,7 @@ nav.controlsRow .controls { background: white; border-radius: 4px; box-shadow: 0px 4px 23px 4px #0000000f; - z-index: $zindex-ControlsDrawer; + z-index: $zindex-controls-drawer; overflow-y: scroll; } @@ -74,7 +71,7 @@ nav.controlsRow .controls { top: 0; width: 100%; height: 100%; - z-index: $zindex-ControlsBackdrop; + z-index: $zindex-controls-backdrop; } } } @@ -88,10 +85,10 @@ nav.controlsRow .controls { top: 0; width: 300px; height: 100vh; - z-index: $zindex-ControlsDrawer; + z-index: $zindex-controls-drawer; overflow-y: scroll; background: white; - padding-top: 80px; + padding-top: $indent; .config-header { position: static; @@ -104,7 +101,7 @@ nav.controlsRow .controls { right: 0; bottom: 0; background: rgba(0, 0, 0, 0.2); - z-index: $zindex-ControlsBackdrop; + z-index: $zindex-controls-backdrop; } } diff --git a/packages/@ourworldindata/grapher/src/controls/Controls.tsx b/packages/@ourworldindata/grapher/src/controls/Controls.tsx index e002470c885..5ff105adf4b 100644 --- a/packages/@ourworldindata/grapher/src/controls/Controls.tsx +++ b/packages/@ourworldindata/grapher/src/controls/Controls.tsx @@ -236,10 +236,11 @@ export class SettingsMenu extends React.Component<{ // TODO: add a showCompareEndPointsOnlyTogggle to complement compareEndPointsOnly } - @action.bound toggleVisibility(): void { + @action.bound toggleVisibility(e: React.MouseEvent): void { this.visible = !this.visible if (this.visible) this.shouldRender = true this.drawer?.classList.toggle("active", this.visible) + e.stopPropagation() } @action.bound onAnimationEnd(): void { diff --git a/packages/@ourworldindata/grapher/src/core/grapher.scss b/packages/@ourworldindata/grapher/src/core/grapher.scss index 35446f9d2d3..b6d46f9c966 100644 --- a/packages/@ourworldindata/grapher/src/core/grapher.scss +++ b/packages/@ourworldindata/grapher/src/core/grapher.scss @@ -48,7 +48,9 @@ $zindex-global-entity-select: 11; $zindex-Tooltip: 20; $zindex-modal: 30; -$zindex-full-screen: 2000; +$zindex-full-screen: 120; +$zindex-controls-backdrop: 130; +$zindex-controls-drawer: 140; // needed for .global-entity-control-container @mixin xxlg-down { diff --git a/packages/@ourworldindata/grapher/src/fullScreen/FullScreen.tsx b/packages/@ourworldindata/grapher/src/fullScreen/FullScreen.tsx index 7a138a45467..e94b3529715 100644 --- a/packages/@ourworldindata/grapher/src/fullScreen/FullScreen.tsx +++ b/packages/@ourworldindata/grapher/src/fullScreen/FullScreen.tsx @@ -11,7 +11,7 @@ export class FullScreen extends React.Component<{ }> { content: React.RefObject = React.createRef() - @action.bound onDocumentClick(e: MouseEvent): void { + @action.bound onDocumentClick(e: React.MouseEvent): void { // check if the click was outside of the modal if ( this.content?.current && @@ -27,12 +27,10 @@ export class FullScreen extends React.Component<{ } componentDidMount(): void { - document.addEventListener("click", this.onDocumentClick) document.addEventListener("keydown", this.onDocumentKeyDown) } componentWillUnmount(): void { - document.removeEventListener("click", this.onDocumentClick) document.removeEventListener("keydown", this.onDocumentKeyDown) } @@ -43,6 +41,7 @@ export class FullScreen extends React.Component<{ className="FullScreenOverlay" role="dialog" aria-modal="true" + onClick={this.onDocumentClick} style={{ backgroundColor: this.props.overlayColor ?? "#fff", }}