Skip to content

Commit

Permalink
fix: define Input render
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Apr 7, 2020
1 parent 09d07f4 commit f72a66b
Showing 1 changed file with 8 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from "react";
import { I18NValue } from "@webiny/app-i18n/components";
import HelperMessage from "../components/HelperMessage";
import { CmsContentModelModelField } from "@webiny/app-headless-cms/types";
import { BindComponentRenderProp } from "@webiny/form";
import { Input as UiInput } from "@webiny/ui/Input";

type Props = {
type?: string;
Expand All @@ -11,39 +11,14 @@ type Props = {
};

const Input = (props: Props) => {
const { onChange, value, validation, validate } = props.bind;

// @ts-ignore
const onBlur = (e: SyntheticInputEvent<HTMLInputElement>) => {
if (validate) {
// Since we are accessing event in an async operation, we need to persist it.
// See https://reactjs.org/docs/events.html#event-pooling.
e.persist();
validate();
}
};

return (
<div className="webiny-fb-form-field webiny-fb-form-field--input">
<label className="webiny-pb-typography-body webiny-fb-form-field__label">
<I18NValue value={props.field.label} />
</label>
<input
onBlur={onBlur}
onChange={e => onChange(e.target.value)}
value={value}
placeholder={I18NValue(props.field.placeholderText)}
type={props.type}
name={props.field.fieldId}
id={props.field.fieldId}
className="webiny-fb-form-field__input"
/>
<HelperMessage
isValid={validation.isValid}
errorMessage={validation.message}
helperMessage={<I18NValue value={props.field.helpText} />}
/>
</div>
<UiInput
{...props.bind}
label={I18NValue(props.field.label)}
placeholder={I18NValue(props.field.placeholderText)}
type={props.type}
className="webiny-fb-form-field__input"
/>
);
};

Expand Down

0 comments on commit f72a66b

Please sign in to comment.