Flash tooltip text when tapping undo/redo toolbar buttons and disabled operation buttons on touch devices (re: #7699)

This commit is contained in:
Quincy Morgan
2020-06-12 12:48:16 -04:00
parent b40aeaaeab
commit 1e68917e2a
2 changed files with 78 additions and 21 deletions
+24 -3
View File
@@ -81,6 +81,8 @@ export function uiEditMenu(context) {
.style('width', _buttonWidth + 'px')
.style('height', _buttonHeight + 'px')
.on('click', click)
// don't listen for `mouseup` because we only care about non-mouse pointer types
.on('pointerup', pointerup)
.on('pointerdown mousedown', pointerdown);
var tooltipSide = tooltipPosition(viewport, menuLeft);
@@ -101,11 +103,30 @@ export function uiEditMenu(context) {
.merge(buttons)
.classed('disabled', function(d) { return d.disabled(); });
var lastPointerUpType;
// `pointerup` is always called before `click`
function pointerup() {
lastPointerUpType = d3_event.pointerType;
}
function click(operation) {
d3_event.stopPropagation();
if (operation.disabled()) return;
operation();
editMenu.close();
if (operation.disabled()) {
if (lastPointerUpType === 'touch' ||
lastPointerUpType === 'pen') {
// there are no tooltips for touch interactions so flash feedback instead
context.ui().flash
.duration(4000)
.iconName('#iD-operation-' + operation.id)
.iconClass('operation disabled')
.text(operation.tooltip)();
}
} else {
operation();
editMenu.close();
}
lastPointerUpType = null;
}
function pointerdown() {