You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-11-20 16:22:28 +03:00
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:
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user