Skip to content

Commit ab81edd

Browse files
committed
fix arrow navigation
1 parent 76f3ac0 commit ab81edd

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

cypress/support/utils.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ export function testPieSectorFocus(Component, props, { only }: { only?: boolean
130130
.and('have.attr', 'role', 'img')
131131
.and('have.attr', 'aria-label');
132132

133-
cy.realPress('ArrowRight');
134-
cy.focused().should('have.attr', 'data-sector-index', '1');
135133
cy.realPress('ArrowLeft');
134+
cy.focused().should('have.attr', 'data-sector-index', '1');
135+
cy.realPress('ArrowRight');
136136
cy.focused().should('have.attr', 'data-sector-index', '0');
137137

138138
// Wraps from first to last
139-
cy.realPress('ArrowLeft');
139+
cy.realPress('ArrowRight');
140140
cy.focused().should('have.attr', 'data-sector-index', String(props.dataset.length - 1));
141141

142142
cy.realPress('Enter');
@@ -180,7 +180,7 @@ export function testPieSectorFocus(Component, props, { only }: { only?: boolean
180180
cy.realPress('Tab');
181181
cy.focused().should('have.attr', 'data-sector-index', '3');
182182

183-
cy.realPress('ArrowRight');
183+
cy.realPress('ArrowLeft');
184184
cy.focused().should('have.attr', 'data-sector-index', '4');
185185
cy.realPress('Enter');
186186
cy.get('@onDataPointClick').should(
@@ -194,12 +194,12 @@ export function testPieSectorFocus(Component, props, { only }: { only?: boolean
194194
cy.get('.recharts-active-shape').should('exist');
195195
cy.focused().should('have.attr', 'data-sector-index', '4');
196196

197-
cy.realPress('ArrowRight');
197+
cy.realPress('ArrowLeft');
198198
cy.focused().should('have.attr', 'data-sector-index', '5');
199199

200200
// Space activates on keyup — hold Space, arrow to next sector, then release
201201
cy.focused().then(($el) => $el[0].dispatchEvent(new KeyboardEvent('keydown', { key: ' ', bubbles: true })));
202-
cy.realPress('ArrowRight');
202+
cy.realPress('ArrowLeft');
203203
cy.focused().should('have.attr', 'data-sector-index', '6');
204204
cy.focused().then(($el) => $el[0].dispatchEvent(new KeyboardEvent('keyup', { key: ' ', bubbles: true })));
205205
cy.get('@onDataPointClick').should(

packages/charts/src/components/PieChart/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
361361
)}
362362
>
363363
<Pie
364+
// TODO: only pass onClick when hasDataPointClick || activeSegment != null in v3
364365
onClick={onDataPointClickInternal}
365366
innerRadius={chartConfig.innerRadius}
366367
outerRadius={chartConfig.outerRadius}

packages/charts/src/components/PieChart/usePieSectorFocus.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ export function usePieSectorFocus({
147147
}
148148

149149
switch (e.key) {
150-
case 'ArrowRight':
150+
case 'ArrowLeft':
151151
case 'ArrowUp': {
152152
e.preventDefault();
153153
e.stopPropagation();
154154
focusSector((sectorFocusRef.current + 1) % dataLength);
155155
break;
156156
}
157-
case 'ArrowLeft':
157+
case 'ArrowRight':
158158
case 'ArrowDown': {
159159
e.preventDefault();
160160
e.stopPropagation();
@@ -182,7 +182,7 @@ export function usePieSectorFocus({
182182
const handleBlur = useCallback(
183183
(e: FocusEvent<HTMLDivElement>) => {
184184
// Defer cleanup — blur fires before layout effects, so the new focus target may not be settled yet.
185-
if (!e.currentTarget.contains(e.relatedTarget as Node)) {
185+
if (!e.currentTarget.contains(e.relatedTarget)) {
186186
const container = e.currentTarget as HTMLElement;
187187
rafIdRef.current = requestAnimationFrame(() => {
188188
if (!container.contains(document.activeElement)) {

0 commit comments

Comments
 (0)