Skip to content

Commit

Permalink
fix reset table row selection when clicking outside
Browse files Browse the repository at this point in the history
  • Loading branch information
bosiraphael committed Oct 18, 2024
1 parent 43efae4 commit 118a593
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const ActionMenuDropdown = () => {
return (
<StyledContainerActionMenuDropdown
position={actionMenuDropdownPosition}
className="context-menu"
className="action-menu-dropdown"
>
<Dropdown
dropdownId={`action-menu-dropdown-${actionMenuId}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const RecordBoard = () => {

useListenClickOutsideByClassName({
classNames: ['record-board-card'],
excludeClassNames: ['bottom-bar', 'context-menu'],
excludeClassNames: ['bottom-bar', 'action-menu-dropdown'],
callback: resetRecordSelection,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { useRecordTable } from '@/object-record/record-table/hooks/useRecordTabl
import { TableHotkeyScope } from '@/object-record/record-table/types/TableHotkeyScope';
import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';
import { useClickOutsideListener } from '@/ui/utilities/pointer-event/hooks/useClickOutsideListener';
import {
ClickOutsideMode,
useListenClickOutsideByClassName,
} from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';
import { useListenClickOutsideByClassName } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';

type RecordTableInternalEffectProps = {
recordTableId: string;
Expand All @@ -28,14 +25,6 @@ export const RecordTableInternalEffect = ({
SOFT_FOCUS_CLICK_OUTSIDE_LISTENER_ID,
);

useListenClickOutside({
refs: [tableBodyRef],
callback: () => {
leaveTableFocus();
},
mode: ClickOutsideMode.compareHTMLRef,
});

useScopedHotkeys(
[Key.Escape],
() => {
Expand All @@ -46,9 +35,10 @@ export const RecordTableInternalEffect = ({

useListenClickOutsideByClassName({
classNames: ['entity-table-cell'],
excludeClassNames: ['bottom-bar', 'context-menu'],
excludeClassNames: ['bottom-bar', 'action-menu-dropdown'],
callback: () => {
resetTableRowSelection();
console.log('click outside');
leaveTableFocus();
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotV

import { TableHotkeyScope } from '../../types/TableHotkeyScope';

import { useResetTableRowSelection } from '@/object-record/record-table/hooks/internal/useResetTableRowSelection';
import { useCloseCurrentTableCellInEditMode } from './useCloseCurrentTableCellInEditMode';
import { useDisableSoftFocus } from './useDisableSoftFocus';

Expand All @@ -16,6 +17,8 @@ export const useLeaveTableFocus = (recordTableId?: string) => {

const { isSoftFocusActiveState } = useRecordTableStates(recordTableId);

const resetTableRowSelection = useResetTableRowSelection(recordTableId);

return useRecoilCallback(
({ snapshot }) =>
() => {
Expand All @@ -28,6 +31,8 @@ export const useLeaveTableFocus = (recordTableId?: string) => {
.getLoadable(currentHotkeyScopeState)
.getValue();

resetTableRowSelection();

if (!isSoftFocusActive) {
return;
}
Expand All @@ -39,6 +44,11 @@ export const useLeaveTableFocus = (recordTableId?: string) => {
closeCurrentCellInEditMode();
disableSoftFocus();
},
[closeCurrentCellInEditMode, disableSoftFocus, isSoftFocusActiveState],
[
closeCurrentCellInEditMode,
disableSoftFocus,
isSoftFocusActiveState,
resetTableRowSelection,
],
);
};

0 comments on commit 118a593

Please sign in to comment.