Other InputProps are not applied to InputProps.inputComponent
See original GitHub issue- This is a v1.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
<TextField
className={classes.formControl}
label="react-number-format"
value={numberformat}
onChange={this.handleChange("numberformat")}
id="formatted-numberformat-input"
InputProps={{
inputComponent: NumberFormatCustom,
testProp: "yo"
}}
/>
The testProp
should be passed along with other input properties when instantiating NumberFormatCustom
: <NumberFormatCustom testProp="yo" ... />
.
Current Behavior
The testProp
is not passed.
Steps to Reproduce
Code to reproduce the issue: https://codesandbox.io/s/5z8xqoozzn
/* eslint-disable react/prefer-stateless-function */
import React from "react";
import NumberFormat from "react-number-format";
import PropTypes from "prop-types";
import { withStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
const styles = theme => ({
container: {
display: "flex",
flexWrap: "wrap"
},
formControl: {
margin: theme.spacing.unit
}
});
function NumberFormatCustom(props) {
const { inputRef, onChange, testProp, ...other } = props;
// THIS SHOULD BE "YO" but is undefined instead
console.log("testProp", testProp);
return (
<NumberFormat
{...other}
ref={inputRef}
onValueChange={values => {
onChange({
target: {
value: values.value
}
});
}}
thousandSeparator
prefix="$"
/>
);
}
NumberFormatCustom.propTypes = {
inputRef: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired
};
class FormattedInputs extends React.Component {
state = {
textmask: "(1 ) - ",
numberformat: "1320"
};
handleChange = name => event => {
this.setState({
[name]: event.target.value
});
};
render() {
const { classes } = this.props;
const { textmask, numberformat } = this.state;
return (
<div className={classes.container}>
<TextField
className={classes.formControl}
label="react-number-format"
value={numberformat}
onChange={this.handleChange("numberformat")}
id="formatted-numberformat-input"
InputProps={{
inputComponent: NumberFormatCustom,
testProp: "yo"
}}
/>
</div>
);
}
}
FormattedInputs.propTypes = {
classes: PropTypes.object.isRequired
};
export default withStyles(styles)(FormattedInputs);
Context
There seems to be some discussion about TextField
having too complex an API and targetting only 80% of the use cases, e.g. #9326. IMHO, the behavior looks like a bug (or I’m doing something wrong, because after reading the code the InputProps
seem to be passed correctly.
Your Environment
Tech | Version |
---|---|
Material-UI | v1.4.2 |
React | 16.4.1 |
browser | N/A |
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Other InputProps are not applied to InputProps.inputComponent
This is a v1.x issue. I have searched the issues of this repository and believe that this is not a duplicate. Expected Behavior....
Read more >React - Material UI - TextField controlled input with custom ...
The problem is that you are defining inline the component type for the inputComponent prop. This means that with each re-render it will...
Read more >Input Components - React-admin - Marmelab
An Input component displays an input, or a dropdown list, a list of radio buttons, etc. Such components allow to update a record...
Read more >Select API - Material UI - MUI
Name Type Default
autoWidth bool false
children node
classes object
Read more ><input>: The Input (Form Input) element - HTML
The HTML element is used to create interactive controls for ... If this attribute is not specified, the default type adopted is text...
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 FreeTop 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
Top GitHub Comments
My bad, that’s indeed the case, the proper way to do this is:
Please try this ,it worked for me