events on input like `onChange`, `onBlur` get called twice
See original GitHub issueHey @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:
- Created 8 years ago
- Comments:7 (2 by maintainers)
Top 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 >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 FreeTop 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
Top GitHub Comments
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.
This probably affect most rebass elements with DOM events since most inherit from Base.