fix: add cursor prop type to BaseChartProps#7065
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughAdded an optional Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/chart/BarChart.typed.spec.tsx (1)
7-23: Type-checking tests look good, consider adding negative test cases.The type compilation tests correctly verify that the
cursorprop is accepted on chart components. For more comprehensive type coverage, consider adding a negative test case using@ts-expect-errorto verify that invalid cursor values are rejected by TypeScript.💡 Optional enhancement for negative type testing
it('should reject invalid cursor values', () => { return ( // `@ts-expect-error` - invalid cursor value should fail type check <BarChart width={400} height={300} data={data} cursor="invalid-cursor-value" /> ); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/chart/BarChart.typed.spec.tsx` around lines 7 - 23, Add a negative type-check test to ensure invalid cursor values are rejected by TypeScript: in the existing test suite that uses BarChart, LineChart, and PieChart add an it block that returns a chart component (e.g., BarChart) with an obviously invalid cursor string and annotate the JSX line with // `@ts-expect-error` so the test fails compilation if the types erroneously accept the invalid value; reference the existing BarChart/LineChart/PieChart components and keep the other props (width, height, data) consistent with current tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/chart/BarChart.typed.spec.tsx`:
- Around line 7-23: Add a negative type-check test to ensure invalid cursor
values are rejected by TypeScript: in the existing test suite that uses
BarChart, LineChart, and PieChart add an it block that returns a chart component
(e.g., BarChart) with an obviously invalid cursor string and annotate the JSX
line with // `@ts-expect-error` so the test fails compilation if the types
erroneously accept the invalid value; reference the existing
BarChart/LineChart/PieChart components and keep the other props (width, height,
data) consistent with current tests.
|
Conflicts |
test/chart/BarChart.typed.spec.tsx
Outdated
| </BarChart>, | ||
| ); | ||
| it('should accept cursor prop on LineChart', () => { | ||
| return <LineChart width={400} height={300} data={data} cursor="crosshair" />; |
There was a problem hiding this comment.
Let's assert that the prop actually appears in the DOM
Closes recharts#2484 The cursor SVG presentation attribute was already forwarded to the SVG element at runtime (listed in SVGElementPropKeys) but was missing from the TypeScript type definitions. Adding it to BaseChartProps makes it available on all chart types (BarChart, LineChart, PieChart, etc.).
65ad7de to
3a43b34
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7065 +/- ##
=======================================
Coverage 89.61% 89.61%
=======================================
Files 534 534
Lines 40252 40252
Branches 5477 5477
=======================================
Hits 36070 36070
Misses 4174 4174
Partials 8 8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fixes #2484
The
cursorSVG presentation attribute was already forwarded to the<svg>element at runtime (it's listed inSVGElementPropKeysinsvgPropertiesNoEvents.ts), but was missing from the TypeScript type definitions, causing a TS error when passing it directly.This adds
cursor?: CSSProperties['cursor']toBaseChartProps, which covers all chart components that extend it (BarChart, LineChart, AreaChart, PieChart, RadarChart, etc.).Before:
After:
Also adds a typed spec test file to verify compilation.
Summary by CodeRabbit
New Features
Tests
Documentation