mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 19:31:58 +00:00
flatpickr: Cut dependency on hotkey.js.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
575f51ed08
commit
f959dbe867
@@ -2,7 +2,6 @@ import {formatISO} from "date-fns";
|
|||||||
import ConfirmDatePlugin from "flatpickr/dist/plugins/confirmDate/confirmDate";
|
import ConfirmDatePlugin from "flatpickr/dist/plugins/confirmDate/confirmDate";
|
||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
|
|
||||||
import {get_keydown_hotkey} from "./hotkey";
|
|
||||||
import {$t} from "./i18n";
|
import {$t} from "./i18n";
|
||||||
import {user_settings} from "./user_settings";
|
import {user_settings} from "./user_settings";
|
||||||
|
|
||||||
@@ -40,9 +39,7 @@ export function show_flatpickr(element, callback, default_timestamp, options = {
|
|||||||
// onKeyDown function, and the below keydown handler are
|
// onKeyDown function, and the below keydown handler are
|
||||||
// used, but it's not at all clear in what order they are
|
// used, but it's not at all clear in what order they are
|
||||||
// called, or what the overall control flow is.
|
// called, or what the overall control flow is.
|
||||||
const hotkey = get_keydown_hotkey(event);
|
if (event.key === "Tab") {
|
||||||
|
|
||||||
if (hotkey && ["tab", "shift_tab"].includes(hotkey.name)) {
|
|
||||||
// Ensure that tab/shift_tab navigation work to
|
// Ensure that tab/shift_tab navigation work to
|
||||||
// navigate between the elements in flatpickr itself
|
// navigate between the elements in flatpickr itself
|
||||||
// and the confirmation button at the bottom of the
|
// and the confirmation button at the bottom of the
|
||||||
@@ -82,18 +79,12 @@ export function show_flatpickr(element, callback, default_timestamp, options = {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const hotkey = get_keydown_hotkey(e);
|
if (e.key === "Backspace" || e.key === "Delete") {
|
||||||
|
|
||||||
if (!hotkey) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hotkey.name === "backspace" || hotkey.name === "delete") {
|
|
||||||
// Let backspace or delete be handled normally
|
// Let backspace or delete be handled normally
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hotkey.name === "enter") {
|
if (e.key === "Enter") {
|
||||||
if (e.target.classList[0] === "flatpickr-day") {
|
if (e.target.classList[0] === "flatpickr-day") {
|
||||||
// use flatpickr's built-in behavior to choose the selected day.
|
// use flatpickr's built-in behavior to choose the selected day.
|
||||||
return true;
|
return true;
|
||||||
@@ -102,18 +93,18 @@ export function show_flatpickr(element, callback, default_timestamp, options = {
|
|||||||
$container.find(".flatpickr-confirm").trigger("click");
|
$container.find(".flatpickr-confirm").trigger("click");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hotkey.name === "escape") {
|
if (e.key === "Escape") {
|
||||||
$(element).toggleClass("has_popover");
|
$(element).toggleClass("has_popover");
|
||||||
instance.close();
|
instance.close();
|
||||||
instance.destroy();
|
instance.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (["tab", "shift_tab"].includes(hotkey.name)) {
|
if (e.key === "Tab") {
|
||||||
// Use flatpickr's built-in navigation between elements.
|
// Use flatpickr's built-in navigation between elements.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (["right_arrow", "up_arrow", "left_arrow", "down_arrow"].includes(hotkey.name)) {
|
if (["ArrowLeft", "ArrowUp", "ArrowRight", "ArrowDown"].includes(e.key)) {
|
||||||
// use flatpickr's built-in navigation of the date grid.
|
// use flatpickr's built-in navigation of the date grid.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user