Skip to content

Conversation

@javiercn
Copy link
Member

@javiercn javiercn commented Dec 2, 2025

Summary

This PR adds a new OnRowClick parameter to the QuickGrid component, allowing users to handle row click events. This addresses a common scenario where developers need to respond to user clicks on grid rows.

Fixes #44899

Changes

  • Added OnRowClick parameter of type EventCallback<TGridItem> to QuickGrid
  • When the delegate is set:
    • Row elements receive a row-clickable CSS class
    • A cursor: pointer style is applied via scoped CSS
    • Clicking the row invokes the callback with the clicked item
  • Added E2E tests to verify the callback is triggered and cursor style is applied

Usage Example

<QuickGrid Items="@people" OnRowClick="HandleRowClick">
    <PropertyColumn Property="@(p => p.Name)" />
</QuickGrid>

@code {
    void HandleRowClick(Person person)
    {
        // Handle the row click
        Console.WriteLine($"Clicked: {person.Name}");
    }
}

Files Changed

File Description
QuickGrid.razor Added if/else in RenderRow to apply click handler and CSS class
QuickGrid.razor.cs Added OnRowClick parameter with XML docs
QuickGrid.razor.css Added .row-clickable CSS class with cursor:pointer
PublicAPI.Unshipped.txt Documented new public API
SampleQuickGridComponent.razor Updated test component with OnRowClick handler
QuickGridTest.cs Added E2E tests for OnRowClick behavior

Copilot AI review requested due to automatic review settings December 2, 2025 18:39
@javiercn javiercn requested a review from a team as a code owner December 2, 2025 18:39
@github-actions github-actions bot added the area-blazor Includes: Blazor, Razor Components label Dec 2, 2025
Copilot finished reviewing on behalf of javiercn December 2, 2025 18:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an OnRowClick EventCallback parameter to the QuickGrid component, enabling developers to handle row click events. The implementation conditionally applies the row-clickable CSS class and click handler when the callback is set, with accompanying E2E tests to verify functionality.

Key Changes:

  • Added OnRowClick EventCallback parameter to QuickGrid
  • Implemented conditional rendering in RenderRow to attach click handlers and apply styling when the callback is set
  • Added CSS styling (cursor: pointer) for clickable rows via the row-clickable class

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
QuickGrid.razor Modified RenderRow method to conditionally apply click handlers and row-clickable class based on OnRowClick.HasDelegate
QuickGrid.razor.cs Added OnRowClick parameter with XML documentation
QuickGrid.razor.css Added .row-clickable CSS class with cursor: pointer styling
PublicAPI.Unshipped.txt Documented the new public API getter/setter for OnRowClick
SampleQuickGridComponent.razor Updated test component to include row click handling with state tracking
QuickGridTest.cs Added E2E tests verifying callback invocation and cursor styling
Agents.md New documentation file (unrelated to this PR's purpose)

@javiercn
Copy link
Member Author

javiercn commented Dec 2, 2025

@copilot fix the following test

Microsoft.AspNetCore.Components.E2ETests.Tests.QuickGridTest.RowClassApplied

Assert.Equal() Failure: Strings differ
           ↓ (pos 0)
Expected: "highlight"
Actual:   "row-clickable highlight"
           ↑ (pos 0)

Update to match the expectations as needed.

Also implement the suggestion from

The if/else block contains significant code duplication. The only differences between the two branches are the @OnClick handler and the row-clickable class. Consider consolidating this logic to avoid duplication:

You can remove the commit about Agents.md from this change too.

Anything else, leave it be.

Copy link
Contributor

Copilot AI commented Dec 2, 2025

@javiercn I've opened a new pull request, #64606, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Dec 3, 2025

@javiercn I've opened a new pull request, #64621, to work on those changes. Once the pull request is ready, I'll request review from you.

@javiercn javiercn changed the title Add OnRowClick EventCallback to QuickGrid [Blazor] Add OnRowClick EventCallback to QuickGrid Dec 3, 2025
Copy link
Contributor

Copilot AI commented Dec 3, 2025

@javiercn I've opened a new pull request, #64628, to work on those changes. Once the pull request is ready, I'll request review from you.

javiercn and others added 3 commits December 3, 2025 13:27
This change adds an OnRowClick parameter to QuickGrid that allows users to handle row click events. When the OnRowClick delegate is set:

- The row receives a 'row-clickable' CSS class
- A cursor: pointer style is applied via scoped CSS
- Clicking the row invokes the callback with the row item

Fixes #44899
* Initial plan

* Fix RowClassApplied test and consolidate RenderRow logic

Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>

* Fix trailing space in combinedClass when rowClass is null

Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
…cation (#64621)

* Initial plan

* Simplify RenderRow by removing if/else and coalescing OnRowClick callback

Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
@javiercn javiercn force-pushed the javiercn/quickgrid-row-click-event branch from e3cd250 to d16f068 Compare December 3, 2025 12:27
: rowClass;
var rowClick = OnRowClick.HasDelegate ? EventCallback.Factory.Create<MouseEventArgs>(this, () => OnRowClick.InvokeAsync(item)) : default;

<tr @key="@(ItemKey(item))"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the row click behave when it comes to propagation? Will a click on the element bubble up to its ancestor DOM element? Do we have to support stopPropagation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blazor uses event delegation for handling events. All events bubble up to the root where the handler intercepts them and then dispatches to the appropriate Blazor code. We normally don't stop event propagation unless we have good reasons to.

https://learn.microsoft.com/en-us/aspnet/core/blazor/components/event-handling?view=aspnetcore-10.0#stop-event-propagation

@javiercn javiercn merged commit 6b8e991 into main Dec 4, 2025
30 checks passed
@javiercn javiercn deleted the javiercn/quickgrid-row-click-event branch December 4, 2025 14:45
@dotnet-policy-service dotnet-policy-service bot added this to the 11.0-preview1 milestone Dec 4, 2025
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QuickGrid: Add EventCallback<TGridItem> for clicking on a row.

3 participants