Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
tippy: Hide stream settings popover on pressing `escape`.
Aman Agrawalf171b436f329
diff --git a/static/js/click_handlers.js b/static/js/click_handlers.jsindex cd8409d1dcf..60cfeeff109 100644--- a/static/js/click_handlers.js+++ b/static/js/click_handlers.js@@ -920,7 +920,13 @@ export function initialize() {'.popover-inner, #user-profile-modal, .emoji-info-popover, .app-main [class^="column-"].expanded',).has(e.target).length === 0) {- popovers.hide_all();+ // Since tippy instance can handle outside clicks on their own,+ // we don't need to trigger them from here.+ // This fixes the bug of `hideAll` being called+ // after a tippy popover has been triggered which hides+ // the popover without being displayed.+ const not_hide_tippy_instances = true;+ popovers.hide_all(not_hide_tippy_instances);}if (compose_state.composing()) {diff --git a/static/js/popovers.js b/static/js/popovers.jsindex 98fd71ff6e7..fde69cfde90 100644--- a/static/js/popovers.js+++ b/static/js/popovers.js@@ -2,6 +2,7 @@ import ClipboardJS from "clipboard";import {add, formatISO, parseISO, set} from "date-fns";import ConfirmDatePlugin from "flatpickr/dist/plugins/confirmDate/confirmDate";import $ from "jquery";+import {hideAll} from "tippy.js";import render_actions_popover_content from "../templates/actions_popover_content.hbs";import render_mobile_message_buttons_popover from "../templates/mobile_message_buttons_popover.hbs";@@ -50,6 +51,7 @@ import * as settings_data from "./settings_data";import * as settings_profile_fields from "./settings_profile_fields";import * as stream_data from "./stream_data";import * as stream_popover from "./stream_popover";+import * as tippyjs from "./tippyjs";import * as user_groups from "./user_groups";import * as user_status from "./user_status";import * as user_status_ui from "./user_status_ui";@@ -1466,6 +1468,7 @@ export function any_active() {// True if any popover (that this module manages) is currently shown.// Expanded sidebars on mobile view count as popovers as well.return (+ tippyjs.is_left_sidebar_stream_setting_popover_displayed() ||actions_popped() ||user_sidebar_popped() ||stream_popover.stream_popped() ||@@ -1480,8 +1483,13 @@ export function any_active() {// This function will hide all true popovers (the streamlist and// userlist sidebars use the popover infrastructure, but doesn't work// like a popover structurally).-export function hide_all_except_sidebars() {+export function hide_all_except_sidebars(opts) {$(".has_popover").removeClass("has_popover has_actions_popover has_emoji_popover");+ if (!opts || !opts.not_hide_tippy_instances) {+ hideAll();+ } else if (opts.exclude_tippy_instance) {+ hideAll({exclude: opts.exclude_tippy_instance});+ }hide_actions_popover();hide_message_info_popover();emoji_picker.hide_emoji_popover();@@ -1506,10 +1514,13 @@ export function hide_all_except_sidebars() {// This function will hide all the popovers, including the mobile web// or narrow window sidebars.-export function hide_all() {+export function hide_all(not_hide_tippy_instances) {hide_userlist_sidebar();stream_popover.hide_streamlist_sidebar();- hide_all_except_sidebars();+ hide_all_except_sidebars({+ exclude_tippy_instance: undefined,+ not_hide_tippy_instances,+ });}export function set_userlist_placement(placement) {diff --git a/static/js/tippyjs.js b/static/js/tippyjs.jsindex 90c22e6385f..0075557c121 100644--- a/static/js/tippyjs.js+++ b/static/js/tippyjs.js@@ -39,6 +39,12 @@ tippy.setDefaultProps({// in the tag or a parameter.});+let left_sidebar_stream_setting_popover_displayed = false;++export function is_left_sidebar_stream_setting_popover_displayed() {+ return left_sidebar_stream_setting_popover_displayed;+}+export function initialize() {delegate("body", {// Add elements here which are not displayed on@@ -143,12 +149,13 @@ export function initialize() {delay: 0,target: "#streams_inline_cog",onShow(instance) {- popovers.hide_all_except_sidebars();+ popovers.hide_all_except_sidebars(instance);instance.setContent(render_left_sidebar_stream_setting_popover({can_create_streams: settings_data.user_can_create_streams(),}),);+ left_sidebar_stream_setting_popover_displayed = true;$(instance.popper).one("click", instance.hide);},appendTo: () => document.body,@@ -158,5 +165,8 @@ export function initialize() {hideOnClick: true,theme: "light-border",touch: true,+ onHidden() {+ left_sidebar_stream_setting_popover_displayed = false;+ },});}