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

[TextField] FormHelperTextProps component prop error in TypeScript #33339

Closed
2 tasks done
robcaldecott opened this issue Jun 30, 2022 · 8 comments · Fixed by #35924
Closed
2 tasks done

[TextField] FormHelperTextProps component prop error in TypeScript #33339

robcaldecott opened this issue Jun 30, 2022 · 8 comments · Fixed by #35924
Labels
bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! typescript

Comments

@robcaldecott
Copy link
Contributor

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

I am trying to replace the FormHelperText component used by a TextField with my own variant but am getting a TS error when attempting to override the component prop. Here is the code:

// Custom helper text component
const HelperText = ({ children }: FormHelperTextProps) => (
  <Stack direction="row" spacing={0.5} alignItems="center" sx={{ p: 1 }}>
    <ErrorOutlineIcon color="error" />
    <Typography component="span" variant="body2" color="error">
      {children}
    </Typography>
  </Stack>
);

<TextField
  label="Enter some stuff"
  defaultValue="Hello"
  helperText="Hello, world!"
  // ts(2322) error here
  FormHelperTextProps={{ component: HelperText }}
/>

The full TS error is:

Type '{ component: ({ children }: FormHelperTextProps<"p", {}>) => JSX.Element; }' is not assignable to type 'Partial<FormHelperTextProps<"p", {}>>'.
  Object literal may only specify known properties, and 'component' does not exist in type 'Partial<FormHelperTextProps<"p", {}>>'.

The code works and I get my fancy helper text replacement but I cannot fix the TS error.

Expected behavior 🤔

I would expect to be able to override the component prop of FormHelperTextProps to replace the implemenation.

The MUI docs state:

The component used for the root node. Either a string to use a HTML element or a component.

https://mui.com/material-ui/api/form-helper-text/#props

Steps to reproduce 🕹

https://codesandbox.io/s/upbeat-lamarr-z7f72d?file=/src/App.tsx

Context 🔦

I want to customise the component used to render TextField helperText.
Maybe there is another way to do this without incurring the wrath of TypeScript?

Your environment 🌎

@mui/material 5.8.4

@robcaldecott robcaldecott added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jun 30, 2022
@robcaldecott
Copy link
Contributor Author

Seems to be related to this:

#27703

And maybe more. Looks like there's no workaround other than ts-expect-error 🤷‍♂️

@ZeeshanTamboli
Copy link
Member

Also related to #32392 and #32872

@ZeeshanTamboli ZeeshanTamboli changed the title TextField: FormHelperTextProps component error in TypeScript [TextField] FormHelperTextProps component error in TypeScript Jul 5, 2022
@ZeeshanTamboli ZeeshanTamboli added bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! typescript and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jul 5, 2022
@ZeeshanTamboli ZeeshanTamboli changed the title [TextField] FormHelperTextProps component error in TypeScript [TextField] FormHelperTextProps component prop error in TypeScript Jul 5, 2022
@auduongtuan
Copy link

any updates on this?

@ZeeshanTamboli
Copy link
Member

any updates on this?

@auduongtuan There is a fix provided in #35924.

@JanPretzel
Copy link

any updates on this?

@auduongtuan There is a fix provided in #35924.

It doesn't really fix the issue. The component prop now only allows 'p' | undefined. Is this intended or still broken?

Updated the codesandbox of @robcaldecott here: https://codesandbox.io/s/rough-tree-cxvcgc

sai6855 added a commit to sai6855/material-ui that referenced this issue Jul 24, 2023
@sai6855
Copy link
Contributor

sai6855 commented Jul 24, 2023

@JanPretzel this will be fixed in #38084

@jonesmac
Copy link

jonesmac commented Aug 1, 2023

I think this might be back in 5.14.3

@jonesmac
Copy link

jonesmac commented Aug 1, 2023

The issue is solved for the standard component prop on a mui component. However, its still a regression for styled components as passing the component prop causes a type error. Since it worked previously, can we revert again till the styled case is fixed?

Let me know if a new issue would help.

See updated sandbox - https://codesandbox.io/s/nifty-paper-gqcq77?file=/src/App.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! typescript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants