-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v6] fields losing focus after first onChange #1094
Comments
** FACE PALM *** My bad, just traced it through the stack and discovered that it was simply re-rendering the component... DUH ITS STATLESS Basically for those who want to know we are cutting our boiler plate by creating a component to wrap error validation, label and other stuff. Also saves on our build size of course :-)
|
It is not the explanation. http://redux-form.com/6.0.0-alpha.13/examples/material-ui/ |
I have this issue only in [email protected] |
I have this same issue in
|
component={ username => this.generateInput(username) } You can't do this. This is constructing a new component function on every render. It must be component={ this.generateInput } |
Exactly I also met this issue in [email protected] This issue should be be reopened, @andrewmclagan |
@spaceoi It should not. Please read the release note of v6.0.0-alpha.14. |
@ooflorent I've read several times but haven't seen any notice about losing focus bug. |
By the way, in my another application everything works fine, I implemented both them at the same time, but in one case this bug present, in another not. And I have no idea why so and how to debug this. |
The losing focus bug is not a bug. It's the expected React behavior. If you are defining your component as an arrow function on every |
@beornborn Related discussions: #961, #961 (comment) and #961 (comment) |
@ooflorent But why then another changes of this field don't remove focus, and other changes of other fields don't remove focus. And I tried implementation without arrow functions - the same problem. And I didn't change anything, just downgraded the version to 13, and everything works fine! |
This is an issue. Could you create a minimal sample to reproduce this and paste it here (or link a gist) ? |
@ooflorent ok, I'll do it in few hours |
@ooflorent But I reproduced situation when it works on 6.0.13 with arrow links. |
Wow. I'm having this issue too! When I type the first char, it loses focus, after that it doesn't. |
Thanks @ooflorent |
Causes form fields to lose focus. Icky. But, now fixed! See: https://github.com/erikras/redux-form/releases/tag/v6.0.0-alpha.14 and redux-form/redux-form#1094
Some more clarification for anyone struggling:
Those are my observations. I don't know if the last one is expected behaviour, so use at your own risk as maybe it will break in the future? EDIT: Still unsure how to get |
any suggestion on this on version 6.0.0-rc.3 having the same issue EDIT: To pass custom props to your renderInput function outside of the class, add them to the In your function
|
I encountered the same problem with material-ui and using a form in a dialog. import React, {Component} from 'react';
import TextField from 'material-ui/TextField';
const TextInput = props =>
<TextField errorText={props.touched && props.error}
{...props.input}
/>;
export default TextInput <Field name="my_field" component={TextInput} type="text" placeholder="My placeholder" value={this.props.my_value || ''}/> |
If anyone still gets this error, please check this issue. |
The example in the migration guide: Specifically this line:
is not valid JSX because of the <Field> inside the comment. |
I'm using last version 6.5.0
|
Hi @xander9112, |
@gustavohenke I am getting the same issue and here is a small example of my implementation. I am getting this only when I wrap the component in a HOC (which in my case is Popup.jsx). Can you tell me where I am going wrong? I am loosing the focus on the first onChange in the TextField.
and this is how I am using the TextField component:
just for reference, this is my popup.jsx
Here is what i am getting in the redux dev tools: |
For me it was |
What's the status of this ticket and why it's closed? I still have this issue in v.7. |
@ooflorent Do you know how to solve this problem? Fields losing focus after first onChange, so I stopped using class & "react": "^15.6.1",
"redux": "^3.7.2",
"redux-form": "^7.0.3", ./src/view/ViewSignin/FormSignin.js 'use strict';
import React, { Component } from 'react';
import Radium from 'radium';
import { Link } from 'react-router-dom';
import {
Field,
reduxForm
} from 'redux-form';
const renderField = ({
input,
type,
label
}) => (
<div>
<input { ...input } type={ type } placeholder={ label } />
</div>
);
const FormSignin = (props) => {
const { handleSubmit } = props;
return (
<form className='frm-signin' onSubmit={ handleSubmit }>
<div className='border-box xy-center row field-area'>
<div className='fields'>
<Field
name="userAccount"
component={ renderField }
type="text"
label='电子邮件 / 手机号'/>
<i></i>
<Field
name="userPassword"
component={ renderField }
type="password"
label='密码'/>
</div>
</div>
<div className='border-box xy-center row button-area'>
<div>
<button
type="submit">
<span className='xy-center'>
登录
</span>
</button>
</div>
</div>
<div className='border-box row others-area'>
<Field
className='chk-keep-signin'
name="keepSignin"
id="keep-signin"
component="input"
type="checkbox"
/>
<label className='lbl-keep-signin' htmlFor="keep-signin">
保持登录
</label>
<Link className='right btn-signup'
to='signin'>
立即注册
</Link>
<Link className='right clean-link btn-forget-password'
to='signin'>
忘记密码
</Link>
</div>
</form>
);
}
export default reduxForm({
form: 'signin'
})(FormSignin); |
If you still have this problem, you're probably trying to send some properties to your component and you are mistakenly doing it by passing them as arguments to the function in front of the component.
which regenerates the component every time (which seems like the component is just losing focus). The correct way is to use the
Then inside
|
I am not passing props, not using a function in render and I still have this problem. |
try to wrap the class component with the CSSModules inside reduxForm instead of using decorator |
This particular component and its parents are not using css modules. |
Thanks @i6mi6. It was
|
I had the same problem with an html table in which I have input text lines in a column. inside a loop I read a json object and I create rows in particular I have a column with inputtext.
var trElementList = (function (list, tableComponent) {
});
|
I just came across the same issue. Reading this blog helped me fixing it, thank you OkNoah! |
I had the same problem trying to pass down a prop to my custom react native input like: <Field
name="email"
component={props => <EmailField dark {...props} />}
/> Solved this way: <Field
name="email"
dark
component={EmailField}
/> I changed the place of |
It's worked to me too) Rerender - this is the clue. |
You have helped someone 4 years after this comment, thank you :) |
included the next code in tag input:
Before:
After:
|
To everyone who are facing this issue currently or might be in future, of onChange not firing inside a component that we are firing by rendering that component into other component, I found a temporary solution that I'm writing down here. But I still wanna know why we can't use setState inside this onChange function. If there's any solution with anyone, please do let me know. Thanks! FYI - @andrewmclagan import "./styles.css";
import React, { useState, useEffect } from "react";
import { TextArea } from "carbon-components-react";
export default function App() {
let updatedArray = [];
const [testArray, setTestArray] = useState(updatedArray);
const Test = (props) => {
const { id, sampleText } = props;
return (
<div>
<TextArea
name="sampleText"
id="sampleText"
onChange={(e) => {
const { name, value } = (e && e.target) || {};
const editArray = testArray.map((item) => {
return item;
});
editArray[id][name] = value;
updatedArray = editArray;
}}
defaultValue={sampleText}
/>
</div>
);
};
const viewFinal = () => {
console.log(testArray);
// you can send the updatedArray to backend here if needed
};
const add = () => setTestArray([...testArray, {}]);
// useEffect(() => {
// receive adat from backend and set to current array state here
// setTestArray(dataFromBackend)
// },[])
return (
<div className="App">
<button onClick={(e) => add(e)}>add</button>
{testArray && Array.isArray(testArray) && testArray.length > 0 && (
<div>
{testArray.map((items, id) => {
const { sampleText = "" } = items || {};
return <Test id={id} sampleText={sampleText} />;
})}
</div>
)}
<button onClick={viewFinal}>view Curr Array</button>
</div>
);
} To view it in action, go over to - https://codesandbox.io/s/optimistic-mopsa-m12wmv Thank you. |
Using version
6.0.0-alpha.13
we are encountering behaviour that is hard to debug.Rendering
<Field />
components that have thecomponent={props => ...
syntax we experience the following: On entering text into theinput
field, it loses focus after the first key press.This behaviour does not occur when rendering the component as:
<Field component="input" type="text" />
OR after the first character is inserted and any field is refocusedThe
onChange
event and all other event inherited through context seem to be there when inspect. Test with both versions6.0.0-alpha.13
and6.0.0-alpha.14
. Dependancies that may / may not be effecting the issue: react-bootstrap, react 15.1.0.There seem to be issues with focus changing on various other circumstances, tabs also not jumping to the correct component.
The text was updated successfully, but these errors were encountered: