add help to input field

This commit is contained in:
Maren Süwer
2018-10-02 09:43:41 +02:00
parent 8eb2c273ca
commit 829583bdd0
4 changed files with 33 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
//@flow
import React from "react";
import classNames from "classnames";
import {Help, Page} from "../index";
type Props = {
label?: string,
@@ -12,7 +13,8 @@ type Props = {
onReturnPressed?: () => void,
validationError: boolean,
errorMessage: string,
disabled?: boolean
disabled?: boolean,
helpText?: string
};
class InputField extends React.Component<Props> {
@@ -41,6 +43,17 @@ class InputField extends React.Component<Props> {
return "";
};
renderHelp = () => {
const helpText = this.props.helpText;
if(helpText){
return (
<div className="control columns is-vcentered">
<Help message={helpText} />
</div>);
}
else
return null;
}
handleKeyPress = (event: SyntheticKeyboardEvent<HTMLInputElement>) => {
const onReturnPressed = this.props.onReturnPressed;
@@ -71,19 +84,22 @@ class InputField extends React.Component<Props> {
return (
<div className="field">
{this.renderLabel()}
<div className="control">
<input
ref={input => {
this.field = input;
}}
className={classNames("input", errorView)}
type={type}
placeholder={placeholder}
value={value}
onChange={this.handleInput}
onKeyPress={this.handleKeyPress}
disabled={disabled}
/>
<div className="field is-grouped">
<div className="control is-expanded">
<input
ref={input => {
this.field = input;
}}
className={classNames("input", errorView)}
type={type}
placeholder={placeholder}
value={value}
onChange={this.handleInput}
onKeyPress={this.handleKeyPress}
disabled={disabled}
/>
</div>
{this.renderHelp()}
</div>
{helper}
</div>