-
Notifications
You must be signed in to change notification settings - Fork 338
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
Add checkbox mousedown event handler #2827
Conversation
cf159fa
to
f303a67
Compare
f303a67
to
7aa216b
Compare
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.
This looks all cushty to me.
The outcome is a little different in Safari. Previously Safari wouldn't show the yellow outline at all, as the focus state wasn't triggered by click events. With this change, it now shows the yellow outline during the mousedown/active state.
That's not a blocker as far as I'm concerned, but just in case someone raises that checkboxes are 'flashing' yellow on Safari, going forwards...
Relatedly: Technically this is also an issue with radio buttons if you click the same one multiple times. That's not how radio buttons are intended to be used, however, so also not a big deal, IMO. |
@querkmachine Good spots. The safari note gives me pause as we're essentially recreating the issue but for safari only. We could consider it a safari bug but it's known and they've said they wont fix it. I'm gonna investigate if there's an alternative that could cover safari, including @edwardhorsford's original solution, although IMO we've reduced the scope of the problem and this feels more like a safari problem than a problem with the component now. |
@owenatgov PR works well for me I think. It would be nice if the same fix could be applied to radios too to make them consistent. |
Although it's somewhat an edge case, because the active and focused elements can be different, you can end up with two elements that look focused. (If you click a checkbox label, keep the mouse button held, and tab, you'll end up with both the checkbox you're clicking and the checkbox that are focused in the 'focus state') Generally, I'm a bit nervous about applying the focus state to something that isn't explicitly focused. |
@36degrees I think my original solution didn't have the same issue - as it made the parent thing get focus, and then styled based on that. Otherwise I still think I'd go with this - as it's a visual glitch you get on all mouse-downs of labels (albeit not very noticeably) vs a much rarer behaviour of mouse-down and tab. But then looking more wrong. |
When clicking the label of an associated checkbox, focus breifly moves away from the checkbox creating a small visual bug where the focus styles disappear from the checkbox. To fix this, we check for mousedowns on a given checkbox, check if the element being clicked is a label and stop default behaviour with zevent.preventDefault()`
7aa216b
to
aa22e1c
Compare
An update on where we are with this.
Based on the above, @querkmachine I'm going to reject your review for now (thanks all the same!) |
One thing I'll mention is where I first discovered this was because of the more obvious visual glitch you get if the checkboxes are contained in a focusable container. |
@edwardhorsford Correct me if I'm wrong but it looks like that instance you mentioned, specifically the wider issue around the focusable filter element mentioned in ministryofjustice/moj-design-system#39, is intended to give keyboard users a way to skip to the filters from another part of the page. In that case, we'd recommend using js to give that containing element focus programatically ( |
Closing this PR along with the linked issue. Reasons detailed in comment on the issue #1906 (comment) |
Fixes #1906
Handles the visual bug mentioned in the issue using a
mousedown
event handler that targets checkbox labels. More details can be found in the commit message.Thanks to @edwardhorsford for his investigation into this issue and original PR #1907