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.

events on input like `onChange`, `onBlur` get called twice

See original GitHub issue

Hey @jxnblk, awesome library!

When using the <Input /> component, event handlers always get called twice. This is because you capture all events into rootProps and after that you apply them to two <Base />components

  const {
    rounded,
    backgroundColor,
    theme,
    inverted,
    // event handlers go into this variable
    ...rootProps
  } = props

// later
<Base
  // applies onClick, onBlur etc.
  {...rootProps}
>
  // applies onClick, onBlur etc. again
  <Base
    {...props}
    type='input'
  >
  </Base>
</Base>

My best advice is to switch to something like a rootProps prop on Input and then delegate the rest of the props to the Input component. I can create a pull request if you agree with that.

const Input = ({
  label,
  name,
  type,
  message,
  hideLabel,
  children,
  rootProps,
  ...props
}, { rebass }) => {
  const {
    rounded,
    backgroundColor,
    theme,
    inverted
  } = props

  return (
    <Base
      {...rootProps}
      >

      <Base
        {...props}
      />
        {message && <Text small children={message} />}
    </Base>
  )
}

Another option would be to filter out all events and delegate them to the second <Base />. This would require a list of events though.

EDIT: Same problem exists for <Select />

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jxnblkcommented, Mar 23, 2016

Thanks! This probably also affects Textarea, Checkbox, and Radio. I tend to think certain props should just be explicitly passed to the form control, but let me think about possible solutions for this.

If you want to take a stab at a PR (maybe just start with one component), I’d be happy to take a look at what you’re suggesting.

0reactions
theseyicommented, May 22, 2016

This probably affect most rebass elements with DOM events since most inherit from Base.

Read more comments on GitHub >

github_iconTop Results From Across the Web

double actuating onblur event - javascript - Stack Overflow
It seems like a bug to me, and I don't know what can be done about it. ... to another application), then Chrome...
Read more >
onBlur called twice · Issue #1547 · Hacker0x01/react-datepicker
Expected behavior onBlur to be called once. Actual behavior onBlur is called twice. Once with event and second time without event.
Read more >
Fire OnChange only once - Telerik UI for Blazor
Description. I observe twice firing onchange event in dropdownlist or other inputs. I want the event to fire only once when the user...
Read more >
React.js:- The best way to handle the onChange event on ...
So the advantage of using onBlur is that the event handler will be called only once when the user moves out from the...
Read more >
JavaScript Events Examples - W3Schools
Examples of using JavaScript to react to events. Input Events. onblur - When a user leaves an input field onchange - When a...
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