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

[Feature]: It would be great if the Dialog component supported a parameter like "onClose". #31129

Open
1 task done
phuctvt opened this issue Apr 21, 2024 · 4 comments
Open
1 task done

Comments

@phuctvt
Copy link

phuctvt commented Apr 21, 2024

Library

React Components / v9 (@fluentui/react-components)

Describe the feature that you would like added

Hello Fluent UI team,

I'm using the Fluent UI and I love it. Recently there was a situation in a project I'm working on, it's something like this sample: https://stackblitz.com/edit/urlkjp.

In the demo sample, if you select a product, wait ~2 seconds for it to finish loading the product descriptions, then click "Close", the dialog starts closing as normal, but at the moment it is fading out, we can see it has a flickering. Here is my screen recording of the slowed down what happened to easier show what I mean:

mpv_Q2lhAjOpqZ.mp4

The reason is in the file ProductListDialog.tsx, at line 41, the cleanUp() is called at the moment the dialog is fading out, it means the dialog is not closed completely yet, until the CSS animation finishes.

I think it would be better if the Dialog component supported a parameter like onClose: () => void. The onClose should be called when the dialog is completely closed, including the CSS animation. So I can assign my cleanUp to this param to avoid the flickering.


One workaround I found is, I can create a new below component and use it instead of the original DialogSurface, then I can assign cleanUp to onDialogClosed:

import React, { useEffect } from "react";
import { DialogSurfaceProps, DialogSurface as RealDialogSurface } from "@fluentui/react-components";

export function DialogSurface(
    props: DialogSurfaceProps & {
        /**
         * Callback that is called when the dialog is completely closed, including the animation.
         */
        onDialogClosed?: () => void;
    }
) {
    useEffect(() => {
        return () => {
            // This callback is called when the RealDialogSurface element is removed from DOM.
            props.onDialogClosed?.();
        };
    }, []);

    return <RealDialogSurface {...props}>{props.children}</RealDialogSurface>;
}

Here is a demo for it: https://stackblitz.com/edit/urlkjp-nlnoaz.

Have you discussed this feature with our team

No response

Additional context

No response

Validations

  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.

Priority

None

@miroslavstastny
Copy link
Member

Waiting for motion events support.

@jacksonv1lle
Copy link
Contributor

Create a separate component for the product listing and description and manage the load state from there instead.

Each time the dialog is opened, the new component should be re mounted

@phuctvt
Copy link
Author

phuctvt commented Apr 30, 2024

Hi @jacksonv1lle, it will work.

However, I think it's quite inconvenient for fairly common use cases. I usually see components that have names like this format SomethingDialog that wrap some business logic. For example, in cases of ProductListDialog, ConfirmationDialog, or LoginDialog, we have to create two components for each case.

@layershifter
Copy link
Member

Blocked by #30700.

@layershifter layershifter added the Status: Blocked Resolution blocked by another issue label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants