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

Sidenav toggle button triggers on spacebar press #5084

Merged
merged 6 commits into from May 21, 2024

Conversation

jmuzina
Copy link
Member

@jmuzina jmuzina commented May 7, 2024

Done

Changes all uses of a.p-side-navigation__toggle and a.p-side-navigation__toggle--in-drawer to <button> elements and removed href attribute

Fixes #4559, WD-11071

QA

Check if PR is ready for release

If this PR contains Vanilla SCSS code changes, it should contain the following changes to make sure it's ready for the release:

  • PR should have one of the following labels to automatically categorise it in release notes:
    • Feature 🎁, Breaking Change 💣, Bug 🐛, Documentation 📝, Maintenance 🔨.
  • Vanilla version in package.json should be updated relative to the most recent release, following semver convention:
    • if CSS class names are not changed it can be bugfix relesase (x.x.X)
    • if CSS class names are changed/added/removed it should be minor version (x.X.0)
    • see the wiki for more details
  • Any changes to component class names (new patterns, variants, removed or added features) should be listed on the what's new page.

Screenshots

Screenshot 2024-05-07 at 1 44 28 PM

@webteam-app
Copy link

@jmuzina jmuzina changed the title Accessibility fix: Change sidenav toggle links to buttons Sidenav toggle button triggers on spacebar press May 7, 2024
@jmuzina jmuzina marked this pull request as ready for review May 7, 2024 21:55
@bartaz
Copy link
Contributor

bartaz commented May 8, 2024

I had a suspicion there was a reason why we used a link instead of the button there:

.p-side-navigation:target &,
[class*='p-side-navigation--']:target &,

So it turns out originally we did have a button to toggle side navigation, but it was changed to links so that it can be opened just via CSS (:target) in #3065

So it seems we have 2 conflicting accessibility concerns here: do we want to make it accessible without JS, or do we want to make it accessible via required keys for button, which requires JS.

@bartaz
Copy link
Contributor

bartaz commented May 8, 2024

So, how I see our options:

A) using links (leave as is) - it's accessible without JS (assuming people build it correctly with link opening it having the id of the drawer in href), but it's not fully accessible via keyboard (as it doesn't support space key).

B) using buttons (this PR) - it's fully accessible via keyboard natively, but requires JS. For users without JS side navigation will be unavailable on small screens (they will not be able to expand it).

C) using links with additional JS to make space key work - it's accessible without JS (assuming href/id are set up correctly) and via additional JS works with keyboard as well (although not natively).

While the C) solution seems to cover the most cases, it's also most complicated and relies on many assumptions (href/id properly linked, and JS needed to handle keyboard)

I looked around for some reference, but (as usual in accessibility) there is no definitive answer. This article (https://webaim.org/techniques/javascript/#reliance) suggests that most of users have JS enabled, so the JS version needs to be accessible for sure. So it seems we would be doing a better job by using option B) with a button, and making it accessible for most of the cases.

The question remains, what to do with noJS users. And again, it's not that side navigation is completely unavailable without JS - it's still in the document, visible on large screens. Only on small screens, when it's collapsed, it would not be opened (without JS). So switching to button would solve one issue (keyboard accessibility), and introduce another one (arguabely smaller or less common issue), of expanding side nav without JS.

@bartaz
Copy link
Contributor

bartaz commented May 9, 2024

@petermakowski Hey, any opinions on this from accessibility standpoint?

@petermakowski
Copy link
Contributor

@petermakowski Hey, any opinions on this from accessibility standpoint?

TLDR; I also think that using a button (and relying on JS) seems like the best choice.

Using a link with added JavaScript to handle spacebar on small screens (most likely a touchscreen device without a keyboard) is definitely not worth additional complexity.

The percentage of users with JavaScript disabled on small screens is likely very low. It's hard to find exact stats, but in various studies it comes at an average of 1% (but that's for all screen sizes). For mobile devices is probably even lower, the vast majority of mobile browsers have JS enabled by default.

@bartaz
Copy link
Contributor

bartaz commented May 10, 2024

Let's remove the CSS that uses :target selector then, and keep it as a button.

@jmuzina jmuzina removed the request for review from lyubomir-popov May 20, 2024 14:22
Comment on lines 171 to 173
// :target can be used to control the sidenav with an anchor element, but this was removed in PR #5084.
//.p-side-navigation:target &,
//[class*='p-side-navigation--']:target &,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// :target can be used to control the sidenav with an anchor element, but this was removed in PR #5084.
//.p-side-navigation:target &,
//[class*='p-side-navigation--']:target &,

Comment on lines 263 to 265
// :target can be used to control the sidenav with an anchor element, but this was removed in PR #5084.
// .p-side-navigation:target .p-side-navigation__drawer,
// [class*='p-side-navigation--']:target .p-side-navigation__drawer,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// :target can be used to control the sidenav with an anchor element, but this was removed in PR #5084.
// .p-side-navigation:target .p-side-navigation__drawer,
// [class*='p-side-navigation--']:target .p-side-navigation__drawer,

Comment on lines 120 to 122
// :target can be used to control the sidenav with an anchor element, but this was removed in PR #5084.
// .p-side-navigation:target &,
// [class*='p-side-navigation--']:target &,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend to remove commented out code, changes and relevant PRs can be tracked using git history.

Suggested change
// :target can be used to control the sidenav with an anchor element, but this was removed in PR #5084.
// .p-side-navigation:target &,
// [class*='p-side-navigation--']:target &,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. There is no point of keeping commented code. There is a clear reason to remove that.

@petermakowski
Copy link
Contributor

I can confirm this fixes the issue I raised canonical/juju.is#431 (comment)

@jmuzina
Copy link
Member Author

jmuzina commented May 20, 2024

I have a commit ready to remove those comments, just holding the push until @bartaz performs code review on his return (I'd rather not kick off a Percy build from just removing some sass comments) :)

Copy link
Contributor

@bartaz bartaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but let's remove the commented out code.

@jmuzina
Copy link
Member Author

jmuzina commented May 21, 2024

Removed comments & will merge after checks pass

@jmuzina jmuzina added Review: Percy needed This PR needs a review of Percy for visual regressions Review: Percy +1 and removed Review: Percy needed This PR needs a review of Percy for visual regressions labels May 21, 2024
@jmuzina jmuzina merged commit 5ef9ffc into canonical:main May 21, 2024
5 checks passed
@jmuzina jmuzina deleted the sidenav-toggle-links-to-buttons branch May 21, 2024 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Side navigation toggle button doesn't work on space
4 participants