Skip to content

Commit

Permalink
fix(core): allow users to 'escape' axis tooltip in heatmap (#1454)
Browse files Browse the repository at this point in the history
fix #1453
  • Loading branch information
Akshat55 committed Oct 20, 2022
1 parent 299dd3d commit d6873e2
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions packages/core/src/components/axes/hover-axis.ts
Expand Up @@ -86,27 +86,6 @@ export class HoverAxis extends Axis {
)
.attr('height', height)
.lower();

// Add keyboard event listeners to each group element
g.on('keydown', function (event: KeyboardEvent) {
// Choose specific arrow key depending on the axis
if (
axisPosition === AxisPositions.LEFT ||
axisPosition === AxisPositions.RIGHT
) {
if (event.key && event.key === 'ArrowUp') {
self.goNext(this as HTMLElement, event);
} else if (event.key && event.key === 'ArrowDown') {
self.goPrevious(this as HTMLElement, event);
}
} else {
if (event.key && event.key === 'ArrowLeft') {
self.goPrevious(this as HTMLElement, event);
} else if (event.key && event.key === 'ArrowRight') {
self.goNext(this as HTMLElement, event);
}
}
});
});

// Add event listeners to element group
Expand Down Expand Up @@ -219,6 +198,35 @@ export class HoverAxis extends Axis {
element: select(this),
datum: select(this).select('text').datum(),
});
})
.on('keydown', function (event) {
// Hide the tooltip when `Escape` is pressed, but keep focus
if (event.key && event.key === 'Escape') {
self.services.events.dispatchEvent(Events.Tooltip.HIDE);
self.services.events.dispatchEvent(Events.Axis.LABEL_BLUR, {
event,
element: select(this),
datum: select(this).select('text').datum(),
});
}

// Choose specific arrow key depending on the axis
if (
axisPosition === AxisPositions.LEFT ||
axisPosition === AxisPositions.RIGHT
) {
if (event.key && event.key === 'ArrowUp') {
self.goNext(this as HTMLElement, event);
} else if (event.key && event.key === 'ArrowDown') {
self.goPrevious(this as HTMLElement, event);
}
} else {
if (event.key && event.key === 'ArrowLeft') {
self.goPrevious(this as HTMLElement, event);
} else if (event.key && event.key === 'ArrowRight') {
self.goNext(this as HTMLElement, event);
}
}
});
}

Expand Down

0 comments on commit d6873e2

Please sign in to comment.