From ea14cb2bd044f1c0ee329993f7d0b7b73d53b9ab Mon Sep 17 00:00:00 2001 From: Jaya Krishna Namburu Date: Mon, 17 Jul 2023 18:13:51 +0200 Subject: [PATCH] (fix): Re-focus the tree-node after completion of editing the name (#1945) ## Description 1. What is this PR about (link the issue and add a short description) ## Steps for reproduction 1. Use keyboard to navigate between the tree elements. 2. Click `Ctrl + E` to enter into edit mode. 3. Edit the name of the tree-node and then press `Enter`. 4. Use the up/down arrows to navigate to other nodes in the tree. ## Code Review - [ ] hi, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [x] made a self-review - [x] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [x] tested locally and on preview environment (preview dev login: 5de6) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio-builder/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env.example` and the `builder/env-check.js` if mandatory --- apps/builder/app/builder/shared/tree/index.tsx | 10 ++++++++-- .../design-system/src/components/tree/tree-node.tsx | 2 -- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/builder/app/builder/shared/tree/index.tsx b/apps/builder/app/builder/shared/tree/index.tsx index bf3760c4f6..5ee06ab54f 100644 --- a/apps/builder/app/builder/shared/tree/index.tsx +++ b/apps/builder/app/builder/shared/tree/index.tsx @@ -88,7 +88,7 @@ export const InstanceTree = ( const isEditing = props.itemData.id === editingItemId; return ( - + { + onChangeValue(value); + const button = ref.current?.closest( + "[data-item-button-id]" + ) as HTMLElement; + button?.focus(); + }, onChangeEditing, }); diff --git a/packages/design-system/src/components/tree/tree-node.tsx b/packages/design-system/src/components/tree/tree-node.tsx index f5c9d27ab4..fcac94c039 100644 --- a/packages/design-system/src/components/tree/tree-node.tsx +++ b/packages/design-system/src/components/tree/tree-node.tsx @@ -263,14 +263,12 @@ export const TreeItemBody = ({ forceFocus = false, selectionEvent = "click", onToggle, - isEditing = false, }: TreeItemRenderProps & { children: React.ReactNode; suffix?: React.ReactNode; suffixWidth?: string; alwaysShowSuffix?: boolean; forceFocus?: boolean; - isEditing?: boolean; selectionEvent?: "click" | "focus"; }) => { const [focusTarget, setFocusTarget] = useState<