Commit 0a2d7236 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'close-droplab-dropdowns-on-click' into 'master'

Close DropLab dropdowns on click instead of mousedown

See merge request gitlab-org/gitlab!56847
parents bd60d039 a4b411b0
...@@ -60,21 +60,24 @@ class DropLab { ...@@ -60,21 +60,24 @@ class DropLab {
addEvents() { addEvents() {
this.eventWrapper.documentClicked = this.documentClicked.bind(this); this.eventWrapper.documentClicked = this.documentClicked.bind(this);
document.addEventListener('mousedown', this.eventWrapper.documentClicked); document.addEventListener('click', this.eventWrapper.documentClicked);
} }
documentClicked(e) { documentClicked(e) {
let thisTag = e.target; if (e.defaultPrevented) return;
if (thisTag.tagName !== 'UL') thisTag = utils.closest(thisTag, 'UL'); if (utils.isDropDownParts(e.target)) return;
if (utils.isDropDownParts(thisTag, this.hooks)) return;
if (utils.isDropDownParts(e.target, this.hooks)) return; if (e.target.tagName !== 'UL') {
const closestUl = utils.closest(e.target, 'UL');
if (utils.isDropDownParts(closestUl)) return;
}
this.hooks.forEach((hook) => hook.list.hide()); this.hooks.forEach((hook) => hook.list.hide());
} }
removeEvents() { removeEvents() {
document.removeEventListener('mousedown', this.eventWrapper.documentClicked); document.removeEventListener('click', this.eventWrapper.documentClicked);
} }
changeHookList(trigger, list, plugins, config) { changeHookList(trigger, list, plugins, config) {
......
...@@ -18,6 +18,8 @@ class HookButton extends Hook { ...@@ -18,6 +18,8 @@ class HookButton extends Hook {
} }
clicked(e) { clicked(e) {
e.preventDefault();
const buttonEvent = new CustomEvent('click.dl', { const buttonEvent = new CustomEvent('click.dl', {
detail: { detail: {
hook: this, hook: this,
......
---
title: Close DropLab dropdowns on click instead of mousedown
merge_request: 56847
author: Simon Stieger @sim0
type: fixed
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment