Skip to content
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

events on input like onChange, onBlur get called twice #57

Closed
queckezz opened this issue Mar 21, 2016 · 7 comments
Closed

events on input like onChange, onBlur get called twice #57

queckezz opened this issue Mar 21, 2016 · 7 comments

Comments

@queckezz
Copy link
Contributor

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

@jxnblk
Copy link
Member

jxnblk commented 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.

@rbvea
Copy link

rbvea commented Apr 4, 2016

Just chiming in that this does occur when binding an onClick function to Checkbox

@bmcmahen
Copy link

bmcmahen commented Apr 6, 2016

I can confirm that this also happens for events like onKeyDown, onKeyPress for Input.

@dispalt
Copy link

dispalt commented Apr 14, 2016

Im willing to take a stab at this, what do you think would be the best way to go with it, desugar all the event names, or do something like @queckezz described?

@jxnblk
Copy link
Member

jxnblk commented Apr 14, 2016

I think I'd prefer desugaring. I also would like tests for events – something I started but didn't have time to wrap up.

@anton6
Copy link

anton6 commented May 10, 2016

Currently experiencing this issue with <Select /> and <Input />. Is there any progress on this? Thanks.

@theseyi
Copy link

theseyi commented May 22, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants