Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

compose: Fix numeric typing regression related to global time widget.

YashRE42bea41e975dbd
diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js
index 6f03bc5f58a..eff9c2c35d6 100644
--- a/static/js/composebox_typeahead.js
+++ b/static/js/composebox_typeahead.js
@@ -768,6 +768,10 @@ export function content_highlighter(item) {
}
}
+function is_numeric_key(key) {
+ return ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"].includes(key);
+}
+
export function show_flatpickr(element, callback, default_timestamp, options = {}) {
const flatpickr_input = $("<input id='#timestamp_flatpickr'>");
@@ -788,8 +792,18 @@ export function show_flatpickr(element, callback, default_timestamp, options = {
formatDate: (date) => formatISO(date),
disableMobile: true,
onKeyDown: (selectedDates, dateStr, instance, event) => {
+ if (is_numeric_key(event.key)) {
+ // Don't stopPropagation for numeric inputs, let them be handled normally
+ return;
+ }
+
const hotkey = get_keydown_hotkey(event);
+ if (hotkey === "backspace" || hotkey === "delete") {
+ // Don't stopPropagation for backspace or delete, let them be handled normally
+ return;
+ }
+
if (["tab", "shift_tab"].includes(hotkey.name)) {
const elems = [
instance.selectedDateElem,
@@ -815,12 +829,20 @@ export function show_flatpickr(element, callback, default_timestamp, options = {
const container = $($(instance.innerContainer).parent());
container.on("keydown", (e) => {
+ if (is_numeric_key(e.key)) {
+ return true; // Let users type numeric values
+ }
+
const hotkey = get_keydown_hotkey(e);
if (!hotkey) {
return false;
}
+ if (hotkey.name === "backspace" || hotkey.name === "delete") {
+ return true; // Let backspace or delete be handled normally
+ }
+
if (hotkey.name === "enter") {
if (e.target.classList[0] === "flatpickr-day") {
return true; // use flatpickr default implementation