Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backspace on key functionality for deleting of multiple cells #408

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions client/components/Controllers/Table/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import TableEditor from '../../Editors/Table'
import { useStore } from './store'
import * as React from 'react'
import { useKeyPress } from 'ahooks'

export default function Editor() {
const schema = useStore((state) => state.record?.resource.schema)
Expand All @@ -16,12 +17,10 @@ export default function Editor() {

const [cellSelection, setCellSelection] = React.useState({})

const onKeyDown = React.useCallback(
(event: { key: any }) => {
if (event.key === 'Delete') deleteMultipleCells(cellSelection)
},
[cellSelection]
)
// works automatically, doesnt need to be passed to <TableEditor with onKeyPress
useKeyPress(['delete', 'backspace'], () => {
deleteMultipleCells(cellSelection)
})

if (!schema) return null
if (!report) return null
Expand All @@ -37,7 +36,6 @@ export default function Editor() {
onEditComplete={saveEditing}
onEditStop={stopEditing}
handle={(gridRef) => updateState({ gridRef })}
onKeyDown={onKeyDown}
defaultCellSelection={cellSelection}
onCellSelectionChange={setCellSelection}
/>
Expand Down
Loading