mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Fix scrolling to selected row in collapsed mode
This commit is contained in:
@@ -429,6 +429,21 @@ export default class Store extends EventEmitter {
|
||||
return null;
|
||||
}
|
||||
|
||||
isInsideCollapsedSubTree(id: number): boolean {
|
||||
let current = this._idToElement.get(id);
|
||||
while (current != null) {
|
||||
if (current.parentID === 0) {
|
||||
return false;
|
||||
} else {
|
||||
current = this._idToElement.get(current.parentID);
|
||||
if (current != null && current.isCollapsed) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
startProfiling(): void {
|
||||
this._bridge.send('startProfiling');
|
||||
|
||||
|
||||
@@ -596,6 +596,20 @@ function TreeContextController({ children, viewElementSource }: Props) {
|
||||
state = reduceTreeState(store, state, action);
|
||||
state = reduceSearchState(store, state, action);
|
||||
state = reduceOwnersState(store, state, action);
|
||||
|
||||
// If the selected ID is in a collapsed subtree, reset the selected index to null.
|
||||
// We'll know the correct index after the layout effect will toggle the tree,
|
||||
// and the store tree is mutated to account for that.
|
||||
if (
|
||||
state.selectedElementID !== null &&
|
||||
store.isInsideCollapsedSubTree(state.selectedElementID)
|
||||
) {
|
||||
return {
|
||||
...state,
|
||||
selectedElementIndex: null,
|
||||
};
|
||||
}
|
||||
|
||||
return state;
|
||||
default:
|
||||
throw new Error(`Unrecognized action "${type}"`);
|
||||
|
||||
Reference in New Issue
Block a user