microsoft / fast

The adaptive interface system for modern web experiences.
https://www.fast.design
Other
9.25k stars 590 forks source link

feat: Indicate the difference between deselecting, and selecting a different tree-item #6777

Closed mrpmorris closed 3 months ago

mrpmorris commented 1 year ago

I am helping to write the Blazor FluentUI components.

I am writing a FluentNavMenu component which uses tree-view as a nested expandable menu structure, and I need to ensure that the user can select a different node (to navigate) but not simply deselect a node and leave none selected at all (you cannot navigate to nowhere).

At the moment I think I am seeing the following behaviour in a tree-view that already has a selected node -

Scenario 1: User selects a different node A: Notification that the currently selected node is no longer selected B: Notification that a different node is now selected

Scenario 2: User deselects the currently selected item A: Notification that the currently selected node is no longer selected

By step A I cannot tell if the user has selected a new node, or merely deselected the current one. So by step A I cannot determine if I should disallow the deselection by reselecting the node.

What would be useful would be to receive the selected == true notification for the newly selected node before the selected == false notification for the previous node. I understand this is a change in behaviour which might break existing code, so perhaps we could have a property added to the event, either

A: bool reselecting or B: nextSelected

This way if reselecting == false or nextSelected == null then I know the user is simply deselecting and I can force selected back to true.

If reselecting == true or nextSelected != null then I know the user is changing navigation and I can allow the item to become deselected as another will be selected afterwards.

Note: nextSelected would be more useful, because then we could also handle allowing/disallowing selection based on the state of the item.

janechu commented 3 months ago

Unfortunately @microsoft/fast-foundation is being deprecated, refer to #6955.