-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: Extra Checkbox and Radio focus events #8567
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
base: main
Are you sure you want to change the base?
Conversation
Build successful! 🎉 |
labelProps, | ||
pressProps, | ||
useMemo(() => ({ | ||
onMouseDown: e => e.preventDefault() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
Can you write a description of the issue and how this solves it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is fine but it technically deviates from native behavior if the label was rendered in such a way that it didn't wrap the input (aka in that case a blur on the input happens every time the label is clicked).
Build successful! 🎉 |
Build successful! 🎉 |
@LFDanLu I'm not sure I follow. I've provided a useCheckbox story with a separate label and input. Let me know if you're expecting something else for the behaviour. |
Build successful! 🎉 |
Build successful! 🎉 |
@snowystinger right, so at the moment clicking on the label in the story you added won't trigger extra blur events due to the again, this is probably fine IMO |
I see, but that behaviour doesn't change whether or not the label is separate or wrapping. |
Closes #8045
If a checkbox or radio is already focused, pressing on the element a second time will call onBlur (since it is technically the label getting pressed, not the actual input).
Because focus happens in
mousedown
, we can prevent default to stop focus from going to the label, this doesn't interfere with focus moving to the input itself which happens inclick
.✅ Pull Request Checklist:
📝 Test Instructions:
Test by going to RAC's checkbox/radio stories with focus/blur actions. Click the label for the component multiple times, you should only see one set of events
🧢 Your Project: