Skip to content

Commit

Permalink
[1070] Ensure the selected item is visible
Browse files Browse the repository at this point in the history
Bug: #1070
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
  • Loading branch information
pcdavid committed Mar 1, 2022
1 parent 2c21768 commit c897152
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions frontend/src/tree/TreeItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ export const TreeItem = ({
className = `${className} ${styles.selected}`;
dataTestid = 'selected';
}
useEffect(() => {
if (selected) {
if (refDom.current.scrollIntoViewIfNeeded) {
refDom.current.scrollIntoViewIfNeeded(true);
} else {
// Fallback for browsers not supporting the non-standard `scrollIntoViewIfNeeded`
refDom.current.scrollIntoView({ behavior: 'smooth' });
}
}
}, [selected]);

let image = <NoIcon title={item.kind} />;
if (item.imageURL) {
Expand Down

0 comments on commit c897152

Please sign in to comment.