Skip to content

Modal OnClose event not called when Modal closed with ESC key (when closed for the first time). #273

@m-chandler

Description

@m-chandler

Describe the bug

When a Modal is closed for the very first time using the ESC key, the OnClose handler is not invoked. If it is opened again and then closed the ESC the OnClose handler is then invoked.

To Reproduce

A single file component is shown below.

  1. Click the button to open the Modal.
  2. Press the ESC key on keyboard.
  3. Note that below the text "Step 3: Verify modal close events below." nothing is logged, suggesting the OnClose handler was not invoked.
  4. Click the button again to open the Modal.
  5. Press the ESC key on keyboard.
  6. Note that below the text "Step 3: Verify modal close events below.", a close event is now logged.
<div>
    <Modal @ref="Modal">
        <ModalDialog Title="Test Modal" OnClose="ModalOnClose" Size="Size.Large">
            <BodyTemplate>
                Step 2. Press ESC to close. 
                The first time you do this, the Close is not registered
            </BodyTemplate>
        </ModalDialog>
    </Modal>
    <button class="btn btn-primary" @onclick="() => Modal?.Show()">Step 1. Click to Show Modal</button>
    <hr/>
    <p>Step 3: Verify modal close events below.</p>
    @foreach (var modalEvent in ModalEvents)
    {
        <p>@modalEvent</p>
    }
</div>

@code
{

    public List<string> ModalEvents { get; } = new();
    public Modal? Modal { get; set; }

    public Task ModalOnClose()
    {
        ModalEvents.Add($"Modal Closed: {DateTimeOffset.Now:O}");
        StateHasChanged();
        return Task.CompletedTask;
    }
}

Further technical details

  • BootstrapBlazor version: Tried with 6.12.0 and 7.0.0
  • Include the output of dotnet --info
.NET SDK:
 Version:   7.0.100
 Commit:    e12b7af219

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22621
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.100\

Host:
  Version:      7.0.0
  Architecture: x64
  Commit:       d099f075e4

.NET SDKs installed:
  5.0.302 [C:\Program Files\dotnet\sdk]
  5.0.408 [C:\Program Files\dotnet\sdk]
  6.0.111 [C:\Program Files\dotnet\sdk]
  6.0.202 [C:\Program Files\dotnet\sdk]
  6.0.203 [C:\Program Files\dotnet\sdk]
  6.0.306 [C:\Program Files\dotnet\sdk]
  7.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download 
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version: VS Code

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions