From f2da833ac991b2fbeac4a10c1e5fe030f95d7c71 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 9 Apr 2019 16:10:36 +0100 Subject: [PATCH] Fix validation to avoid `undefined` class on fields The class name handling for validation inadvertently added `undefined` as a class when validation is not used. This rearranges the logic to avoid the issue. Fixes https://github.com/vector-im/riot-web/issues/9345 --- src/components/views/elements/Field.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/components/views/elements/Field.js b/src/components/views/elements/Field.js index daf6ec0ce1..12e20ad789 100644 --- a/src/components/views/elements/Field.js +++ b/src/components/views/elements/Field.js @@ -86,20 +86,13 @@ export default class Field extends React.PureComponent { prefixContainer = {prefix}; } - let validClass; - if (onValidate) { - validClass = classNames({ - mx_Field_valid: this.state.valid === true, - mx_Field_invalid: this.state.valid === false, - }); - } - const fieldClasses = classNames("mx_Field", `mx_Field_${inputElement}`, { // If we have a prefix element, leave the label always at the top left and // don't animate it, as it looks a bit clunky and would add complexity to do // properly. mx_Field_labelAlwaysTopLeft: prefix, - [validClass]: true, + mx_Field_valid: onValidate && this.state.valid === true, + mx_Field_invalid: onValidate && this.state.valid === false, }); // handle displaying feedback on validity