Last active
June 12, 2019 14:49
-
-
Save martinmckenna/a3c7f261225c44b74ccb9d0f69f892e6 to your computer and use it in GitHub Desktop.
MUI Errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react' | |
import TextField, { Props as TextFieldProps } from 'src/TextField' | |
type Props = TextFieldProps & { | |
hideHelperText?: boolean; | |
}; | |
class PasswordInput extends React.Component<Props> { | |
onChange = (e: React.ChangeEvent<HTMLInputElement>) => { | |
/** do stuff */ | |
}; | |
render() { | |
const { | |
hideHelperText, | |
classes, | |
...rest | |
} = this.props; | |
return ( | |
<React.Fragment> | |
<TextField | |
/** errors out here */ | |
/* | |
Type 'HideShowText | null' is not assignable to type 'HTMLDivElement | null'. | |
Type 'HideShowText' is missing the following properties from type 'HTMLDivElement': | |
align, addEventListener, removeEventListener, accessKey, and 238 more | |
*/ | |
{...rest} | |
onChange={this.onChange} | |
/> | |
{!hideHelperText && 'hello world'} | |
</React.Fragment> | |
); | |
} | |
} | |
export default PasswordInput; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import TextField, { | |
StandardTextFieldProps as TextFieldProps | |
} from '@material-ui/core/TextField'; | |
type ClassNames = | |
| 'root' | |
const styles = (theme: Theme) => | |
createStyles({ | |
root: {}, | |
}); | |
interface BaseProps { | |
tooltipText?: string; | |
dataAttrs?: Record<string, any> | |
} | |
export type Props = BaseProps & TextFieldProps | |
type CombinedProps = Props & | |
WithStyles<ClassNames>; | |
class MyTextField extends React.Component<CombinedProps> { | |
render() { | |
const { | |
children, | |
tooltipText, | |
dataAttrs, | |
/** everything else that goes on the root */ | |
...textFieldProps | |
} = this.props; | |
return ( | |
<div | |
> | |
<TextField | |
{...textFieldProps} | |
{...dataAttrs} | |
> | |
{this.props.children} | |
</TextField> | |
{tooltipText && <HelpIcon text={tooltipText} />} | |
</div> | |
); | |
} | |
} | |
const styled = withStyles(styles); | |
export default compose<CombinedProps, Props>( | |
styled | |
)(MyTextField); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment