-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[TreeView] Add focusedNode
prop
#11343
Conversation
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
focusedNodeId
prop
packages/x-tree-view/src/internals/plugins/useTreeViewFocus/useTreeViewFocus.ts
Outdated
Show resolved
Hide resolved
focusedNodeId
propfocusedNode
prop
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
packages/x-tree-view/src/internals/plugins/useTreeViewFocus/useTreeViewFocus.types.ts
Outdated
Show resolved
Hide resolved
packages/x-tree-view/src/internals/plugins/useTreeViewFocus/useTreeViewFocus.types.ts
Outdated
Show resolved
Hide resolved
packages/x-tree-view/src/internals/plugins/useTreeViewId/useTreeViewId.types.ts
Outdated
Show resolved
Hide resolved
...ee-view/src/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.ts
Show resolved
Hide resolved
packages/x-tree-view/src/internals/plugins/useTreeViewFocus/useTreeViewFocus.ts
Show resolved
Hide resolved
@@ -89,10 +79,10 @@ export const useTreeViewFocus: TreeViewPlugin<UseTreeViewFocusSignature> = ({ | |||
const createHandleBlur = | |||
(otherHandlers: EventHandlers) => (event: React.FocusEvent<HTMLUListElement>) => { | |||
otherHandlers.onBlur?.(event); | |||
setFocusedNodeId(null); | |||
models.focusedNode.setControlledValue(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be in favor of having one single function that calls setControlledValue
, that way it can also call onFocusedNodeChange
without any fear of missing on occurence.
Here, I think it should call onFocusedNodeChange
since it's now the callback of a controllable model.
This would require to change the signature of onFocusedNodeChange
to accept null
Right now in your doc example, when we blur the Tree View, the previously focused element remains visually focused, which is not the intended behavior IMHO.
But this raises another question: if the Tree View is not focused and focusedNode != null
, should we display the item as focused? I don't think so, I think that isNodeFocused
should check if the Tree View is focused.
I would like to have the opinion of others on this one @LukasTy @alexfauquette
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may lack of context, but from my past experience on the data grid and pickers, each time we tracked a focused
item, if the component don't have focus, it's not visible, but used to initial the focus when it comes back.
Here is a data grid example of the focus coming back to the last focused cell
Screencast.from.22-01-2024.14.49.00.mp4
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
I opened a separate PR for this to keep things clean. Closing this one in favor of #12143 |
closes #10236
TODO: