Skip to content

How to detect when the file picker is canceled? #88

Description

@f957-cua

Hi there!
Brilliant package with many options.

It would be nice to have an onCancel callback to control this stage properly.

I mean to control the cancel button and the picker window close button.

Approach to openning filePicker simultaneously with backdrop behind is very popular nowadays.
And how to cover the case closing backdrop if user close filePicker with any selected files.

I have found the same needs with another library:
pnp/sp-dev-fx-controls-react#665

Activity

  1. MrKampla commented on Feb 14, 2024

    @MrKampla
    Collaborator

    Hi @f957-cua,
    I'm afraid I don't have a good answer to your question. Some time ago we wanted to change the open file picker function to return a promise, but it turned out there's no way of implementing rejection reliably across different browsers when user cancels the file selection. Blur and focus events are not fired correctly in browsers, so a user has to make some sort of an action like a click, to focus back the window.
    You can find more details here:
    #58 (comment)

    If you want to add a backdrop, I'd probably try to make a workaround by adding a visual element that clearly indicates user has to click on it in order to dismiss. For example a button with an unambiguous icon in the middle of the screen.

  2. f957-cua commented on Feb 14, 2024

    @f957-cua
    Author

    Hi @MrKampla,
    Thanks for your quick answer.
    Close backdrop is not a bid deal, you can just click on it.
    But I want to avoid this click and receive info from package, what file picker window was closed.

    Is it possible?

  3. MrKampla commented on Feb 14, 2024

    @MrKampla
    Collaborator

    I understand, but as I said, there's no reliable way of doing that, so use-file-picker package is also not offering such functionality.

  4. f957-cua commented on Feb 14, 2024

    @f957-cua
    Author

    I know.
    You're maintaining a nice product, from my POV.
    It's only wish for the future.)
    Don't give up on this idea, maybe in the future something will have been changed in browsers with event handling.

  5. Jaaneek commented on Feb 15, 2024

    @Jaaneek
    Owner

    As @MrKampla said:

    I understand, but as I said, there's no reliable way of doing that, so use-file-picker package is also not offering such functionality.

    I'm closing it, feel free to open another issue if you have any questions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions