Use input element's value directly

Since we're keeping the input as a ref anyway, let's use that rather than
requiring the value to be passed to `validate`. This allows others to call
`validate` as well.
This commit is contained in:
J. Ryan Stinnett 2019-04-18 17:37:07 +01:00
parent 5d95c31875
commit 778697abf1

View file

@ -55,7 +55,6 @@ export default class Field extends React.PureComponent {
onFocus = (ev) => { onFocus = (ev) => {
this.validate({ this.validate({
value: ev.target.value,
focused: true, focused: true,
}); });
// Parent component may have supplied its own `onFocus` as well // Parent component may have supplied its own `onFocus` as well
@ -66,7 +65,6 @@ export default class Field extends React.PureComponent {
onChange = (ev) => { onChange = (ev) => {
this.validate({ this.validate({
value: ev.target.value,
focused: true, focused: true,
}); });
// Parent component may have supplied its own `onChange` as well // Parent component may have supplied its own `onChange` as well
@ -77,7 +75,6 @@ export default class Field extends React.PureComponent {
onBlur = (ev) => { onBlur = (ev) => {
this.validate({ this.validate({
value: ev.target.value,
focused: false, focused: false,
}); });
// Parent component may have supplied its own `onBlur` as well // Parent component may have supplied its own `onBlur` as well
@ -90,10 +87,11 @@ export default class Field extends React.PureComponent {
this.input.focus(); this.input.focus();
} }
validate({ value, focused }) { validate({ focused }) {
if (!this.props.onValidate) { if (!this.props.onValidate) {
return; return;
} }
const { value } = this.input;
const { valid, feedback } = this.props.onValidate({ const { valid, feedback } = this.props.onValidate({
value, value,
focused, focused,