-
Notifications
You must be signed in to change notification settings - Fork 10
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
Fix for focus appearing on mousedown of checkbox labels #2640
Conversation
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.
Nice one - but the focus styles are needed for small screens.
Can you make sure the focus style works there and maybe only include the tabindex on that.
Bear in mind that the MOJ JS component can be configured to toggle the filter on big screens regardless. So the inclusion of the tabindex should be based on this too and not just screen size (matchmedia).
@adamsilver updated with my revised solution - the wider component can now show correct focus styles - but you won't get a weird flash when users click the checkbox. |
85b572a
to
77a5369
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.
LGTM — one comment re comments!
@@ -36,7 +36,9 @@ | |||
</div> | |||
<% end %> | |||
|
|||
<div class="moj-filter__options"> | |||
<!-- Div made focusable to 'catch' focus from checkboxes. see https://github.com/DFE-Digital/apply-for-teacher-training/pull/2640 |
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.
No need for this comment here or in the CSS — GitHub's merge commit will include the PR reference & we'll be able to get back to it from the diff. Possibly the rationale ought to go into the commit message.
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.
@duncanjbrown normally I'd agree - but in this case I think what I'm doing is unexpected and it might be helpful to note this is intentionally weird.
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.
As you like!
Context
Quick for this issue. Because the filter has
tabindex="-1"
, it briefly gets focus each mousedown on a checkbox label.My fix involves having a second focusable element inside the one we already have. That element has focus styles suppressed. When a user clicks on a checkbox label, it receives focus, but nothing visually changes. When they release their cursor, the checkboxes are focused as normal.
As that second element has
tabindex="-1"
users can't normally tab in to it. As our main filter has normal focus styles, it looks correct when the popover is opened.Before
After
Note I've raised an issue upstream with the MOJ design system about the issue.
Other changes
I fixed the incorrect focus styling on the filter component.