-
Notifications
You must be signed in to change notification settings - Fork 210
Add toggle mechanism for docs.rs source sidebar #1464
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
Conversation
static/source.js
Outdated
@@ -0,0 +1,34 @@ | |||
(function() { | |||
function showSourceFiles(button, sideMenu, sourceCode) { | |||
button.getElementsByClassName("pure-menu-link")[0].childNodes[0].textContent = "< "; |
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.
Hmm, could you maybe add a title-text of "collapse" (and "expand" for the other)? This seems not great for accessibility.
Actually, @ahicks92 do you know how this is normally done for screen-readers? I assume this will read out as "left arrow" which doesn't seem ideal.
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 can't figure out how to get a test link out of the pr; is there a way to do that?
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.
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 think you want aria-label
. You'd also want aria-expanded I think. Unfortunately this is tentative: let's say that I'm 70% confident. Fortunately, I think most screen reader users would be able to figure this out even without changes, though improving this is definitely a good idea.
Not 100% on whether or not title
is relevant, but probably not the end of the world to add one. I think that title ends up being togglable and counted as a tooltip or something like that, not entirely replacing the text of the button in all contexts.
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 a followup to that note that aria-expanded
if done right is going to make it obvious that the button expands or collapses something, and the common mistake is working the action into the label (e.g. "expand table of contents" as the label becomes "expand table of contents button collapsed" for example, which is irrelevant info).
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.
Ah, it's IPv6 only. I can maybe throw cloudflare in front of it to get an IPv4 reverse proxy 🤔.
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.
Using cloudflare as a reverse proxy is a little more annoying than I expected, but hopefully this works now: https://ipvold-docs-rs-dev.nemo157.com/crate/tokio-util/0.6.7/source/src/codec/decoder.rs
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.
@ahicks92: Let's go for aria-label
, title
and aria-expanded
. :)
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.
That's not a button tag. Missed that in my review somehow. The labeling stuff only works on items of the right role. The easiest (read: bug-free) way here is to use a button tag outside the list instead, but if we're willing to possibly accept bugs on some platforms then adding role="button"
might or might not work. Unfortunately screen readers get buggy around edge cases, and "li tagged as button inside a list" seems like one. I hacked it in via the inspector with Firefox+NVDA and it seems to work for me. If there's a reason we need to keep it this way rather than using a proper button we can try it and I'll do some more testing on the combinations I have access to.
note also that non-button buttons etc. like this need tabindex=0 for keyboard accessibility; you can't tab to them by default either.
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 plan to use a button
, for now it was mostly validating the UI (but I think it's ok now so I'll update it).
@@ -438,7 +438,7 @@ div.package-page-container { | |||
margin-top: 0; | |||
} | |||
|
|||
a.pure-menu-link { | |||
.pure-menu-link { |
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.
Hmm, why did this change?
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.
Because I wanted to use the style of this class in the "collapse" button.
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.
The classes don't entirely work on a non-link, if you click and drag it selects the text inside instead of dragging a button around like the other links.
Because I don't know otherwise where to keep the button to "expand" the sidebar. Edit: I got an idea: simply hide the links and only keep the button. |
f02fbe4
to
9148411
Compare
Updated the UI a bit and added the aria attributes. I also updated the video to show what the new UI looks like. |
Updated my server, looks nicer to me 😁 https://fontawesome.com/v5.15/icons/chevron-left?style=solid and -right might look good next to the filetype icons? |
Why not! I think @jyn514 didn't like just having "<"/">" but maybe I misunderstood. If they're happy with it, I will use the fontawesome icon instead. |
9148411
to
7633294
Compare
I replaced with font-awesome icons and now use a button. |
If @Nemo157 updates their server I'll check it again. The code looks right, though do we know if it's valid HTML to put buttons inside list elements? I didn't think so, and "isn't valid HTML" is often a good proxy for breaks with some screen reader somewhere. |
I tested this HTML on the w3c validator: <!DOCTYPE html>
<html lang="en">
<head>
<title>hello</title>
</head>
<body>
<ul>
<li><button>yolo</button></li>
</ul>
</body>
</html> No warning or error, so I guess it's fine. 😄 |
@ahicks92 it's updated |
Yeah, that works. Maybe "hide" in the label/title, because "collapse source sidebar expanded" is a bit awkward, but that's very much a NIT. |
7633294
to
bab13f5
Compare
@ahicks92 No it makes sense because I used "Show" in for expanding it. So I replaced "collapse" with "hide". |
It's easy to do but I'd prefer to do it in a follow-up for a simple reason: it's a behaviour change. So I'd prefer for people to confirm whether they want it or not on this specific part. I'll send a PR for it once this one is merged. |
Fixes #1445
Showing how it works in video:
Peek.2021-08-17.14-09.mp4