Skip to content

Commit

Permalink
Fix missing onEscape handle in SelectTree (woocommerce#49396)
Browse files Browse the repository at this point in the history
* Fix missing onEscape handle in SelectTree

* Avoid passing onEscape to html element

* Propagate onEscape for recursive Tree
  • Loading branch information
nathanss authored Jul 17, 2024
1 parent 16513b3 commit f2a4db4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/js/components/changelog/fix-add-escape-handle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fix
Comment: Fix missing onEscape handle in SelectTree


Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ export const SelectTree = function SelectTree( {
isOpen={ isOpen }
items={ linkedTree }
shouldShowCreateButton={ shouldShowCreateButton }
onEscape={ () => {
focusOnInput();
setIsOpen( false );
} }
onClose={ () => {
setIsOpen( false );
} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function useTreeItem( {
onLastItemLoop,
onFirstItemLoop,
onTreeBlur,
onEscape,
...props
}: TreeItemProps ) {
const nextLevel = level + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function useTree( {
onCreateNew,
shouldShowCreateButton,
onFirstItemLoop,
onEscape,
...props
}: TreeProps ) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const TreeItem = forwardRef( function ForwardedTreeItem(
</div>

{ Boolean( item.children.length ) && isExpanded && (
<Tree { ...treeProps } />
<Tree { ...treeProps } onEscape={ props.onEscape } />
) }
</li>
);
Expand Down

0 comments on commit f2a4db4

Please sign in to comment.