mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: dropdowns should close on tab key (#4351)
This commit is contained in:
parent
1b55411919
commit
8cf4260219
@ -9,23 +9,25 @@ type TUseDropdownKeyDown = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const useDropdownKeyDown: TUseDropdownKeyDown = (onEnterKeyDown, onEscKeyDown, stopPropagation = true) => {
|
export const useDropdownKeyDown: TUseDropdownKeyDown = (onEnterKeyDown, onEscKeyDown, stopPropagation = true) => {
|
||||||
const stopEventPropagation = (event: React.KeyboardEvent<HTMLElement>) => {
|
const stopEventPropagation = useCallback(
|
||||||
if (stopPropagation) {
|
(event: React.KeyboardEvent<HTMLElement>) => {
|
||||||
event.stopPropagation();
|
if (stopPropagation) {
|
||||||
event.preventDefault();
|
event.stopPropagation();
|
||||||
}
|
event.preventDefault();
|
||||||
};
|
}
|
||||||
|
},
|
||||||
|
[stopPropagation]
|
||||||
|
);
|
||||||
|
|
||||||
const handleKeyDown = useCallback(
|
const handleKeyDown = useCallback(
|
||||||
(event: React.KeyboardEvent<HTMLElement>) => {
|
(event: React.KeyboardEvent<HTMLElement>) => {
|
||||||
if (event.key === "Enter") {
|
if (event.key === "Enter") {
|
||||||
stopEventPropagation(event);
|
stopEventPropagation(event);
|
||||||
|
|
||||||
onEnterKeyDown();
|
onEnterKeyDown();
|
||||||
} else if (event.key === "Escape") {
|
} else if (event.key === "Escape") {
|
||||||
stopEventPropagation(event);
|
stopEventPropagation(event);
|
||||||
onEscKeyDown();
|
onEscKeyDown();
|
||||||
}
|
} else if (event.key === "Tab") onEscKeyDown();
|
||||||
},
|
},
|
||||||
[onEnterKeyDown, onEscKeyDown, stopEventPropagation]
|
[onEnterKeyDown, onEscKeyDown, stopEventPropagation]
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user