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

Add tabindex to highlight template func markup #7194

Closed
gpanders opened this issue Apr 20, 2020 · 6 comments
Closed

Add tabindex to highlight template func markup #7194

gpanders opened this issue Apr 20, 2020 · 6 comments
Milestone

Comments

@gpanders
Copy link

@gpanders gpanders commented Apr 20, 2020

Code blocks generated through the {{ highlight }} shortcode or through the use of Markdown code fences should have the tabindex="0" attribute, allowing them to be tab focusable. This is good for accessibility; see here.

I've searched through the docs and I cannot find any way to set this attribute myself in my own site, since the highlight shortcode is (apparently) built-in to Hugo, so I don't think there is any way to do this outside of a change to Hugo itself.

@gpanders gpanders changed the title Scrollable highlighted code blocks should be focusable Scrollable highlighted code blocks should be tab focusable Apr 20, 2020
@bep bep added Enhancement and removed Proposal labels Apr 21, 2020
@bep bep changed the title Scrollable highlighted code blocks should be tab focusable Add tabindex to highlight shortcode markup Apr 21, 2020
@bep
Copy link
Member

@bep bep commented Apr 21, 2020

so I don't think there is any way to do this outside of a change to Hugo itself.

You can copy this into your project:

https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/shortcodes/highlight.html

@bep
Copy link
Member

@bep bep commented Apr 21, 2020

Never mind that comment, I see that the shortcode is just delegating to the internal template func.

@bep bep added this to the v0.70 milestone Apr 21, 2020
@bep bep changed the title Add tabindex to highlight shortcode markup Add tabindex to highlight template func markup Apr 21, 2020
@bep bep removed this from the v0.70 milestone Apr 28, 2020
@bep bep added this to the v0.71 milestone Apr 28, 2020
@bep bep removed this from the v0.71 milestone May 18, 2020
@bep bep added this to the v0.72 milestone May 18, 2020
@bep bep removed this from the v0.72 milestone May 31, 2020
@bep bep added this to the v0.73 milestone May 31, 2020
@bep bep removed this from the v0.73 milestone Jun 23, 2020
@bep bep added this to the v0.74 milestone Jun 23, 2020
@bep bep removed this from the v0.74 milestone Jul 13, 2020
@bep bep added this to the v0.75 milestone Jul 13, 2020
@bep bep removed this from the v0.75 milestone Sep 14, 2020
@bep bep added this to the v0.76 milestone Sep 14, 2020
@bep bep removed this from the v0.76 milestone Oct 6, 2020
@bep bep added this to the v0.77 milestone Oct 6, 2020
@bep bep removed this from the v0.77 milestone Oct 30, 2020
@bep bep added this to the v0.78 milestone Oct 30, 2020
@faraixyz
Copy link

@faraixyz faraixyz commented Dec 1, 2020

The internal function wraps the code in a div tag.

fmt.Fprint(w, `<div class="highlight">`)
if err := formatter.Format(w, style, iterator); err != nil {
return "", err
}
fmt.Fprint(w, `</div>`)

Would it be possible to move this to the short code?

{{ if len .Params | eq 2 }}{{ highlight (trim .Inner "\n\r") (.Get 0) (.Get 1) }}{{ else }}{{ highlight (trim .Inner "\n\r") (.Get 0) "" }}{{ end }}

That way users have more flexibility in wrapping the generated pre block.

@faraixyz
Copy link

@faraixyz faraixyz commented Mar 4, 2021

Hey again, I was thinking of this again since #8280 with attribute lists for code fences. Would it be possible to have a way to specify default attributes for code fences?

@bep bep removed this from the v0.78 milestone Apr 23, 2021
@bep bep added this to the v0.83 milestone Apr 23, 2021
@bep bep removed this from the v0.83 milestone May 3, 2021
@bep bep added this to the v0.84 milestone May 3, 2021
rhymes added a commit to rhymes/hugo that referenced this issue May 23, 2021
rhymes added a commit to rhymes/hugo that referenced this issue May 23, 2021
Currently the generated `<pre>` element isn't fully accessible as it can't be focused by keyboard users.
To make this fully accessible, the attribute `tabindex="0"` should be added to the `<pre>` tag.

Closes gohugoio#7194
@sephore
Copy link

@sephore sephore commented Jun 8, 2021

Browsers like Firefox will allow scrollable elements to be tab focusable by default, so maybe it's a browser-level issue? I've been injecting tabindexes with replaceRE as a temporary workaround for Chrome users and etc, but it really sounds like a hack.

Edit: Oh yeah. And while using tabindex, Firefox is the one complaining about accessibility. 🤣 (Even tho it works fine.)

By forcing tabindex in ALL elements (even if not scrollable), the issue becomes "Focusable elements should have interactive semantics".

@rhymes
Copy link
Contributor

@rhymes rhymes commented Jun 8, 2021

@sephore I have opened a PR to fix it here #8568 - I used Firexo and generated a demo Hugo site with highlighting and I wasn't able to focus on <pre>, you need that for accessibility purposes, see the documentation in the PR

@bep bep removed this from the v0.84 milestone Jun 18, 2021
@bep bep added this to the v0.85 milestone Jun 18, 2021
@bep bep removed this from the v0.85 milestone Jul 5, 2021
@bep bep added this to the v0.86 milestone Jul 5, 2021
@bep bep closed this in #8568 Jul 15, 2021
bep pushed a commit that referenced this issue Jul 15, 2021
Currently the generated `<pre>` element isn't fully accessible as it can't be focused by keyboard users.
To make this fully accessible, the attribute `tabindex="0"` should be added to the `<pre>` tag.

Closes #7194
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants