Support :single as select_variant for TreeView #3712
+574
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What are you trying to accomplish?
Allow
select_variant: :single
forPrimer::Alpha::TreeView
. The goal is to allow the TreeView to behave like a single-select component — meaning only one item can be selected at a time. This is particularly useful in scenarios where the user should choose one item out of many in a hierachy (similar to a radio button group).Screenshots
Integration
It should not, as it only adding an option
List the issues that this change affects.
Closes #3701
Risk Assessment
What approach did you choose and why?
I based my current draft on the implementation on how SelectPanel handles single-selection. Specifically:
select_variant: :multiple
works.One difference from the SelectPanel is the position of the checkmark. In the TreeView, the checkmark is shown at the end of the line rather than the beginning.
This was necessary because placing the checkmark at the start of the line led to large visual gaps — especially since most items do not show a checkmark at all.
The current placement helps maintain a more consistent and compact layout.
Anything you want to highlight for special attention from reviewers?
Currently, it is impossible to deselect an item once a selection was made. I copied that behaviour from the SelectPanel as well, but that is up for discussion.
Accessibility
Since the selection is made via the
aria-checked
, the current selection is accessible for screen reader usersThe TreeView can be used via KeyBoard:
Merge checklist