Add 'Esc' hotkey behavior on Filter and Sorts dropdown (#1622)
* fix esc key * add changes * add changes * add changes
This commit is contained in:
@ -3,6 +3,7 @@ import { Keys } from 'react-hotkeys-hook';
|
|||||||
import { flip, offset, Placement, useFloating } from '@floating-ui/react';
|
import { flip, offset, Placement, useFloating } from '@floating-ui/react';
|
||||||
|
|
||||||
import { HotkeyEffect } from '@/ui/utilities/hotkey/components/HotkeyEffect';
|
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 { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';
|
||||||
import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';
|
import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ type OwnProps = {
|
|||||||
key: Keys;
|
key: Keys;
|
||||||
scope: string;
|
scope: string;
|
||||||
};
|
};
|
||||||
dropdownHotkeyScope?: HotkeyScope;
|
dropdownHotkeyScope: HotkeyScope;
|
||||||
dropdownPlacement?: Placement;
|
dropdownPlacement?: Placement;
|
||||||
onClickOutside?: () => void;
|
onClickOutside?: () => void;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
@ -67,6 +68,15 @@ export const DropdownButton = ({
|
|||||||
dropdownHotkeyScope,
|
dropdownHotkeyScope,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useScopedHotkeys(
|
||||||
|
'esc',
|
||||||
|
() => {
|
||||||
|
closeDropdownButton();
|
||||||
|
},
|
||||||
|
dropdownHotkeyScope.scope,
|
||||||
|
[closeDropdownButton],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={containerRef}>
|
<div ref={containerRef}>
|
||||||
{hotkey && (
|
{hotkey && (
|
||||||
|
|||||||
@ -85,6 +85,10 @@ export const SortDropdownButton = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleDropdownButtonClose = () => {
|
||||||
|
resetState();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownButton
|
<DropdownButton
|
||||||
dropdownId={SortDropdownId}
|
dropdownId={SortDropdownId}
|
||||||
@ -135,6 +139,7 @@ export const SortDropdownButton = ({
|
|||||||
)}
|
)}
|
||||||
</StyledDropdownMenu>
|
</StyledDropdownMenu>
|
||||||
}
|
}
|
||||||
|
onClose={handleDropdownButtonClose}
|
||||||
></DropdownButton>
|
></DropdownButton>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -43,7 +43,7 @@ export const ViewBar = ({
|
|||||||
hotkeyScope={{ scope: FiltersHotkeyScope.FilterDropdownButton }}
|
hotkeyScope={{ scope: FiltersHotkeyScope.FilterDropdownButton }}
|
||||||
/>
|
/>
|
||||||
<SortDropdownButton
|
<SortDropdownButton
|
||||||
hotkeyScope={{ scope: FiltersHotkeyScope.FilterDropdownButton }}
|
hotkeyScope={{ scope: FiltersHotkeyScope.SortDropdownButton }}
|
||||||
isPrimaryButton
|
isPrimaryButton
|
||||||
/>
|
/>
|
||||||
{optionsDropdownButton}
|
{optionsDropdownButton}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
export enum FiltersHotkeyScope {
|
export enum FiltersHotkeyScope {
|
||||||
FilterDropdownButton = 'filter-dropdown-button',
|
FilterDropdownButton = 'filter-dropdown-button',
|
||||||
|
SortDropdownButton = 'sort-dropdown-button',
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user