Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/core/__tests__/chart-core-navigation-cartesian.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ describe("CoreChart: navigation, cartesian charts", () => {
expect(describeFocusedElement()).toBe("button:1[true,false]");
expect(wrapper.findTooltip()!.getElement().textContent).toBe("1Line series 111Line series 221");

// First ESC dismisses tooltip, second ESC navigates to chart
keyDown(KeyCode.escape);
keyDown(KeyCode.escape);

expect(describeFocusedElement()).toBe("application:Test chart");
Expand Down Expand Up @@ -560,19 +562,21 @@ describe("CoreChart: navigation, cartesian charts", () => {
);

test("moves focus from point to group", () => {
const { wrapper } = renderChart(commonProps(false, seriesLong1));
const { wrapper } = renderChart(commonProps(false, seriesShort2));

focusApplication();
keyDown(KeyCode.enter);
keyDown(KeyCode.down);

expect(describeFocusedElement()).toBe("button:1 -1, Line series 1[true,false]");
expect(wrapper.findTooltip()!.getElement().textContent).toBe("1Line series 1-1");
expect(describeFocusedElement()).toBe("button:1 11, Line series 1[true,false]");
expect(wrapper.findTooltip()!.getElement().textContent).toBe("1Line series 111Line series 221");

// First ESC dismisses tooltip, second ESC navigates to group
keyDown(KeyCode.escape);
keyDown(KeyCode.escape);

expect(describeFocusedElement()).toBe("button:1[true,false]");
expect(wrapper.findTooltip()!.getElement().textContent).toBe("1Line series 1-1");
expect(wrapper.findTooltip()!.getElement().textContent).toBe("1Line series 111Line series 221");
});

test("pins popover at point", () => {
Expand Down
2 changes: 2 additions & 0 deletions src/core/__tests__/chart-core-navigation-pie.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ describe("CoreChart: navigation, pie charts", () => {
expect(describeFocusedElement()).toBe("button:P1, 10. Pie series[true,false]");
expect(wrapper.findTooltip()!.getElement().textContent).toBe("P1Pie series10");

// First ESC dismisses tooltip, second ESC navigates to chart
keyDown(KeyCode.escape);
keyDown(KeyCode.escape);

expect(describeFocusedElement()).toBe("application:Test chart");
Expand Down
16 changes: 14 additions & 2 deletions src/core/chart-api/chart-extra-navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export interface ChartExtraNavigationHandlers {
onBlur(): void;
onActivatePoint(point: Highcharts.Point, group: readonly Highcharts.Point[]): void;
onActivateGroup(group: readonly Highcharts.Point[]): void;
// Returns true if a tooltip was dismissed, false otherwise.
// Used by ESC handlers to decide whether to also navigate.
onDismissHoverTooltip(): boolean;
}

export type FocusedState = FocusedStateChart | FocusedStateGroup | FocusedStatePoint;
Expand Down Expand Up @@ -193,6 +196,7 @@ export class ChartExtraNavigation {
private onKeyDownChart = (event: KeyboardEvent) => {
handleKey(event, {
onActivate: () => this.moveToFirstGroup(),
onEscape: () => this.handlers.onDismissHoverTooltip(),
onInlineStart: () => this.moveToLastGroup(),
onInlineEnd: () => this.moveToFirstGroup(),
onBlockStart: () => this.moveToLastGroup(),
Expand All @@ -206,7 +210,11 @@ export class ChartExtraNavigation {
const i = !!this.context.chart().inverted;
handleKey(event, {
onActivate: () => this.activateGroup(group),
onEscape: () => this.moveToChart(),
onEscape: () => {
if (!this.handlers.onDismissHoverTooltip()) {
this.moveToChart();
}
},
onInlineStart: () => (i ? this.moveToFirstInGroup(group) : this.moveToPrevGroup(group)),
onInlineEnd: () => (i ? this.moveToLastInGroup(group) : this.moveToNextGroup(group)),
onBlockStart: () => (i ? this.moveToPrevGroup(group) : this.moveToLastInGroup(group)),
Expand All @@ -222,7 +230,11 @@ export class ChartExtraNavigation {
const i = !!this.context.chart().inverted;
handleKey(event, {
onActivate: () => this.activatePoint(point, group),
onEscape: () => this.moveToParentGroup(point),
onEscape: () => {
if (!this.handlers.onDismissHoverTooltip()) {
this.moveToParentGroup(point);
}
},
onInlineEnd: () => (i ? this.moveToPrevInGroup(point) : this.moveToNextInSeries(point)),
onInlineStart: () => (i ? this.moveToNextInGroup(point) : this.moveToPrevInSeries(point)),
onBlockEnd: () => (i ? this.moveToNextInSeries(point) : this.moveToNextInGroup(point)),
Expand Down
11 changes: 11 additions & 0 deletions src/core/chart-api/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,17 @@ export class ChartAPI {
this.clearChartHighlight({ isApiCall: false });
this.chartExtraNavigation.announceChart(getChartAccessibleDescription(this.context.chart()));
},
onDismissHoverTooltip: () => {
// Dismiss any visible non-pinned tooltip when ESC is pressed.
// Returns true if a tooltip was dismissed, false otherwise.
// Used by ESC handlers at group/point level to decide whether to also navigate.
const tooltipState = this.chartExtraTooltip.get();
if (tooltipState.visible && !tooltipState.pinned) {
this.clearChartHighlight({ isApiCall: false });
return true;
}
return false;
},
onFocusGroup: (group: Highcharts.Point[]) => {
this.highlightActions(group, { isApiCall: false, overrideTooltipLock: true });
this.chartExtraNavigation.announceElement(getGroupAccessibleDescription(group), false);
Expand Down
Loading