Skip to content

Commit fb24a10

Browse files
committed
fix
1 parent 21b999f commit fb24a10

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

packages/x-charts-premium/src/Map/seriesConfig/keyboardFocusHandler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import {
55

66
const mapShapeSeriesTypes = new Set(['mapShape'] as const);
77

8+
const allowCycles = false;
9+
const seriesMaxLength = true;
10+
811
/**
912
* Move the focus across the shapes of the map series.
1013
*
1114
* `ArrowRight`/`ArrowLeft` move to the next/previous shape of the focused series,
1215
* while `ArrowUp`/`ArrowDown` move between series.
1316
*/
1417
const keyboardFocusHandler: KeyboardFocusHandler<'mapShape', 'mapShape'> =
15-
createCommonKeyboardFocusHandler(mapShapeSeriesTypes);
18+
createCommonKeyboardFocusHandler(mapShapeSeriesTypes, allowCycles, seriesMaxLength);
1619

1720
export default keyboardFocusHandler;

packages/x-charts/src/internals/commonNextFocusItem.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export function createGetNextIndexFocusedItem<
4242
* If true, allows cycling from the last item to the first one.
4343
*/
4444
allowCycles: boolean = false,
45+
/**
46+
* If true, series max index is defined by the current series length and not all series.
47+
*/
48+
seriesMaxLength: boolean = false,
4549
) {
4650
return function getNextIndexFocusedItem(
4751
currentItem: FocusedItemIdentifier<InSeriesType> | null,
@@ -71,7 +75,9 @@ export function createGetNextIndexFocusedItem<
7175
seriesId = nextSeries.seriesId;
7276
}
7377

74-
const maxLength = getMaxSeriesLength(processedSeries, compatibleSeriesTypes);
78+
const maxLength = seriesMaxLength
79+
? (processedSeries[type]?.series[seriesId]?.data.length ?? 0)
80+
: getMaxSeriesLength(processedSeries, compatibleSeriesTypes);
7581

7682
let dataIndex = currentItem?.dataIndex == null ? 0 : currentItem.dataIndex + 1;
7783
if (allowCycles) {
@@ -114,6 +120,10 @@ export function createGetPreviousIndexFocusedItem<
114120
* If true, allows cycling from the last item to the first one.
115121
*/
116122
allowCycles: boolean = false,
123+
/**
124+
* If true, series max index is defined by the current series length and not all series.
125+
*/
126+
seriesMaxLength: boolean = false,
117127
) {
118128
return function getPreviousIndexFocusedItem(
119129
currentItem: FocusedItemIdentifier<InSeriesType> | null,
@@ -143,7 +153,9 @@ export function createGetPreviousIndexFocusedItem<
143153
seriesId = previousSeries.seriesId;
144154
}
145155

146-
const maxLength = getMaxSeriesLength(processedSeries, compatibleSeriesTypes);
156+
const maxLength = seriesMaxLength
157+
? (processedSeries[type]?.series[seriesId]?.data.length ?? 0)
158+
: getMaxSeriesLength(processedSeries, compatibleSeriesTypes);
147159

148160
let dataIndex = currentItem?.dataIndex == null ? maxLength - 1 : currentItem.dataIndex - 1;
149161
if (allowCycles) {

packages/x-charts/src/internals/createCommonKeyboardFocusHandler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ import {
1212
export function createCommonKeyboardFocusHandler<
1313
SeriesType extends Exclude<ChartSeriesType, 'sankey' | 'heatmap'>,
1414
TInputSeriesType extends Exclude<ChartSeriesType, 'sankey' | 'heatmap'> = SeriesType,
15-
>(outSeriesTypes: Set<SeriesType>, allowCycles?: boolean) {
15+
>(outSeriesTypes: Set<SeriesType>, allowCycles?: boolean, seriesMaxLength?: boolean) {
1616
const keyboardFocusHandler = (event: KeyboardEvent) => {
1717
switch (event.key) {
1818
case 'ArrowRight':
1919
return createGetNextIndexFocusedItem<TInputSeriesType, SeriesType>(
2020
outSeriesTypes,
2121
allowCycles,
22+
seriesMaxLength,
2223
);
2324
case 'ArrowLeft':
2425
return createGetPreviousIndexFocusedItem<TInputSeriesType, SeriesType>(
2526
outSeriesTypes,
2627
allowCycles,
28+
seriesMaxLength,
2729
);
2830
case 'ArrowDown':
2931
return createGetPreviousSeriesFocusedItem<TInputSeriesType, SeriesType>(outSeriesTypes);

0 commit comments

Comments
 (0)