Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): allow users to 'escape' axis tooltip in heatmap #1454

Merged
merged 1 commit into from Oct 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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