-
-
Notifications
You must be signed in to change notification settings - Fork 32.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] Fix focus steal #20232
[TreeView] Fix focus steal #20232
Conversation
Details of bundle changes.Comparing: c16f941...c9e2cae Details of page changes
|
https://codesandbox.io/s/bold-hill-rw9y5 - sandbox with bug |
- groups statements into arrange-act-assert - removes indirection in act (a click does what?) - moves from gDSFP to effect during mutation
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.
Similar approach used as in #20240:
- had a hard time with the click-mounted indirection (what does a click accomplish? why do I need to call it twice?) so I made an explicit state setter. Hope this makes it more clear
- update state when the item is removed not during the render after the item is removed
Yes that's better. |
@@ -56,9 +56,10 @@ const TreeView = React.forwardRef(function TreeView(props, ref) { | |||
...other | |||
} = props; | |||
const [tabbable, setTabbable] = React.useState(null); | |||
const [focused, setFocused] = React.useState(null); | |||
const [focusedNodeId, setFocusedNodeId] = React.useState(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.
focused
implies that this component is focused but it's actually for tracking other components. For example FormControl
also has a focused
state but that has a different meaning.
Confirmed manually that it does indeed fix the crashes in the linked issue. |
@tonyhallett Thanks! |
Closes #19882