UX: Do not close login modal and search menu on outside mouse up event. (#7366)

This commit is contained in:
Bianca Nenciu 2019-04-23 06:01:44 +03:00 committed by Sam
parent 9050b1bf5a
commit 58fe45ffd9
4 changed files with 30 additions and 2 deletions

View File

@ -73,7 +73,7 @@ export default Ember.Component.extend({
$("html").off("keydown.discourse-modal"); $("html").off("keydown.discourse-modal");
}, },
click(e) { mouseDown(e) {
if (!this.get("dismissable")) { if (!this.get("dismissable")) {
return; return;
} }

View File

@ -2,6 +2,8 @@
const CLICK_ATTRIBUTE_NAME = "_discourse_click_widget"; const CLICK_ATTRIBUTE_NAME = "_discourse_click_widget";
const CLICK_OUTSIDE_ATTRIBUTE_NAME = "_discourse_click_outside_widget"; const CLICK_OUTSIDE_ATTRIBUTE_NAME = "_discourse_click_outside_widget";
const MOUSE_DOWN_OUTSIDE_ATTRIBUTE_NAME =
"_discourse_mouse_down_outside_widget";
const KEY_UP_ATTRIBUTE_NAME = "_discourse_key_up_widget"; const KEY_UP_ATTRIBUTE_NAME = "_discourse_key_up_widget";
const KEY_DOWN_ATTRIBUTE_NAME = "_discourse_key_down_widget"; const KEY_DOWN_ATTRIBUTE_NAME = "_discourse_key_down_widget";
const DRAG_ATTRIBUTE_NAME = "_discourse_drag_widget"; const DRAG_ATTRIBUTE_NAME = "_discourse_drag_widget";
@ -33,6 +35,10 @@ export const WidgetClickOutsideHook = buildHook(
CLICK_OUTSIDE_ATTRIBUTE_NAME, CLICK_OUTSIDE_ATTRIBUTE_NAME,
"data-click-outside" "data-click-outside"
); );
export const WidgetMouseDownOutsideHook = buildHook(
MOUSE_DOWN_OUTSIDE_ATTRIBUTE_NAME,
"data-mouse-down-outside"
);
export const WidgetKeyUpHook = buildHook(KEY_UP_ATTRIBUTE_NAME); export const WidgetKeyUpHook = buildHook(KEY_UP_ATTRIBUTE_NAME);
export const WidgetKeyDownHook = buildHook(KEY_DOWN_ATTRIBUTE_NAME); export const WidgetKeyDownHook = buildHook(KEY_DOWN_ATTRIBUTE_NAME);
export const WidgetDragHook = buildHook(DRAG_ATTRIBUTE_NAME); export const WidgetDragHook = buildHook(DRAG_ATTRIBUTE_NAME);
@ -136,6 +142,20 @@ WidgetClickHook.setupDocumentCallback = function() {
}); });
}); });
$(document).on("mousedown.discourse-widget", e => {
let node = e.target;
const $outside = $("[data-mouse-down-outside]");
$outside.each((i, outNode) => {
if (outNode.contains(node)) {
return;
}
const widget2 = outNode[MOUSE_DOWN_OUTSIDE_ATTRIBUTE_NAME];
if (widget2) {
widget2.mouseDownOutside(e);
}
});
});
$(document).on("keyup.discourse-widget", e => { $(document).on("keyup.discourse-widget", e => {
nodeCallback(e.target, KEY_UP_ATTRIBUTE_NAME, w => w.keyUp(e)); nodeCallback(e.target, KEY_UP_ATTRIBUTE_NAME, w => w.keyUp(e));
}); });

View File

@ -199,7 +199,7 @@ export default createWidget("search-menu", {
}); });
}, },
clickOutside() { mouseDownOutside() {
this.sendWidgetAction("toggleSearchMenu"); this.sendWidgetAction("toggleSearchMenu");
}, },

View File

@ -3,6 +3,7 @@ import {
WidgetClickOutsideHook, WidgetClickOutsideHook,
WidgetKeyUpHook, WidgetKeyUpHook,
WidgetKeyDownHook, WidgetKeyDownHook,
WidgetMouseDownOutsideHook,
WidgetDragHook WidgetDragHook
} from "discourse/widgets/hooks"; } from "discourse/widgets/hooks";
import { h } from "virtual-dom"; import { h } from "virtual-dom";
@ -84,6 +85,13 @@ function drawWidget(builder, attrs, state) {
if (this.click) { if (this.click) {
properties["widget-click"] = new WidgetClickHook(this); properties["widget-click"] = new WidgetClickHook(this);
} }
if (this.mouseDownOutside) {
properties["widget-mouse-down-outside"] = new WidgetMouseDownOutsideHook(
this
);
}
if (this.drag) { if (this.drag) {
properties["widget-drag"] = new WidgetDragHook(this); properties["widget-drag"] = new WidgetDragHook(this);
} }