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

Option to not close dialog on blur #42

Closed
simonsegatin opened this issue Dec 12, 2023 · 3 comments · Fixed by #43
Closed

Option to not close dialog on blur #42

simonsegatin opened this issue Dec 12, 2023 · 3 comments · Fixed by #43
Assignees
Labels
enhancement New feature or request

Comments

@simonsegatin
Copy link

Hi,

first of all thank you for porting Headless UI to Blazor, it's really awesome. I did find the default behavior of dialogs where they close on blur is a bit restrictive.

For example, if I have a form in a slide-over implemented using a dialog, I don't want it to close if the user clicks outside of it as that makes it really easy to unintentionally lose changes. I've kind of solved this by putting the DialogPanel component at the root (e.g. above the backdrop) which works ok but feels a bit hacky.

However, a more difficult problem is if I want to open a nested dialog without closing the previous one. Using the previous example, let's say I want the user to confirm they want to discard any changes they made when clicking Cancel in the slide over form. I'll show a modal dialog prompting them if they want to discard the changes. This works fine, but as soon as they click inside of that modal (e.g. on a "Keep editing" button), the dialog panel of the slide over loses focus and the root dialog closes.

Would it be possible to add an option to disable closing on blur or even better have a way to trigger an event callback on blur. That way, when the user clicks outside of the dialog panel, I could detect it and show the discard changes prompt then close the root dialog based on the user's choice.

Thanks!

@DavidVollmers
Copy link
Owner

Hi,

Thank you for using Ignis!

You made a good point here. I will make sure to provide event callbacks for focus and blur on all components, so one can cancel them (similar to other events in Ignis).

I hope I will find the time for it today, but expect an update this week :)

@DavidVollmers DavidVollmers self-assigned this Dec 13, 2023
@DavidVollmers DavidVollmers added enhancement New feature or request good first issue Good for newcomers and removed good first issue Good for newcomers labels Dec 13, 2023
@DavidVollmers DavidVollmers linked a pull request Dec 14, 2023 that will close this issue
@DavidVollmers
Copy link
Owner

DavidVollmers commented Dec 14, 2023

@simonsegatin So with version 1.1.0 you can now prevent the default bahvior of all focus components using the OnBlur event callback. Specifically for your use case you will want to overwrite it on the DialogPanel component:

<DialogPanel OnBlur="e => e.PreventDefault()">
</DialogPanel>

@simonsegatin
Copy link
Author

Great, thanks for the quick update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants