mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-16 18:26:16 +01:00
add disabled option to input field
This commit is contained in:
@@ -11,7 +11,8 @@ type Props = {
|
|||||||
onChange: string => void,
|
onChange: string => void,
|
||||||
onReturnPressed?: () => void,
|
onReturnPressed?: () => void,
|
||||||
validationError: boolean,
|
validationError: boolean,
|
||||||
errorMessage: string
|
errorMessage: string,
|
||||||
|
disable?: boolean
|
||||||
};
|
};
|
||||||
|
|
||||||
class InputField extends React.Component<Props> {
|
class InputField extends React.Component<Props> {
|
||||||
@@ -40,21 +41,33 @@ class InputField extends React.Component<Props> {
|
|||||||
return "";
|
return "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
handleKeyPress = (event: SyntheticKeyboardEvent<HTMLInputElement>) => {
|
handleKeyPress = (event: SyntheticKeyboardEvent<HTMLInputElement>) => {
|
||||||
const onReturnPressed = this.props.onReturnPressed;
|
const onReturnPressed = this.props.onReturnPressed;
|
||||||
if (!onReturnPressed) {
|
if (!onReturnPressed) {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
if (event.key === "Enter") {
|
if (event.key === "Enter") {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
onReturnPressed();
|
onReturnPressed();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { type, placeholder, value, validationError, errorMessage } = this.props;
|
const {
|
||||||
|
type,
|
||||||
|
placeholder,
|
||||||
|
value,
|
||||||
|
validationError,
|
||||||
|
errorMessage,
|
||||||
|
disable
|
||||||
|
} = this.props;
|
||||||
const errorView = validationError ? "is-danger" : "";
|
const errorView = validationError ? "is-danger" : "";
|
||||||
const helper = validationError ? <p className="help is-danger">{errorMessage}</p> : "";
|
const helper = validationError ? (
|
||||||
|
<p className="help is-danger">{errorMessage}</p>
|
||||||
|
) : (
|
||||||
|
""
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<div className="field">
|
<div className="field">
|
||||||
{this.renderLabel()}
|
{this.renderLabel()}
|
||||||
@@ -63,15 +76,13 @@ class InputField extends React.Component<Props> {
|
|||||||
ref={input => {
|
ref={input => {
|
||||||
this.field = input;
|
this.field = input;
|
||||||
}}
|
}}
|
||||||
className={ classNames(
|
className={classNames("input", errorView)}
|
||||||
"input",
|
|
||||||
errorView
|
|
||||||
)}
|
|
||||||
type={type}
|
type={type}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={this.handleInput}
|
onChange={this.handleInput}
|
||||||
onKeyPress={this.handleKeyPress}
|
onKeyPress={this.handleKeyPress}
|
||||||
|
disabled={disable}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{helper}
|
{helper}
|
||||||
|
|||||||
Reference in New Issue
Block a user