Fix split-menu-button dropmarker triggering the button click event

Regression in fa31956d
This commit is contained in:
Adomas Venčkauskas 2023-07-25 14:22:57 +03:00
parent 630c6d0d97
commit d96afa4499

View file

@ -41,10 +41,8 @@
// Pointer events don't reach the button's children, so check mousedown positions manually and open // Pointer events don't reach the button's children, so check mousedown positions manually and open
// the popup if over the end side of the button // the popup if over the end side of the button
this.addEventListener('mousedown', (event) => { this.addEventListener('mousedown', (event) => {
let rect = this.querySelector('[anonid="dropmarker-box"]').getBoundingClientRect(); if (this._isEventInDropmarkerBox(event)) {
if ((!Zotero.rtl && event.clientX >= rect.left || Zotero.rtl && event.clientX <= rect.right) Zotero.Utilities.Internal.showNativeElementPopup(this);
&& Zotero.Utilities.Internal.showNativeElementPopup(this)) {
event.preventDefault();
} }
}); });
@ -57,6 +55,20 @@
connectedCallback() { connectedCallback() {
this.append(this.constructor.contentFragment); this.append(this.constructor.contentFragment);
// Prevent DOM-attached mouse handlers from running in the dropmarker area
for (const eventType of ['mousedown', 'mouseup', 'click']) {
const handler = this.getAttribute('on' + eventType);
if (!handler) {
continue;
}
this['on' + eventType] = null;
this.addEventListener(eventType, (event) => {
if (!this._isEventInDropmarkerBox(event)) {
eval(handler).bind(this);
}
});
}
} }
get image() { get image() {
@ -94,6 +106,11 @@
Object.defineProperty(this, "dropmarkerFragment", { value: frag }); Object.defineProperty(this, "dropmarkerFragment", { value: frag });
return frag; return frag;
} }
_isEventInDropmarkerBox(event) {
let rect = this.querySelector('[anonid="dropmarker-box"]').getBoundingClientRect();
return !Zotero.rtl && event.clientX >= rect.left || Zotero.rtl && event.clientX <= rect.right
}
} }
customElements.define("split-menu-button", SplitMenuButton, { customElements.define("split-menu-button", SplitMenuButton, {