Limit event scope

updated-RP^2
David Disu 3 years ago committed by yann300
parent 0a06ddb3c4
commit f40b80927f
  1. 19
      libs/remix-ui/workspace/src/lib/components/file-explorer.tsx
  2. 1
      libs/remix-ui/workspace/src/lib/css/file-explorer.css

@ -1,4 +1,4 @@
import React, { useEffect, useState, useContext, SyntheticEvent } from 'react' // eslint-disable-line import React, { useEffect, useState, useRef, SyntheticEvent } from 'react' // eslint-disable-line
import { TreeView, TreeViewItem } from '@remix-ui/tree-view' // eslint-disable-line import { TreeView, TreeViewItem } from '@remix-ui/tree-view' // eslint-disable-line
import { FileExplorerMenu } from './file-explorer-menu' // eslint-disable-line import { FileExplorerMenu } from './file-explorer-menu' // eslint-disable-line
import { FileExplorerContextMenu } from './file-explorer-context-menu' // eslint-disable-line import { FileExplorerContextMenu } from './file-explorer-context-menu' // eslint-disable-line
@ -35,6 +35,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
copyElement: [] copyElement: []
}) })
const [canPaste, setCanPaste] = useState(false) const [canPaste, setCanPaste] = useState(false)
const treeRef = useRef<HTMLDivElement>(null)
useEffect(() => { useEffect(() => {
if (contextMenuItems) { if (contextMenuItems) {
@ -57,6 +58,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
}, [props.focusEdit]) }, [props.focusEdit])
useEffect(() => { useEffect(() => {
if (treeRef.current) {
const keyPressHandler = (e: KeyboardEvent) => { const keyPressHandler = (e: KeyboardEvent) => {
if (e.shiftKey) { if (e.shiftKey) {
setState(prevState => { setState(prevState => {
@ -72,14 +74,17 @@ export const FileExplorer = (props: FileExplorerProps) => {
}) })
} }
} }
const targetDocument = treeRef.current
document.addEventListener('keydown', keyPressHandler) targetDocument.addEventListener('keydown', keyPressHandler)
document.addEventListener('keyup', keyUpHandler) targetDocument.addEventListener('keyup', keyUpHandler)
targetDocument.focus()
return () => { return () => {
document.removeEventListener('keydown', keyPressHandler) targetDocument.removeEventListener('keydown', keyPressHandler)
document.removeEventListener('keyup', keyUpHandler) targetDocument.removeEventListener('keyup', keyUpHandler)
} }
}, []) }
}, [treeRef.current])
useEffect(() => { useEffect(() => {
if (canPaste) { if (canPaste) {
@ -406,7 +411,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
} }
return ( return (
<div> <div ref={treeRef} tabIndex={0} style={{ outline: "none" }}>
<TreeView id='treeView'> <TreeView id='treeView'>
<TreeViewItem id="treeViewItem" <TreeViewItem id="treeViewItem"
controlBehaviour={true} controlBehaviour={true}

@ -1,5 +1,6 @@
.remixui_label { .remixui_label {
margin-top : 4px; margin-top : 4px;
user-select: none;
} }
.remixui_leaf { .remixui_leaf {
overflow : hidden; overflow : hidden;

Loading…
Cancel
Save