dotnet / dotnet/aspnetcore

Blazor: add returnValue to onclose event of <dialog>

Open
#66,496 3 comments 0 reactions 0 assignees View on GitHub
area-blazor copilot-candidate feature-request
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

_No response_

### Describe the solution you'd like

Add the returnValue of a `` to the onclose event. The `close` event of the HTMLDialogElement is just a generic `Event`, so an empty `EventArgs` seems right. But the returnValue gives the developer the information which button was pressed to close the dialog.

### Additional context

If you have a button like this
`Submit`
then the dialog will be closed and the content of `value` is placed into the `returnValue` property of the dialog. But you have to read it separately from this property, it is not part of the close event. When you are in C# you have to use JS Interop to get this value.

Before `` you usually need a dialog service and a container component somewhere in the body and some JavaScript and C# to wire everything together. Nowadays you can create and control the basic functionality of a dialog using HTML only. Opening and closing works with buttons and command/commandfor attributes. On the C# side it is mostly sufficient to subscribe to the already provided events `close` and `toggle`. When toggle is repaired (#66479) only the returnValue is missing to be able to skip JS interop at all.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.