-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[typescript] Allow custom props for custom inputComponent
- Loading branch information
Showing
2 changed files
with
49 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as React from 'react'; | ||
import { AnyComponent } from '@material-ui/core'; | ||
import Input from '@material-ui/core/Input'; | ||
|
||
// asd is not a native element | ||
const WrontNativeName = <Input inputComponent="asd" />; // $ExpectError | ||
|
||
const NativeInput = <Input inputComponent="input" />; | ||
|
||
const NativeInputWithProps = ( | ||
<Input inputComponent="input" inputProps={{ readOnly: true, size: 5 }} /> | ||
); | ||
|
||
const UnknownPropWarning = ( | ||
<Input | ||
inputComponent="input" | ||
inputProps={{ | ||
inputRef: {}, // $ExpectError | ||
}} | ||
/> | ||
); | ||
|
||
interface CustomInputProps { | ||
suggestion: string; | ||
} | ||
const CustomInputComponent: AnyComponent = props => { | ||
return <input placeholder={props.suggestion} />; | ||
}; | ||
|
||
// inputProps is still optional even if Props is not empty | ||
const WithBadInputComponentProps = <Input inputComponent={CustomInputComponent} />; | ||
const WithInputComponent = ( | ||
<Input | ||
inputProps={{ | ||
suggestion: 'testing', | ||
}} | ||
inputComponent={CustomInputComponent} | ||
/> | ||
); |