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

Blazor WebAssembly - HTML select tag with @onchange event does not hit breakpoint when clicking to select values from dropdown using the cursor, but works with up/down key from keyboard #58615

Closed
1 task done
sly97 opened this issue Oct 24, 2024 · 6 comments
Labels
area-blazor Includes: Blazor, Razor Components Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue.

Comments

@sly97
Copy link

sly97 commented Oct 24, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In .NET8, in a new Blazor WebAssembly app, when using a <select> tag, with the @onchange event, if I put a breakpoint in the method being triggered (i.e. @onchange="Test"), the breakpoint will not be hit if I click on different values in the dropdown using the mouse.
However, the breakpoint is being hit fine when using the up/down keys from the keyboard.

In addition, when using the mouse, I can see that the method is run and states are changed - the issue I experienced is the breakpoint that is not being hit.

Additional info: doing the same in .NET6 works fine, and breakpoint is being hit just fine in all cases.

@page "/"

<select @onchange="Test">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
</select>

@code {
    private void Test()
    {
        // Given I've put a breakpoint in VS in the line above
        // It does not get triggered/hit when using the mouse/cursor to click in the dropdown, but it is hit when using up/down key works.
    }
}

Expected Behavior

Breakpoint is being hit when using the mouse/cursor to select different values from a select statement with the @onchange event

Steps To Reproduce

  1. Create a new Blazor Web Assembly project in VS2022.
  2. Add a select tag to any page (I did it to the Counter component)
  3. add the @onchange event to the select tag, and assign it with a method
  4. Put a breakpoint in the method assigned to the @onchange event
  5. Run the app, click on different values in the dropdown, and see that the breakpoint is not being hit.
    Then, try selecting using different values using the up/down keys from the keyboard, and the breakpoint should be hit

Exceptions (if any)

Breakpoint is hit when using the mouse to select different values from a dropdown menu.

.NET Version

8

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Oct 24, 2024
@javiercn
Copy link
Member

@sly97 thanks for contacting us.

Can you validate that the same behavior works if you switch Blazor Server? Can you also make sure that the underlying JS event is fired on the browser debugger? (You should be able to set a breakpoint when the event is raised).

@javiercn javiercn added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Oct 25, 2024
@Kevin-Lewis
Copy link

I've run into this same exact issue.

@page "/counter"
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

<select @onchange="SelectTest">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
</select>
private int currentCount = 0;

private void IncrementCount()
{
    currentCount++;
}

public void SelectTest(ChangeEventArgs e)
{
    return;
}

I created a test web app project to verify. It works as expected when set to InteractiveServer but as the OP described when set to InteractiveWebAssembly.

@Kevin-Lewis
Copy link

Kevin-Lewis commented Nov 6, 2024

@sly97 thanks for contacting us.

Can you validate that the same behavior works if you switch Blazor Server? Can you also make sure that the underlying JS event is fired on the browser debugger? (You should be able to set a breakpoint when the event is raised).

I also checked the underlying JS event and verified it is being fired as expected even when the breakpoint for my .NET event isn't hit. To summarize:

  • Click on the select, navigate to an option with arrow keys, click on the option -> Works
  • Click on the select, click on the option -> Does not Work
  • Click on the select, navigate to an option with arrow keys, press enter key -> Does not Work

@sly97
Copy link
Author

sly97 commented Nov 6, 2024

@javiercn
Apologies for the late reply.
I have checked and it seems to be working fine in Blazor Server (I've created a new project from VS, and chose the Blazor Server template option).
Also, thanks @Kevin-Lewis for your update, and can confirm that I get the same results when looking at the underlying JS events.
Can this issue please be re-opened as it seems to be a valid & ongoing issue?

@Marques01
Copy link

Marques01 commented Nov 12, 2024

@javiercn the problem still persists in wasm. It only hits the breakpoint with the arrows and not with clicks on the select


<label class="form-label">Countries</label>
<select class="form-select" @onchange="OnCountryChanged">
    <option value="1">USA></option>
    <option value="2">Canada</option>
    <option value="3">Mexico</option>
</select>
@code {

    private void OnCountryChanged(ChangeEventArgs e)
    {
    }

}

@affenkonig11b
Copy link

Also seeing this. Any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue.
Projects
None yet
Development

No branches or pull requests

5 participants