Add 'Esc' hotkey behavior on Filter and Sorts dropdown (#1622)

* fix esc key

* add changes

* add changes

* add changes
This commit is contained in:
neo773
2023-09-20 15:10:49 +05:30
committed by GitHub
parent 103fb701e7
commit d8590bb358
4 changed files with 18 additions and 2 deletions

View File

@ -3,6 +3,7 @@ import { Keys } from 'react-hotkeys-hook';
import { flip, offset, Placement, useFloating } from '@floating-ui/react';
import { HotkeyEffect } from '@/ui/utilities/hotkey/components/HotkeyEffect';
import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';
import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';
import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';
@ -19,7 +20,7 @@ type OwnProps = {
key: Keys;
scope: string;
};
dropdownHotkeyScope?: HotkeyScope;
dropdownHotkeyScope: HotkeyScope;
dropdownPlacement?: Placement;
onClickOutside?: () => void;
onClose?: () => void;
@ -67,6 +68,15 @@ export const DropdownButton = ({
dropdownHotkeyScope,
});
useScopedHotkeys(
'esc',
() => {
closeDropdownButton();
},
dropdownHotkeyScope.scope,
[closeDropdownButton],
);
return (
<div ref={containerRef}>
{hotkey && (