(core) Disable mousedown on token delete button

Summary:
This change prevents dragging tokens when the cursor is over the
delete button. Now, trying to drag after mousedown over the delete
button will do nothing if the cursor is released outside the delete
button, and will delete if the cursor is released inside the delete
button.

Test Plan: Tested manually.

Reviewers: alexmojaki

Reviewed By: alexmojaki

Differential Revision: https://phab.getgrist.com/D3024
This commit is contained in:
George Gevoian 2021-09-16 09:56:07 -07:00
parent d5a7fb23fe
commit e5ebc4668c

View File

@ -126,7 +126,12 @@ export class TokenField<Token extends IToken = IToken> extends Disposable {
cssToken(this._options.renderToken(t.token),
dom.cls('selected', (use) => use(this._selection).has(t)),
_options.readonly ? null : [
cssDeleteButton(cssDeleteIcon('CrossSmall'), testId('tokenfield-delete')),
cssDeleteButton(
// Ignore mousedown events, so that tokens aren't draggable by the delete button.
dom.on('mousedown', (ev) => ev.stopPropagation()),
cssDeleteIcon('CrossSmall'),
testId('tokenfield-delete')
),
dom.on('click', (ev) => this._onTokenClick(ev, t)),
dom.on('mousedown', (ev) => this._onMouseDown(ev, t))
],