Adding onFocus to an input element doesn't focus and swallows first click when clicking on an element
See original GitHub issueThe gif below shows the issue. If you notice after adding onFocus={input.onFocus}
it takes longer to focus the input text element and this is because I have to click twice.
Code individuals.js
import React, {PropTypes} from "react"
import {Field, reduxForm, FieldArray} from 'redux-form'
import Individual from './Individual'
import {DropdownList} from 'react-widgets'
import {DateField} from 'react-date-picker'
const Individuals = ({fields}) => {
const renderField = ({input, label, type, meta: {touched, error}}) =>
<div>
<label>{label}</label>
<div>
<input
value={input.value}
onChange={input.onChange}
onBlur={input.onBlur}
onFocus={input.onFocus}
type={type}
placeholder={label}/>
{touched && error && <span>{error}</span>}
</div>
</div>
return (
<div>
<ul>
<li>
<button type="button" onClick={() => fields.push({})}>Add Spouse or Child</button>
</li>
{fields && fields.map((individual, index) =>
<li key={index}>
<button
type="button"
onClick={() => fields.remove(index)}>Remove Individual
</button>
<Field
name={individual + '.firstName'}
type="text"
component={renderField}
label="First Name"/>
-----------------------------------------------------
</li>
)}
</ul>
</div>)
}
Individuals.propTypes = {
fields: PropTypes.object
}
export default Individuals
the above code is called by this code
import React, {PropTypes} from 'react'
import {reduxForm, FieldArray} from 'redux-form'
import Individuals from './Individuals'
let MyNeeds = ({handleSubmit, onMyNeedsFormSubmit}) => {
return (
<div>
<form onSubmit={handleSubmit(onMyNeedsFormSubmit)}>
<h1>I need coverage for</h1>
<FieldArray name='individuals' component={Individuals}/>
<button type="submit">Submit</button>
</form>
</div>
)
}
MyNeeds.propTypes = {}
const validate = values => {
const errors = {}
return errors
}
export default MyNeeds = reduxForm({
form: "myNeedsForm",
validate
}
)(MyNeeds)
Screen Capture
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:8
Top Results From Across the Web
Why is tab keypress causing focus change also triggering ...
Two things needed is: 1: resetting tabPressed in the inputs onKeyup, cause the key events happening inside the input wont bubble up to...
Read more >Scrollable area does not get focus with TAB focus navigation
If scrollable area becomes focused via TAB focus navigation or click, does it become focused element? 3. While focus is on some input...
Read more >When onClick of your Buttons are not fired after onChange of ...
The reason may be that onchange is triggered when the focus of the input field is lost, and when the dialog is opened...
Read more >Keyboard Events. Focusing. Navigation - Webix
Tab, Tab+Shift - moves focus to the next/previous clickable element/input ... If no item is selected at the moment, the first visible item...
Read more >gnome - Non-focused windows not responding to mouse clicks
Wow, I think I may have at least found a workaround fix. I went to system monitor found the Gnome shell and killed...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ah… the classic error of having the component within the render function 😃
Have a look here: https://codesandbox.io/s/x703v0kj4z Basically, all you needed to do was move the
renderField
outside theIndividuals
component.There are plenty of material around our GitHub issues and StackOverflow too why this is wrong.
Sure!
Enough? 😄