Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wizard modal glitch #198

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/lib/components/Modal.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
import { fade, scale } from "svelte/transition";
import { quintOut } from "svelte/easing";
import { fade } from "svelte/transition";
import { createEventDispatcher } from "svelte";
import { i18n } from "$lib/stores/i18n";
import IconClose from "$lib/icons/IconClose.svelte";
Expand All @@ -22,22 +21,27 @@

const dispatch = createEventDispatcher();
const close = () => dispatch("nnsClose");

// A bit faster fade in that backdrop IN, a bit slower on OUT
const FADE_IN_DURATION = 125 as const;
const FADE_OUT_DURATION = 200 as const;
</script>

{#if visible}
<div
class="modal"
transition:fade={{ duration: 125 }}
transition:fade={{ duration: 25 }}
on:introend
{role}
data-tid={testId}
aria-labelledby={showHeader ? "modalTitle" : undefined}
aria-describedby="modalContent"
on:click|stopPropagation
on:introend
>
<Backdrop {disablePointerEvents} on:nnsClose />
<div
transition:scale={{ delay: 25, duration: 150, easing: quintOut }}
in:fade={{ duration: FADE_IN_DURATION }}
out:fade={{ duration: FADE_OUT_DURATION }}
class={`wrapper ${role}`}
>
{#if showHeader}
Expand Down
27 changes: 16 additions & 11 deletions src/lib/components/WizardModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import WizardTransition from "./WizardTransition.svelte";
import { WizardStepsState } from "$lib/stores/wizard.state";
import type { WizardStep, WizardSteps } from "$lib/types/wizard";
import { createEventDispatcher } from "svelte";

export let steps: WizardSteps;
export let disablePointerEvents = false;
Expand All @@ -21,20 +22,24 @@
export const back = () => (stepState = stepState.back());
export const set = (step: number) => (stepState = stepState.set(step));

let presented = false;
// onDestroy is not always called when repetitively opened/closed in NNS-dapp.
// This might be linked to Svelte issue https://github.com/sveltejs/svelte/issues/5268.
// We use to display the content of the wizard modal according the modal intro state (see GIT history) but, this happens to be visually glitchy.
// That is why we rather enforce not rendering any content in the DOM when the modal is closed which solve both issue.
const dispatch = createEventDispatcher();
let visible = true;
const close = () => {
visible = false;
dispatch("nnsClose");
};
</script>

<Modal
on:nnsClose
on:introend={() => (presented = true)}
{testId}
{disablePointerEvents}
>
<slot name="title" slot="title" />
{#if visible}
<Modal on:nnsClose={close} {testId} {disablePointerEvents}>
<slot name="title" slot="title" />

{#if presented}
<WizardTransition {transition}>
<slot />
</WizardTransition>
{/if}
</Modal>
</Modal>
{/if}