diff --git a/CHANGELOG.md b/CHANGELOG.md index ae7e2e71..02496675 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ ## [Unreleased] +### Changed +- Clicking empty area of file list focuses the list ([support#856]). + +[support#856]: https://github.com/pybricks/support/issues/856 + ## [2.0.0-rc.1] - 2022-12-09 ### Added diff --git a/src/explorer/Explorer.tsx b/src/explorer/Explorer.tsx index b453bb1b..abcbaf93 100644 --- a/src/explorer/Explorer.tsx +++ b/src/explorer/Explorer.tsx @@ -12,7 +12,13 @@ import { IconName, useHotkeys, } from '@blueprintjs/core'; -import React, { useCallback, useMemo, useState } from 'react'; +import React, { + MouseEventHandler, + useCallback, + useMemo, + useRef, + useState, +} from 'react'; import { useId } from 'react-aria'; import { ControlledTreeEnvironment, @@ -20,6 +26,7 @@ import { Tree, TreeItem, TreeItemIndex, + TreeRef, useTree, useTreeEnvironment, } from 'react-complex-tree'; @@ -383,6 +390,19 @@ const FileTree: React.VoidFunctionComponent = () => { const dispatch = useDispatch(); const i18n = useI18n(); + const treeRef = useRef(null); + + const handleMouseDown = useCallback( + (e) => { + e.preventDefault(); + e.stopPropagation(); + + // clicking the empty area of the tree should focus the tree + treeRef.current?.focusTree(); + }, + [treeRef], + ); + return ( {...renderers} @@ -399,11 +419,12 @@ const FileTree: React.VoidFunctionComponent = () => { ) } > -
+
diff --git a/src/explorer/explorer.scss b/src/explorer/explorer.scss index 0ce5148a..f150c603 100644 --- a/src/explorer/explorer.scss +++ b/src/explorer/explorer.scss @@ -15,6 +15,7 @@ } &-file-tree { + flex: 1 auto; overflow-y: auto; & .#{bp.$ns}-tree-node-list {