question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding onFocus to an input element doesn't focus and swallows first click when clicking on an element

See original GitHub issue

The 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 reduxformfocusissue

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:8

github_iconTop GitHub Comments

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found