Skip to content

Commit

Permalink
Trigger tooltip option on pointer up (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
alistairjcbrown authored Aug 23, 2023
1 parent 11e8e10 commit 20a6aed
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 49 deletions.
36 changes: 26 additions & 10 deletions dist/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 26 additions & 10 deletions dist/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 25 additions & 9 deletions src/UI/controllers/HTMLTooltipUIController.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class HTMLTooltipUIController extends UIController {
this._options = options
this._htmlTooltipOptions = Object.assign({}, defaultOptions, htmlTooltipOptions)
window.addEventListener('pointerdown', this, true)
window.addEventListener('pointerup', this, true)
}

_activeInput;
Expand All @@ -57,6 +58,7 @@ export class HTMLTooltipUIController extends UIController {
destroy () {
this.removeTooltip()
window.removeEventListener('pointerdown', this, true)
window.removeEventListener('pointerup', this, true)
}

/**
Expand Down Expand Up @@ -197,6 +199,10 @@ export class HTMLTooltipUIController extends UIController {
this._pointerDownListener(event)
break
}
case 'pointerup': {
this._pointerUpListener(event)
break
}
}
}

Expand All @@ -206,6 +212,24 @@ export class HTMLTooltipUIController extends UIController {
// Ignore events on the Dax icon, we handle those elsewhere
if (isEventWithinDax(e, e.target)) return

// @ts-ignore
if (e.target.nodeName === 'DDG-AUTOFILL') {
e.preventDefault()
e.stopImmediatePropagation()
// Ignore pointer down events, we'll handle them on pointer up
} else {
this.removeTooltip().catch(e => {
console.error('error removing tooltip', e)
})
}
}

// Global listener for event delegation
_pointerUpListener (e) {
if (!e.isTrusted) return
// Ignore events on the Dax icon, we handle those elsewhere
if (isEventWithinDax(e, e.target)) return

// @ts-ignore
if (e.target.nodeName === 'DDG-AUTOFILL') {
e.preventDefault()
Expand All @@ -215,15 +239,7 @@ export class HTMLTooltipUIController extends UIController {
if (!isMainMouseButton) return

const activeTooltip = this.getActiveTooltip()
if (!activeTooltip) {
console.warn('Could not get activeTooltip')
} else {
activeTooltip.dispatchClick()
}
} else {
this.removeTooltip().catch(e => {
console.error('error removing tooltip', e)
})
activeTooltip?.dispatchClick()
}
}

Expand Down
36 changes: 26 additions & 10 deletions swift-package/Resources/assets/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 26 additions & 10 deletions swift-package/Resources/assets/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 20a6aed

Please sign in to comment.