Skip to content

docs: add Grid click-to-select example for multi-select mode - #6188

Draft
totally-not-ai[bot] wants to merge 2 commits into
mainfrom
docs/grid-selection-drop-editing-examples
Draft

totally-not-ai[bot] wants to merge 2 commits into
mainfrom
docs/grid-selection-drop-editing-examples

Conversation

@totally-not-ai

@totally-not-ai totally-not-ai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This adds a short Flow example to the Grid selection page. It shows how to select or deselect a row by clicking it in multi-select mode, while still respecting a conditional selection rule.

What changed

  • Added a new section, "Selecting Rows by Clicking", to articles/components/grid/selection.adoc. It is marked as Flow-only.
  • The section explains that clicking a row in multi-select mode does not change its selection by default. It shows how to use an item click listener to toggle selection.
  • It also notes that programmatic selection ignores the conditional selection predicate (setItemSelectableProvider). So the example checks the same predicate inside the listener before it selects a row.
  • The Tree Grid subtree highlight example that was first in this PR has moved to docs: add Tree Grid subtree highlight example #6211.

This is a docs-only change and is fully backward-compatible.

Add a Flow example to the Tree Grid styling page that highlights the
descendants of the selected row with a custom part name, and document
how to toggle selection by clicking a row in multi-select mode while
respecting a conditional selection predicate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Preview Deployment

This PR has been deployed for preview.

URL: https://docs-preview-pr-6188.fly.dev

Changed pages

Added content is highlighted in green; removed content is marked in red on each page.

Built from 688bcd3

Comment on lines +131 to +153
=== Selecting Rows by Clicking [badge-flow]#Flow#

In multi-select mode, clicking a row doesn't change its selection by default. To let users toggle the selection by clicking anywhere on a row, add an item click listener that selects or deselects the clicked item. Programmatic selection ignores the <<#conditional-selection,conditional selection>> predicate, so if you use one, check it in the listener as well.

[source,java]
----
grid.setSelectionMode(Grid.SelectionMode.MULTI);
SerializablePredicate<Order> isSelectable = order -> order
.getStatus() != Order.State.COMPLETE;
grid.setItemSelectableProvider(isSelectable);

grid.addItemClickListener(event -> {
Order order = event.getItem();
if (!isSelectable.test(order)) {
return;
}
if (grid.getSelectedItems().contains(order)) {
grid.deselect(order);
} else {
grid.select(order);
}
});
----

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't Grid have an API similar to the selection column's autoSelect?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@totally-not-ai I'm asking you :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@vursen Sorry, I missed that! Partly. The web component's <vaadin-grid-selection-column> has an autoSelect property (auto-select attribute): when it's set, the row that becomes active on click is toggled, and shift-click selects a range. That's exactly this use case. Flow doesn't expose it, though. GridMultiSelectionModel and GridSelectionColumn only have setDragSelect, and there's no public accessor for the selection column element, so in Flow the item click listener is currently the only supported way.

Options:

  1. Document auto-select for Lit and React, and keep the click-listener snippet for Flow with a note that there's no API for it yet.
  2. Add a setAutoSelect(boolean) to GridMultiSelectionModel in flow-components (next to setDragSelect), then document that for all three frameworks and drop the listener workaround.

I'd go with 2, with 1 as the interim if you want this merged before the API lands. Which would you prefer?

Comment on lines +33 to +55
== Highlighting a Subtree [badge-flow]#Flow#

Custom part names can depend on the position of an item in the hierarchy. In the example below, selecting a row highlights all of its descendants with a `selected-subtree` part name. The part name generator checks whether the selected item is an ancestor of the rendered item. Because part names are generated only when a row is rendered, the selection listener refreshes the descendants of both the previously and the newly selected item.

[.example,themes="lumo,aura"]
--
[source,typescript]
----
include::{root}/frontend/demo/component/tree-grid/tree-grid-imports.ts[preimport,hidden]
----

[source,java]
----
include::{root}/src/main/java/com/vaadin/demo/component/treegrid/TreeGridSubtreeHighlight.java[render,tags=snippet,indent=0]
----

[source,css]
----
include::{root}/frontend/themes/docs/tree-grid-subtree-highlight.css[]
----
--

See <<../grid/styling#part-name-generator,Dynamically Styling Rows & Columns>> for more information about custom part names.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@totally-not-ai Extract this change into a separate PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@vursen Done. The Tree Grid subtree highlight example (the section, TreeGridSubtreeHighlight, and its stylesheet) is now in its own PR, #6211, and I removed it from this one.

It's now proposed in #6211.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@totally-not-ai totally-not-ai Bot changed the title docs: add Tree Grid subtree highlight and Grid click-to-select examples docs: add Grid click-to-select example for multi-select mode Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant