Add inputProps prop that lets you pass props down to the inputComponent
See original GitHub issueThis would be very useful when you have props that you need to pass all the way down to the inputComponent.
Otherwise, you have to create a new hard-coded component for literally every unique combination of props that you may want to pass down to the input component. For example, if you wanted to use PhoneInput several places in your app but wanted to use a different label
prop (or helperText
or …) in each place, you would have to do something horrific like this:
const TextFieldWithLabel1 = ({ ...props }) => {
return (
<TextField {...props}
label="Phone number"
/>
)
}
const TextFieldWithLabel2 = ({ ...props }) => {
return (
<TextField {...props}
label="Optional phone number"
/>
)
}
<PhoneInput inputComponent={TextFieldWithLabel1} />
<PhoneInput inputComponent={TextFieldWithLabel2} />
What I’d like is a way to simply pass the props down like this:
<PhoneInput
inputComponent={TextField}
inputProps={{
label: "Optional phone number"
}}
/>
This is how https://material-ui.com/api/text-field/#props lets you pass props to the <input>
component that it wraps, for example.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
How to pass props to the inputComponent material-ui?
Custom props can be passed to the TextMaskCustom using inputProps <FormControl> <InputLabel>react-text-mask</InputLabel> <Input ...
Read more >How passing props to component works in React
Master how to pass props (properties) to components in React with this useful beginner's guide, including demo code.
Read more >Input Components - React-admin - Marmelab
Additional props are passed down to the underlying component (usually a material-ui component). For instance, when setting the className prop on a TextInput ......
Read more >How to create reusable form components with React Hook ...
Next, let's take a look at how we can pass the register property to our input. import React from 'react'; import ...
Read more ><Field /> | Formik
component can either be a React component or the name of an HTML element to render. All additional props will be passed through....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
An example of how clashing (colliding) props like
error
could be passed:src/PhoneInput.js
Ok, added
numberInputProps
andcountrySelectProps
today. Still the existing “passthrough” approach is preferred I guess (for the<input/>
props).