Files
twenty/front/src/modules/ui/table/editable-cell/components/EditableCellSoftFocusMode.tsx
T
Lucas BordeauandGitHub 62720944fa Feat/open input not focus (#811)
* Fixed click outside

* Finished

* Fixed tests
2023-07-21 22:09:02 -07:00

60 lines
1.3 KiB
TypeScript

import { PropsWithChildren } from 'react';
import { useScopedHotkeys } from '@/ui/hotkey/hooks/useScopedHotkeys';
import { isNonTextWritingKey } from '@/ui/hotkey/utils/isNonTextWritingKey';
import { TableHotkeyScope } from '../../types/TableHotkeyScope';
import { useEditableCell } from '../hooks/useEditableCell';
import { EditableCellDisplayContainer } from './EditableCellContainer';
type OwnProps = PropsWithChildren<unknown>;
export function EditableCellSoftFocusMode({ children }: OwnProps) {
const { openEditableCell } = useEditableCell();
function openEditMode() {
openEditableCell();
}
useScopedHotkeys(
'enter',
() => {
openEditMode();
},
TableHotkeyScope.TableSoftFocus,
[openEditMode],
);
useScopedHotkeys(
'*',
(keyboardEvent) => {
const isWritingText =
!isNonTextWritingKey(keyboardEvent.key) &&
!keyboardEvent.ctrlKey &&
!keyboardEvent.metaKey;
if (!isWritingText) {
return;
}
openEditMode();
},
TableHotkeyScope.TableSoftFocus,
[openEditMode],
{
preventDefault: false,
},
);
function handleClick() {
openEditMode();
}
return (
<EditableCellDisplayContainer onClick={handleClick} softFocus>
{children}
</EditableCellDisplayContainer>
);
}