fix: prevent scroll to softfocus cell when hover (#3990)
This commit is contained in:
@ -5,6 +5,7 @@ import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata'
|
||||
import { useGetIsSomeCellInEditModeState } from '@/object-record/record-table/hooks/internal/useGetIsSomeCellInEditMode';
|
||||
import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates';
|
||||
import { useRecordTableMoveFocus } from '@/object-record/record-table/hooks/useRecordTableMoveFocus';
|
||||
import { isSoftFocusUsingMouseState } from '@/object-record/record-table/states/isSoftFocusUsingMouseState';
|
||||
import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';
|
||||
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
|
||||
import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotValue';
|
||||
@ -126,6 +127,10 @@ export const useRecordTable = (props?: useRecordTableProps) => {
|
||||
const disableSoftFocus = useDisableSoftFocus(recordTableId);
|
||||
const setHotkeyScope = useSetHotkeyScope();
|
||||
|
||||
const setIsSoftFocusUsingMouseState = useSetRecoilState(
|
||||
isSoftFocusUsingMouseState,
|
||||
);
|
||||
|
||||
useScopedHotkeys(
|
||||
[Key.ArrowUp, `${Key.Shift}+${Key.Enter}`],
|
||||
() => {
|
||||
@ -148,6 +153,7 @@ export const useRecordTable = (props?: useRecordTableProps) => {
|
||||
[Key.ArrowLeft, `${Key.Shift}+${Key.Tab}`],
|
||||
() => {
|
||||
moveLeft();
|
||||
setIsSoftFocusUsingMouseState(false);
|
||||
},
|
||||
TableHotkeyScope.TableSoftFocus,
|
||||
[moveLeft],
|
||||
@ -157,6 +163,7 @@ export const useRecordTable = (props?: useRecordTableProps) => {
|
||||
[Key.ArrowRight, Key.Tab],
|
||||
() => {
|
||||
moveRight();
|
||||
setIsSoftFocusUsingMouseState(false);
|
||||
},
|
||||
TableHotkeyScope.TableSoftFocus,
|
||||
[moveRight],
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { ReactElement, useContext, useState } from 'react';
|
||||
import styled from '@emotion/styled';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
|
||||
import { useGetButtonIcon } from '@/object-record/record-field/hooks/useGetButtonIcon';
|
||||
import { useIsFieldEmpty } from '@/object-record/record-field/hooks/useIsFieldEmpty';
|
||||
@ -8,6 +8,7 @@ import { useIsFieldInputOnly } from '@/object-record/record-field/hooks/useIsFie
|
||||
import { RecordTableCellContext } from '@/object-record/record-table/contexts/RecordTableCellContext';
|
||||
import { useGetIsSomeCellInEditModeState } from '@/object-record/record-table/hooks/internal/useGetIsSomeCellInEditMode';
|
||||
import { useOpenRecordTableCell } from '@/object-record/record-table/record-table-cell/hooks/useOpenRecordTableCell';
|
||||
import { isSoftFocusUsingMouseState } from '@/object-record/record-table/states/isSoftFocusUsingMouseState';
|
||||
import { IconArrowUpRight } from '@/ui/display/icon';
|
||||
import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';
|
||||
|
||||
@ -62,6 +63,10 @@ export const RecordTableCellContainer = ({
|
||||
const isSomeCellInEditModeState = useGetIsSomeCellInEditModeState();
|
||||
const isSomeCellInEditMode = useRecoilValue(isSomeCellInEditModeState());
|
||||
|
||||
const setIsSoftFocusUsingMouseState = useSetRecoilState(
|
||||
isSoftFocusUsingMouseState,
|
||||
);
|
||||
|
||||
const moveSoftFocusToCurrentCellOnHover =
|
||||
useMoveSoftFocusToCurrentCellOnHover();
|
||||
|
||||
@ -79,6 +84,7 @@ export const RecordTableCellContainer = ({
|
||||
if (!isHovered && !isSomeCellInEditMode) {
|
||||
setIsHovered(true);
|
||||
moveSoftFocusToCurrentCellOnHover();
|
||||
setIsSoftFocusUsingMouseState(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import { PropsWithChildren, useEffect, useRef } from 'react';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { Key } from 'ts-key-enum';
|
||||
|
||||
import { useIsFieldInputOnly } from '@/object-record/record-field/hooks/useIsFieldInputOnly';
|
||||
import { useToggleEditOnlyInput } from '@/object-record/record-field/hooks/useToggleEditOnlyInput';
|
||||
import { useOpenRecordTableCell } from '@/object-record/record-table/record-table-cell/hooks/useOpenRecordTableCell';
|
||||
import { isSoftFocusUsingMouseState } from '@/object-record/record-table/states/isSoftFocusUsingMouseState';
|
||||
import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';
|
||||
import { isNonTextWritingKey } from '@/ui/utilities/hotkey/utils/isNonTextWritingKey';
|
||||
|
||||
@ -22,9 +24,13 @@ export const RecordTableCellSoftFocusMode = ({
|
||||
const toggleEditOnlyInput = useToggleEditOnlyInput();
|
||||
const scrollRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const isSoftFocusUsingMouse = useRecoilValue(isSoftFocusUsingMouseState);
|
||||
|
||||
useEffect(() => {
|
||||
scrollRef.current?.scrollIntoView({ block: 'nearest' });
|
||||
}, []);
|
||||
if (!isSoftFocusUsingMouse) {
|
||||
scrollRef.current?.scrollIntoView({ block: 'nearest' });
|
||||
}
|
||||
}, [isSoftFocusUsingMouse]);
|
||||
|
||||
useScopedHotkeys(
|
||||
[Key.Backspace, Key.Delete],
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
import { atom } from 'recoil';
|
||||
|
||||
export const isSoftFocusUsingMouseState = atom({
|
||||
key: 'isSoftFocusUsingMouseState',
|
||||
default: false,
|
||||
});
|
||||
Reference in New Issue
Block a user