react icon indicating copy to clipboard operation
react copied to clipboard

Input losing focus on re render in IE9

Open evandegr opened this issue 11 years ago • 0 comments

So this works fine in Chrome etc, but has issues in IE9. Basically I have an onValidChange event that is fired when the form becomes either valid or invalid, which sets a state. In IE, when the onValidChange fires, it re-renders the form and I lose focus on the input. I've seen people having similar problems but have been unable to find a good solution. Important parts of the class look a bit like this:

renderLogin () {
    var self = this;

    return (
        <Form
            method="POST"
            ref={LOGIN_FORM_REF}
            onValidChange={self.checkLoginValid.bind(this)}
            allowDirtyUnmount={true}>
            <div className={self.loginFormClassName()}>
                <div className="login-form-inner-container">
                {self.renderError()}
                    <Input
                        label="Email"
                        id="email"
                        type="text"
                        name="email"
                        key="email"
                        popoverValidationTrigger="onBlur"
                        validationRules={self.rules.email}
                    />

                    <Password
                        label="Password"
                        id="password"
                        name="password"
                        key="password"
                        popoverValidationTrigger="onBlur"
                        validationRules={self.rules.password}
                        onKeyUp={this.passwordKeyUp.bind(this)}
                    />

                    <div className="login-helpers">
                        <Checkbox
                            id="remember"
                            name="remember"
                            className="remember"
                            label="Remember me"
                            includeMsgs={false}
                        />

                        <a
                            className="forgot"
                            onClick={self.showForgotPassword.bind(this)}>Forgot Password?</a>
                    </div>
                </div>

                <hr />

                <Button
                    type="button"
                    onClick={self.login.bind(this)}
                    disabled={!self.loginIsValid()}
                    className= {self.loginButtonClassName()}>Login</Button>
            </div>
        </Form>
    );
}
render () {
    var self = this;
    console.log('re-rendering');

    return (
        <Page app="login" headers={false}>
            <div className={self.className()}>
                <div className="logo-container">
                    <Icon name="logo" />
                </div>
                <div className="form-wrapper">
                    {self.renderLogin()}
                    {self.renderResetPassword()}
                    {self.renderEmailSent()}
                </div>
            </div>
        </Page>
    );
}
loginIsValid () {
    return this.state.loginValid;
}
checkLoginValid () {
    var loginForm = this.refs[LOGIN_FORM_REF],
    isValid = loginForm.isValid();

    console.log('chcking login valid');

    this.setState({loginValid: isValid});
}

evandegr avatar Aug 25 '15 17:08 evandegr