Skip to content
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

[material-ui][Autocomplete] Fix renderOption props type #42689

Merged
merged 5 commits into from
Jun 21, 2024

Conversation

DiegoAndai
Copy link
Member

@DiegoAndai DiegoAndai commented Jun 19, 2024

Closes #39833

Fixes second bug described in #39833 (comment). The first bug was fixed in #42099.

Use the correct type for renderOptions's props callback argument. The type comes from UseAutocompleteReturnValue.

Before: https://codesandbox.io/p/sandbox/39833-render-option-type-next-vd4jpp?file=%2Fsrc%2FDemo.tsx
After: https://codesandbox.io/p/devbox/f27pj7?file=%2Fsrc%2FDemo.tsx%3A7%2C18

@DiegoAndai DiegoAndai added typescript package: material-ui Specific to @mui/material component: autocomplete This is the name of the generic UI component, not the React module! needs cherry-pick The PR should be cherry-picked to master after merge labels Jun 19, 2024
@DiegoAndai DiegoAndai self-assigned this Jun 19, 2024
@DiegoAndai DiegoAndai added the React 19 support PRs required to support React 19 label Jun 19, 2024
@mui-bot
Copy link

mui-bot commented Jun 19, 2024

Netlify deploy preview

https://deploy-preview-42689--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against fe6d0a8

@DiegoAndai
Copy link
Member Author

@aarongarciah I've added the "React 19 support" label so we can add it to all PRs related to React 19, in case we need to backport it from v6 (next) to v5 (master).

I also added the needs cherry-picking label as this is an issue currently affecting users: #39833 (comment)

@DiegoAndai
Copy link
Member Author

Also, I didn't find any other similar type bugs in other components 👍🏼

@@ -361,6 +361,10 @@ export interface UseAutocompleteRenderedOption<Value> {
index: number;
}

export type UseAutocompleteGetOptionPropsReturnValue = React.HTMLAttributes<HTMLLIElement> & {
key: any;
Copy link
Member

@aarongarciah aarongarciah Jun 19, 2024

Choose a reason for hiding this comment

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

Should we use the type coming from @types/react?

Suggested change
key: any;
key: React.Key;

Source: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/298040491bdf086e6fbfe3c9eb12fbe96c90b7fc/types/react/index.d.ts#L239-L262

Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally, yes, but I would keep any as that's the type declared in Base's getOptionProps and we don't want to update that.

Copy link
Member

@aarongarciah aarongarciah left a comment

Choose a reason for hiding this comment

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

Looks good! Left a couple of inline comments for your consideration.

@DiegoAndai DiegoAndai removed the request for review from michaldudak June 21, 2024 15:29
@DiegoAndai DiegoAndai merged commit 9ffa010 into mui:next Jun 21, 2024
19 checks passed
@DiegoAndai DiegoAndai deleted the render-option-props-type branch June 21, 2024 18:37
joserodolfofreitas pushed a commit to joserodolfofreitas/material-ui that referenced this pull request Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module! needs cherry-pick The PR should be cherry-picked to master after merge package: material-ui Specific to @mui/material React 19 support PRs required to support React 19 typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

react 18.3.0 "A props object containing a "key" prop is being spread into JSX"
3 participants