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