-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(14831): update component and getter function types to match #17135
fix(14831): update component and getter function types to match #17135
Conversation
Update <TableExpandRow />, <TableSelectAll />, <TableSelectRow /> props to make checked and isSelected nullable since they already expect undefined or default to a boolean value anyway. This allows the values returned by getSelectionProps and getRowProps to be more consistent. This should resolve typescript errors that occur when using official examples.
All contributors have signed the DCO. |
I have read the DCO document and I hereby sign the DCO. |
✅ Deploy Preview for v11-carbon-react ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for carbon-elements ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey sorry I missed this one in my notifications. This looks good to me
…831-datatable-type-fixes
✅ Deploy Preview for v11-carbon-web-components ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There must've been some overlap with another PR. When I updated this with latest from |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #17135 +/- ##
=======================================
Coverage 80.79% 80.79%
=======================================
Files 406 406
Lines 14041 14041
Branches 4367 4395 +28
=======================================
Hits 11344 11344
Misses 2530 2530
Partials 167 167 ☔ View full report in Codecov by Sentry. |
538060f
Update
<TableExpandRow />
,<TableSelectAll />
,<TableSelectRow />
props to make checked and isSelected optional since they already expect undefined or default to a boolean value anyway. This allows the values returned by getSelectionProps and getRowProps to be more consistent. This should resolve typescript errors that occur when using official examples.Closes #14831
Making the argument for
getSelectionProps
optional allows the official examples to work without breaking anything with the change; the function already defaults the argument to an empty object. There is perhaps something to be said for refactoring thegetSelectionProps
function to better differentiate between the contexts in which it is used (<TableSelectRow />
vs<TableSelectAll />
), but the presence of an optional argument (as it is now) seems reasonable.Switching the
onClick
handlers to use React'sMouseEvent
interface makes them compatible withMouseEventHandler<HTMLButtonElement>
, which resolves a few of the errors on those components.The
checked
prop was overly restrictive in the<TableSelectRow />
and<TableSelectAll />
prop definitions; the only places the prop is used within those components expects it to be optional. Relaxing the type on those two components resolves the typescript errors and seems to have been the original intent based on how it is typed inDataTableRow
. This shouldn't be a breaking change to the component API since all currently allowed values are still valid after the change. TheisExpanded
prop on<TableExpandRow />
is the same issue of being overly restrictive.The
radio
key being returned fromgetSelectionProps
unnecessarily included anull
option - both the actual value and the type. Removing both references tonull
makes it compatible with<TableSelectRow />
props.Changelog
New
Changed
onClick
handlers now use React'sMouseEvent
interface instead of the nativeMouseEvent
getSelectionProps
arguments are now optionalgetSelectionProps
is now accurately typed to returnchecked
as an optional keygetSelectionprops
radio
key is nowboolean | undefined
(changed fromboolean | undefined | null
)<TableSelectRow />
and<TableSelectAll />
checked
prop is now optional<TableExpandRow />
isExpanded
prop is now optionalRemoved
Testing / Reviewing
Run the code examples for
DataTable / Selection / Default
andDataTable / Expansion / Default
in a TypeScript environment; the errors should be resolved.