Skip to content

Fix event types for Pie and RadialBar#6965

Merged
ckifer merged 5 commits intomainfrom
radialbar-events-any
Feb 5, 2026
Merged

Fix event types for Pie and RadialBar#6965
ckifer merged 5 commits intomainfrom
radialbar-events-any

Conversation

@PavelVanecek
Copy link
Collaborator

@PavelVanecek PavelVanecek commented Feb 5, 2026

Description

Remove any, update the event generics so that it's internally compatible with getRelativeCoordinate

Related Issue

#6645

Summary by CodeRabbit

Release Notes

  • New Features

    • Added touch event handlers (onTouchStart, onTouchMove, onTouchEnd) to Pie and RadialBar components for improved touch interaction support.
  • Improvements

    • Enhanced type safety for mouse event handlers in Pie and RadialBar components with more specific SVG element typing.
    • Exported RadialBarDataItem type for improved type support in custom event handlers.
  • Tests

    • Added type safety verification tests for event handlers in Pie and RadialBar components.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

Walkthrough

This PR enhances TypeScript type safety for event handlers in Pie and RadialBar components. It exports RadialBarDataItem as a public type, refines event handler signatures with specific React.MouseEvent<SVGGraphicsElement> and React.TouchEvent<SVGGraphicsElement> types, adds touch event support (onTouchStart, onTouchMove, onTouchEnd), and augments RadialBarDataItem to extend TooltipTriggerInfo. Test files are updated with adjusted import paths and new type-checking test files verify handler type compatibility.

Changes

Cohort / File(s) Summary
Public Type Exports
omnidoc/verifyExamples.spec.ts, src/index.ts
Added RadialBarDataItem to the public API exports and documentation requirements, making it available for external consumers.
Event Handler Type Refinements - Pie
src/polar/Pie.tsx, test/polar/Pie/Pie.typed.spec.tsx
Updated PieEvents interface to type mouse event handlers with React.MouseEvent<SVGGraphicsElement>, added three new touch event handlers (onTouchStart, onTouchMove, onTouchEnd), and omitted event handler keys from SVG attributes. Added new typed test file validating type safety of event handlers with getRelativeCoordinate.
Event Handler Type Refinements - RadialBar
src/polar/RadialBar.tsx, test/polar/RadialBar/RadialBar.typed.spec.tsx
Augmented RadialBarDataItem to extend TooltipTriggerInfo, refined all event handler signatures to use RadialBarDataItem and React.MouseEvent<SVGGraphicsElement>, added three new touch event handlers, and tightened RadialBarProps to omit handler keys. Added new typed test file validating event handler type compatibility.
Test Updates - Import Path Migration
test/polar/Pie/Pie-TwoLevelPieChart.spec.tsx, test/polar/Pie/Pie.animation.spec.tsx, test/polar/Pie/Pie.spec.tsx, test/polar/RadialBar/RadialBar.animation.spec.tsx, test/polar/RadialBar/RadialBar.spec.tsx
Updated relative import paths to reflect test directory reorganization (e.g., ../../src../../../src) and added explicit type annotations for event handlers using Mock<...> with RadialBarDataItem parameters.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Fix mouse event type #6939 — Modifies RadialBar event and tooltip typings alongside SVG event generics, directly overlapping with this PR's event handler refinements.
  • Add missing type exports, test #6852 — Updates public type exports from the main library barrel file, paralleling this PR's addition of RadialBarDataItem to src/index.ts.
  • Fix Pie event handlers type #6944 — Exports TooltipTriggerInfo and updates Pie event types; the main PR depends on TooltipTriggerInfo being available for RadialBarDataItem augmentation.

Suggested reviewers

  • ckifer
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description provides a brief explanation of the change (removing any, updating event generics) and includes a related issue link, but it lacks detail on motivation, testing methodology, and does not follow the template structure with required sections like 'Motivation and Context' and 'How Has This Been Tested'. Expand the description to include Motivation and Context section explaining why this change is needed, and add a How Has This Been Tested section detailing the testing approach and new test files added.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix event types for Pie and RadialBar' accurately summarizes the main change—refining event handler types and removing 'any' types from these components to ensure compatibility with getRelativeCoordinate.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch radialbar-events-any

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@src/polar/Pie.tsx`:
- Around line 222-224: The public touch event props onTouchStart, onTouchMove,
and onTouchEnd lack JSDoc like the mouse handlers; add JSDoc blocks above each
prop declaration (onTouchStart, onTouchMove, onTouchEnd) describing the callback
signature, parameters (data: PieSectorDataItem, index: number, e:
React.TouchEvent<SVGGraphicsElement>), when it's invoked, and any return
behavior so omnidoc will pick them up—mirror the style and phrasing used for the
corresponding mouse handlers to keep the API docs consistent.

In `@src/polar/RadialBar.tsx`:
- Around line 402-404: Add JSDoc comments for the new public touch event handler
props so they appear in generated docs: document onTouchStart, onTouchMove, and
onTouchEnd (each taking a RadialBarDataItem, index: number, and
React.TouchEvent<SVGGraphicsElement>) with brief descriptions of when they fire,
the meaning of the parameters, and that they are optional callback props on the
RadialBar component; place the JSDoc immediately above each property declaration
to match existing style and ensure omnidoc picks them up.
- Around line 418-421: The prop type uses
PresentationAttributesAdaptChildEvent<any, SVGElement> with any; replace the any
with the existing RadialBarDataItem type so RadialBarProps reads
PresentationAttributesAdaptChildEvent<RadialBarDataItem, SVGElement> (follow the
same pattern used in Bar.tsx which uses BarRectangleItem) and ensure
imports/types remain consistent with RadialBarDataItem.

Comment on lines +222 to +224
onTouchStart?: (data: PieSectorDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
onTouchMove?: (data: PieSectorDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
onTouchEnd?: (data: PieSectorDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add JSDoc for new touch event handlers.

onTouchStart, onTouchMove, and onTouchEnd are public props but don’t have doc blocks like the mouse handlers, so omnidoc won’t surface them.

✍️ Suggested doc additions
 interface PieEvents {
   /**
    * The customized event handler of mouseleave on the sectors in this group.
    */
   onMouseLeave?: (data: PieSectorDataItem, index: number, e: React.MouseEvent<SVGGraphicsElement>) => void;
+  /**
+   * The customized event handler of touchstart on the sectors in this group.
+   */
   onTouchStart?: (data: PieSectorDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
+  /**
+   * The customized event handler of touchmove on the sectors in this group.
+   */
   onTouchMove?: (data: PieSectorDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
+  /**
+   * The customized event handler of touchend on the sectors in this group.
+   */
   onTouchEnd?: (data: PieSectorDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
 }

As per coding guidelines, src/**/*.{ts,tsx}: JSDoc comments and TypeScript definitions in source files must be kept up-to-date as they are used to autogenerate API documentation via 'npm run omnidoc'.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onTouchStart?: (data: PieSectorDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
onTouchMove?: (data: PieSectorDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
onTouchEnd?: (data: PieSectorDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
/**
* The customized event handler of touchstart on the sectors in this group.
*/
onTouchStart?: (data: PieSectorDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
/**
* The customized event handler of touchmove on the sectors in this group.
*/
onTouchMove?: (data: PieSectorDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
/**
* The customized event handler of touchend on the sectors in this group.
*/
onTouchEnd?: (data: PieSectorDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
🤖 Prompt for AI Agents
In `@src/polar/Pie.tsx` around lines 222 - 224, The public touch event props
onTouchStart, onTouchMove, and onTouchEnd lack JSDoc like the mouse handlers;
add JSDoc blocks above each prop declaration (onTouchStart, onTouchMove,
onTouchEnd) describing the callback signature, parameters (data:
PieSectorDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>), when
it's invoked, and any return behavior so omnidoc will pick them up—mirror the
style and phrasing used for the corresponding mouse handlers to keep the API
docs consistent.

Comment on lines +402 to +404
onTouchStart?: (data: RadialBarDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
onTouchMove?: (data: RadialBarDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
onTouchEnd?: (data: RadialBarDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add JSDoc for new touch event handlers.

These new public handlers lack documentation, so omnidoc won’t include them.

✍️ Suggested doc additions
   /**
    * The customized event handler of mouseleave in this chart.
    */
   onMouseLeave?: (data: RadialBarDataItem, index: number, e: React.MouseEvent<SVGGraphicsElement>) => void;
+  /**
+   * The customized event handler of touchstart in this chart.
+   */
   onTouchStart?: (data: RadialBarDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
+  /**
+   * The customized event handler of touchmove in this chart.
+   */
   onTouchMove?: (data: RadialBarDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
+  /**
+   * The customized event handler of touchend in this chart.
+   */
   onTouchEnd?: (data: RadialBarDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;

As per coding guidelines, src/**/*.{ts,tsx}: JSDoc comments and TypeScript definitions in source files must be kept up-to-date as they are used to autogenerate API documentation via 'npm run omnidoc'.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onTouchStart?: (data: RadialBarDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
onTouchMove?: (data: RadialBarDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
onTouchEnd?: (data: RadialBarDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
/**
* The customized event handler of touchstart in this chart.
*/
onTouchStart?: (data: RadialBarDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
/**
* The customized event handler of touchmove in this chart.
*/
onTouchMove?: (data: RadialBarDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
/**
* The customized event handler of touchend in this chart.
*/
onTouchEnd?: (data: RadialBarDataItem, index: number, e: React.TouchEvent<SVGGraphicsElement>) => void;
🤖 Prompt for AI Agents
In `@src/polar/RadialBar.tsx` around lines 402 - 404, Add JSDoc comments for the
new public touch event handler props so they appear in generated docs: document
onTouchStart, onTouchMove, and onTouchEnd (each taking a RadialBarDataItem,
index: number, and React.TouchEvent<SVGGraphicsElement>) with brief descriptions
of when they fire, the meaning of the parameters, and that they are optional
callback props on the RadialBar component; place the JSDoc immediately above
each property declaration to match existing style and ensure omnidoc picks them
up.

Comment on lines +418 to +421
export type RadialBarProps = Omit<
PresentationAttributesAdaptChildEvent<any, SVGElement>,
'ref' | keyof InternalRadialBarProps
> &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, check the current state of the file at the specified lines
sed -n '415,425p' src/polar/RadialBar.tsx

Repository: recharts/recharts

Length of output: 361


🏁 Script executed:

# Find and examine PresentationAttributesAdaptChildEvent definition
rg -A 15 "type PresentationAttributesAdaptChildEvent|interface PresentationAttributesAdaptChildEvent" src

Repository: recharts/recharts

Length of output: 727


🏁 Script executed:

# Search for other uses of PresentationAttributesAdaptChildEvent to see patterns
rg "PresentationAttributesAdaptChildEvent<" src --no-heading -B 2 -A 2

Repository: recharts/recharts

Length of output: 4203


🏁 Script executed:

# Look for DOMAttributesAdaptChildEvent definition
rg "type DOMAttributesAdaptChildEvent|interface DOMAttributesAdaptChildEvent" src -A 15

Repository: recharts/recharts

Length of output: 909


🏁 Script executed:

# Check if there are any TODOs or tracking issues for typing PresentationAttributesAdaptChildEvent
rg "PresentationAttributesAdaptChildEvent|DOMAttributesAdaptChildEvent" src -B 3 | rg -i "TODO|FIXME|XXX|issue|typing|any" -B 2 -A 2

Repository: recharts/recharts

Length of output: 2911


🏁 Script executed:

# Check Bar.tsx to see how it properly types the first parameter
sed -n '1,150p' src/cartesian/Bar.tsx | grep -A 20 "BarSvgProps"

Repository: recharts/recharts

Length of output: 43


🏁 Script executed:

# Find the BarRectangleItem type definition and see how Bar.tsx uses it
rg "BarRectangleItem" src -B 5 -A 5

Repository: recharts/recharts

Length of output: 19226


🏁 Script executed:

# Check if there are any issues or discussions about typing these attributes
git log --all --grep="PresentationAttributesAdaptChildEvent\|any\|typing" --oneline | head -20

Repository: recharts/recharts

Length of output: 1471


🏁 Script executed:

# Search for any type definitions or guidance in CONTRIBUTING.md about this pattern
cat CONTRIBUTING.md | grep -A 10 -B 10 "any\|PresentationAttributesAdaptChildEvent" || echo "No matches in CONTRIBUTING.md"

Repository: recharts/recharts

Length of output: 1053


🏁 Script executed:

# Check what RadialBar uses for its data structures - look for sector/point types
rg "sector|RadialBar" src/polar/RadialBar.tsx -B 2 -A 5 | head -80

Repository: recharts/recharts

Length of output: 3005


🏁 Script executed:

# Check what type RadialBar uses in its event handlers
rg "onMouseEnter|onMouseLeave|onChange|onClick" src/polar/RadialBar.tsx -B 2 -A 3

Repository: recharts/recharts

Length of output: 2348


🏁 Script executed:

# Check Pie.tsx for comparison (uses same pattern)
sed -n '1,100p' src/polar/Pie.tsx | grep -A 20 "type\|interface"

Repository: recharts/recharts

Length of output: 2440


Use RadialBarDataItem type instead of any for SVG attributes.

PresentationAttributesAdaptChildEvent<any, SVGElement> violates the "never use any" guideline. Follow the pattern used in Bar.tsx (which uses BarRectangleItem) and use the existing RadialBarDataItem type defined in this file.

🧩 Proposed fix
-export type RadialBarProps = Omit<
-  PresentationAttributesAdaptChildEvent<any, SVGElement>,
+export type RadialBarProps = Omit<
+  PresentationAttributesAdaptChildEvent<RadialBarDataItem, SVGElement>,
   'ref' | keyof InternalRadialBarProps
 > &
   Omit<InternalRadialBarProps, 'sectors'>;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export type RadialBarProps = Omit<
PresentationAttributesAdaptChildEvent<any, SVGElement>,
'ref' | keyof InternalRadialBarProps
> &
export type RadialBarProps = Omit<
PresentationAttributesAdaptChildEvent<RadialBarDataItem, SVGElement>,
'ref' | keyof InternalRadialBarProps
> &
Omit<InternalRadialBarProps, 'sectors'>;
🤖 Prompt for AI Agents
In `@src/polar/RadialBar.tsx` around lines 418 - 421, The prop type uses
PresentationAttributesAdaptChildEvent<any, SVGElement> with any; replace the any
with the existing RadialBarDataItem type so RadialBarProps reads
PresentationAttributesAdaptChildEvent<RadialBarDataItem, SVGElement> (follow the
same pattern used in Bar.tsx which uses BarRectangleItem) and ensure
imports/types remain consistent with RadialBarDataItem.

@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.13%. Comparing base (4ed0bb8) to head (97c8f0f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6965   +/-   ##
=======================================
  Coverage   91.13%   91.13%           
=======================================
  Files         509      509           
  Lines       37967    37967           
  Branches     5287     5287           
=======================================
  Hits        34601    34601           
  Misses       3357     3357           
  Partials        9        9           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codecov
Copy link

codecov bot commented Feb 5, 2026

Bundle Report

Bundle size has no change ✅

@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

Staging Deployment Details

These deployments will remain available for 30 days.

To update snapshots: Comment /update-snapshots on this PR to automatically update the baseline screenshots.

@ckifer ckifer merged commit ff5c33b into main Feb 5, 2026
48 checks passed
@ckifer ckifer deleted the radialbar-events-any branch February 5, 2026 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants