-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Consider adding a headinglevelstart attribute #5033
Comments
Reading through the other thread, I'd prefer this approach of an opt in instead of just overwriting heading levels. The only question I have is what is the expectation for something like: <h1>GitHub</h1>
<h2>jsdom/jsdom</h2>
<div>
<article headinglevelstart="5">
<h1>jsdom</h1>
<h2>Basic usage</h2>
<h2>Customizing jsdom</h2>
<h3>Simple options</h3>
...
</article>
</div> Expose h5, h6, h7 instead? h7 obviously being the outlier here. Quickly looking at some of the different exposed levels from the platform mappings / trees exposed by browsers, a level 7 should work, but JAWS and NVDA range from getting a little tripped up at times, to JAWS with Firefox just not exposing the levels beyond 6 at all, instead reverting to level 2 or the default level of the heading element used. Again, it seems the screen readers would need to be updated to account for heading levels beyond 6. Unfortunately, that also means that anyone using an older screen reader, even with a newer browser, may well not get optimal output. |
This would solve all my problems with hN tags: user/plugin generated content in templates and template partial that use hN tags. The template including any of the above can just tell it where to start. |
If an author can identify what value needs to be set in Pseudo-code with structure borrowed from above:
In other words, the For example, in this Codepen example from 2016 I use Though neither approach prevents an author from choosing a value that renders as |
@aardrian wrote:
The priority of constituencies puts users and authors before implementors, and this seems to be one of the times when that prioritisation is needed. Authors struggle with heading levels as it is, and this has an impact on users. If we ask authors to take on handling more, I'm afraid things will only get harder for authors and worse for users. If the UA does the work, it has other advantages too:
On this last note, would it be possible to extend the capability of the |
I like how short the "start" attribute is but if it only contains a number in it, it isn't as clear what it is doing as it is on ordered lists. If you have |
In fairness, from a development point of view, using
without having to server-side re-munge the content to reprocess all heading levels appropriately. Otherwise, particularly for third-party stuff, they'd have to always proxy content and do, in naive terms, do a find/replace of any heading elements (either native |
@LJWatson, to your point about the Priority of Constituencies, I feel that pushing the logic to the UA creates a black box that will make it easier for developers to ignore, resulting in a generally worse experience for users. And I also want a better experience for users (over authors). @patrickhlauke, that is a good point (and also made by @LJWatson). And yes, the client-side processing is potentially more burden for users than broken / opaque headings. Perhaps something similar to the code/approach I posted above could be the basis for a polyfill (though it still won't help current SRs). |
This mostly addresses what I was interested in in this comment a while ago - though, it still seems to me we could probably just figure that out with simply a marker attribute rather than an explicit level, and that would be better for authors. Still, this very much seems like progress and worth doing if that's not plausible. |
That is simple for simple cases but it gets more complicated quickly. The approach you outlined works fine within a single template file whose content is all under the control of the author (but, in that limited context, so does just using h-tags, which are also easier to read). Here is where it hurts: When a template includes another template the counter needs to be both threaded through the template and used by the child templates as well. Many templating languages support this, though not all make it super pleasant, but it's not of much use unless the entire project agrees upon the convention. That's easy on greenfield projects but legacy code requires more work or when there's a "parent theme" and you end up needing to modify all of its templates even if you're making no other changes. On hosted platforms the choice of templating language is usually fixed so whether this can be done at all can be out of one's hands. Sometimes html comes from a blackbox plugin. This is no one's favorite but it happens distressingly often. The generated html can be parsed and its headers shifted by walking the AST allowing it to be re-rendered correctly, but this is fairly complicated and slow so it's unlikely to happen and probably needs to be fixed up on the client side with some javascript. If the platform had the concept of the heading level baked into its core and took care of threading it through templates and plugins, all of which agreed to use this feature, this wouldn't be as much of an effort. To my knowledge, there is no such platform or at least it is not among the most commonly used. Even if all the popular ones added it today it would take quite a while for it to see widespread use and for legacy code bases to get on board even if their platform now supported it. That still leaves user-generated content. If it's stored in some non-html source or some IR that can make it easy to generate starting at whatever level is necessary (assuming it's an option: it usually is not). Often it's stored in html that was created by some kind of WYSIWYG editor. If every instance of the user generated content starts at, say, h2, you could configure the header to not allow creating h1 tags. If this is a legacy project or a project going under redesign that means going through the database and parsing all the entries and shifting the headings. Not pleasant but it's a one time thing. If you're trying to use the content where the starting header is different in different contexts you're back to fixing it up on the fly. (I haven't looked into it too deeply yet, but it seems like wordpress's gutenberg would have many of these problems simultaneously). None of this is insurmountable but it's enough to surmount that it doesn't seem to ever get surmounted. Having an attribute may mean occasionally having to add a div to hang it off of but the outlining solutions could also mean having to insert an extraneous tag and generally one of greater semantic weight and its less explicit that those tags are necessary to maintain the correct document outline. An attribute would also make it easier to fix up a legacy codebase with just a few simple edits. Another thing I like about having an attribute is that it could possibly have extra modes in the future like "none" to mean "ignore any headings in this subtree" (useful for teasers whose teased body should not be contributing to the document outline) or something to mean "this came from an editor apply a slower algorithm to shift the headings so that are no gaps like h3 to h6 with no intervening h5". |
@jimmyfrasche, I feel bad that my response is so brief as to seem dismissive, but I understand your points and agree with many. After my last comment I am not pushing my model anymore as I made my case (and nobody seems down with it). But I still think a polyfill may be helpful. |
Notes from TPAC, slide for context. What this proposal do: help web authors prevent user generated content from breaking the page heading structure. To clarify, this is the expected affect: Code <h1>jsdom/jsdom</h1>
<h2>Files</h2>
<h2>README.md</h2>
<div headinglevelstart="3"><!-- user generated content starts -->
<h1>jsdom</h1>
<h2>Basic usage</h2>
<h2>Customizing jsdom</h2>
...
</div>
<h2>About</h2>
<h3>Resources</h3>
<h3>Licenses</h3>
<h2>Releases</h2>
... Heading structure h1 jsdom/jsdom
h2 Files
h2 README.md
h3 jsdom
h4 Basic usage
h4 Customizing jsdom
h2 About
h3 Resources
h3 licenses
h2 Releases with an addition to the proposal: interface HTMLHeadingElement {
[CEReactions] readonly attribute unsigned long level;
}; In case of <div headinglevelstart="2">
<article headinglevelstart="6">
<h1><h1>
<h2 aria-level="1"><h2>
</article>
</div> $ h1.level // AAM level 7
7
$ h2.level // AAM level 1
8
$ h2.ariaLevel
1 Todo:
Future to do:
|
Also discussed at TPAC: need to define how this works with Shadow DOM. Most like the level should be computed based on the shadow including ancestor chain. |
For a lot of use cases, this will probably be fine as long as the headings remain in the 1 to 6 level range. But things are slightly better than I mentioned 4 years ago with browser/screen reader support for levels beyond 6. Safari and Firefox expose the specified level if one goes beyond level 6, but Chrome/Edge appear to cap out at level 9, and beyond that heading levels get exposed as a level 2 regardless of the specified value. Vispero/JAWS would need to be looped in on this, as levels beyond 6 get treated as level 2 - regardless of if the browser exposes the specified level or not. I also noticed that NVDA doesn't include headings between 7 and 9 when navigating with the H key with Chrome, but seems to do it fine with Firefox. So, also something they should be looped in on, as well. I mention all of the above specifically in context to:
Since a polyfill won't be enough without Chrome and Edge/UIA being modified to expose levels beyond 9, and JAWS changing their treatment of higher levels. Fairly recently, the Editor's draft for ARIA included this note for
The important part of that note - as support for higher levels can obviously change with work - is more the fact that the higher the potential heading level, the more difficult the content may be to understand/navigate for someone using a screen reader. So with that said, I'm supportive of the intent behind this attribute and how it can make heading levels easier to adjust for developers when necessary, but was there any talk of a level cap for this attribute at TPAC? Making sure all browsers/screen readers support up to level 9 seems reasonable. That's at least what the ARIA wg discussed when creating that note. But beyond level 9 maybe seems a bit much? Someone being able to declare |
I suspect that as soon as you introduce a reasonable-sounding cap, somebody will come along with a particularly complex document/site that requires one more than the cap... |
I mean, they must be getting by somehow right now, with their six-level limitation, though maybe they're not. so yeah, that's fair point @patrickhlauke. Author guidance to allude to the potential cons then, at least? |
Yes, @mcking65 and @spectranaut was at the WHATWG meeting. Matt brought up exactly this issue. I am personally not opposed to capping the levels but agree as @patrickhlauke said. The level problem was why future to do (as author guidance) was included, since user misuse of the attributes (
Happy to add a cap in a draft spec, but regardless I hope it won't block this proposal, as for the alternative seems to be what led to this proposal to begin with 🙈 .
FWIW my plan was to leave this up to further feedback when I create the polyfill, with capping at 6 or 9, or none. |
thanks @muan - yeh i saw the 'future to do', but i would just submit that author guidance should be added with the proposed spec update and also keep the future to do for checkers to consider adding guidance as well. Whatever guidance is added would be contingent on the decision to cap or not, but that shouldn't be a blocker. |
I've initialized a polyfill with some open issues. Feel free to open issues and let me know if you'd like to be a contributor! I'll carry on with the rest of the to-dos. |
Does not seem that Firefox & Chromium have any inherent CSS formatting for
|
@tomByrer FWIW with this proposal there is never going to be for styling @annevk had previously suggested a functional pseudo-class selector. |
I think we should add |
Would <div headinglevelstart="2">
<h1>Hello</h1>
<div headinglevelstart>
<h1>World</h1>
</div>
</div> Where |
Why only up to level 9? I see having a limit of any kind as an unnecessary restriction on what authors can implement in their layouts. |
Things like Gutenberg (the thing replacing TinyMCE in WordPress) allows you to nest components. So you might have a Keeping track of the last used heading level is also something I am considering but I think it will require re-parsing all preceding content. Any component can render whatever HTML it wants. There isn't a hard requirement that they must use a specific function to render headings or that they must trigger a callback. The only way to determine the previous heading with certainty is by buffering the output and re-parsing it. Exposing |
One potential gotcha with a cumulative <main headingoffset=0>
<h1>Settings</h1>
<section headingoffset=1>
<h1>Profile Settings</h1><!-- this is effectively h2 (1+1) -->
...
</section>
<section headingoffset=1>
<h1>Account Settings</h1><!-- this is effectively h2 (1+1) -->
<button invoketarget=delete_dialog>Delete my account</button>
<dialog id=delete_dialog>
<h1>Delete Account - Are you sure?</h1><!-- this is effectively h2 (1+1) -->
<form method=dialog>
<button type=submit>Yes</button>
</form>
</dialog>
</section>
</main> In this example, ideally the content structure would be h1 "Settings", h2 "Profile Settings", h2 "Account Setings", and the Potential solutions?Unfortunately because Stop TagsAllow elements to stop the tree walk - so if the check sees a let node = this;
let offset = 0;
while (node = node.parentElement) {
if (node.localName == 'DIALOG') break;
offset += node.headingOffset;
} Of course the downsides here are that the Stop AttributeAdding a The downsides being that it's more markup to undo stuff that was already added via markup. Allowing negative headingoffsetWe could allow negative offsets to undo the shift from other elements. In the above example The downsides are more markup, and arguably more confusing markup, as well as this potentially not really solving the problem. The desire here is to reset the headingoffset to Go back to absolute
|
For a modal dialog I don't see what would be gained by doing anything other than always resetting to 0 and I can't think of other places where you would want to do that. Is it possible to just special case modal dialogs? Alt: add |
As a reminder, if we do something special for the |
Seems reasonable to have a |
@smockle and I worked a bit more on the prototype today, as well as a draft spec (the core of the algorithms are here: https://whatpr.org/html/11086/005b463...d43c176/sections.html#heading-levels-&-offsets - so folks who are interested please review and share your thoughts). As it stands:
|
I don't think we should do this without pseudo-classes, as previously mentioned. I also wonder if we can cover these somehow in the user agent style sheet. It seems we could replace |
It would be very easy to sell and specify the pseudo-classes if there's actually impl interest here; the previous attempts just died because nobody picked up the outline algorithm so there was no real point. We do need to be careful about specificity; we have a standing "do it if it proves necessary" to extend |
Very happy to try and specify |
FWIW, I think we essentially want what I specified back in 2018 (in #3499): <dt><dfn data-export="" data-dfn-type="selector"><code
data-x="selector-heading">:heading</code></dfn></dt>
<dt><dfn data-export="" data-dfn-type="selector"><code
data-x="selector-heading-function">:heading()</code></dfn></dt>
<!-- TODO: should these be data-noexport? -->
<dd>
<p>The <code data-x="selector-heading">:heading</code> <span>pseudo-class</span> must match any
element that is a <span data-x="concept-heading">heading</span>.</p>
<p>The <code data-x="selector-heading-function">:heading()</code> functional
<span>pseudo-class</span> accepts a <dfn data-x="selector-heading-function-level">level</dfn>.
<span data-x="selector-heading-function-level">Level</span> must be a positive
<span><integer></span>. The <code data-x="selector-heading-function">:heading()</code>
functional <span>pseudo-class</span> must match any element that is a <span
data-x="concept-heading">heading</span> whose <span>heading level</span> is <span
data-x="selector-heading-function-level">level</span>. <ref spec=CSSVALUES></p>
</dd> (For maximum clarity, heading level above is not impacted by ARIA in any way.) |
I do want it to accept An+B, rather than just an integer, to allow for selecting all headings above/below a certain level, like |
@keithamus In line 55 of the test file, the heading level in the
|
@SaekiTominaga no, that's per design. non-modal |
One thing that came out of the code prototype is that the name if (!element || element->headingReset()) {
// When encountering a headingreset, it's important to return the
// existing accumulated offset, to allow for deeply nested trees having
// children with headingoffsets. Returning to 0 would create a confusing
// structure for authors. Consider a deeply nested structure like:
//
// <div headingreset>
// <h1>First Heading</h1>
// <div headingoffset=1>
// <h1>Second Heading</h1>
// </div>
// </div>
//
// The "First Heading" should be an h1 (h1+reset), but importantly
// the "Second Heading" should be an h2 (h1+offset=1+reset). As it walks
// the tree, it will accumulate the `headingoffset=1`, then land on the
// headingreset, where we hit this line of logic. Our choices are to
// return either `0` or `1` (the accumulated offset). Returning `0` makes
// "Second Heading" an h1, which is the incorrect heading for the ideal
// document structure here. Returning the accumulated offset of 1 makes
// it an h2 which is a better heading structure.
// Ultimately, `headingreset` may be a poor choice of name, and perhaps
// something more like `headingoffsetboundary` better describes the logic
// of this attribute.
return std::min(offset, max_offset);
} As you can see from this comment, I think the main confusion lies in your intution about how the offset is computed; if you're imagining that it walks down the tree then I think we should consider a less confusing name than "reset". Some (poor) suggestons for names to get ideas going:
|
I've been reading through this trying to work out how its confusing but honestly i think you guys are overthinking it. |
To be frank, I don’t quite understand why the new attributes need to start their names with ”heading“ when all the respective element names just have ”h“. ”offset“ is a fine choice for the additive variant. If the absolute variant would be specified, I think ”level“ or ”base“ would work well. The usual offset will probably be If some components or elements need to edles that their heading elements’ levels have to be taken absolutely, I think they establish a root level, which should be exposed in the attribute name. <section hoffset>
<h1>level 2</h1>
<dialog hroot>
<h1>level 1</h1>
</dialog>
</section> |
I prefer the more verbose and explicit At first I thought
"reset" seems to imply the offset is reset to zero, which is not what the code does. I think Alternatively, if we decide to go with Edit: Actually, I keep going back and forth on |
It's a reasonable point, but one I'm personally a little ambivalent to. While html has existing shorthands (
I don't strictly agree. For example we're aiming to integrate this at GitHub for comments, and it'll be
The
Right now if you don't pass a value - or you pass an invalid value - you get
I actually think
|
I mentioned this on mastodon, but might as well drop it in here: any reason why the attributs couldn't be prefixed with |
For consistency with the I don't think |
@oscarotero I think the idea behind @keithamus I'm still not clear on what <h1>A</h1>
<div headingoffset="1">
<h1>B</h1>
<div headingreset>
<h1>C</h1>
<h1>D</h1>
</div>
</div> Per my understanding, the following levels will be used:
But in my mind, "reset" (and even
Which is why I feel "reset" is a misnomer, unless I've completely misunderstood how this attribute works. |
One small concern I have here is that folks might conflate it with
The difference here is that
It's important to note that accumulation happens by walking up the tree, on each heading. Instead consider:
What is |
I'm a bit confused about
Example: <h1>Level 1</h1>
<section headinglevel="relative">
<h1>Level 2</h1>
<h2>Level 3</h2>
<section headinglevel="relative">
<h1>Level 4</h1>
<h2>Level 5</h2>
</section>
<section headinglevel="absolute">
<h1>Level 1</h1>
<h2>Level 2</h2>
</section>
<section headinglevel="3">
<h1>Level 3</h1>
<h2>Level 4</h2>
</section>
<h1>Level 2</h1>
<h2>Level 3</h2>
</section>
<h1>Level 1</h1> |
The current prototype allows for this. You can indeed do something like |
Re: #5033 (comment) What about borrowing from CSS? So |
This is a prototype based on the I2P at https://groups.google.com/a/chromium.org/g/blink-dev/c/8yl-pJhuLHE/m/1GDufCYWAAAJ. Implements the `headingoffset` and `headingreset` attributes as discussed in whatwg/html#5033. The `headingoffset` attribute acts as a cumulative integer that sets the heading level of a heading element to that of its tagname, plus the offset. So a `<h1>` inside a `<div headingoffset=1>` effectively becomes an `<h2>`. These changes are gated behind the 'HeadingOffset' runtime flag which is set to experimental. AX-Relnotes: Added `headingoffset` to `HeadingLevel`. Bug: 333628468 Change-Id: I28619e231619ae8541feeefc39ce4a40c1d92e65 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5445406 Reviewed-by: Kurt Catti-Schmidt <[email protected]> Reviewed-by: Mason Freed <[email protected]> Commit-Queue: Keith Cirkel <[email protected]> Cr-Commit-Position: refs/heads/main@{#1430361}
My reading is that this is the behaviour defined so far. If not, I've misunderstood and what I say next doesn't make sense.
The issue of the name being a misnomer seems to be specific to the implementation, no? From that perspective, yes you're climbing up the tree for the accumulation of the level offsets to find the final level offset to use, and while you're stopping that process when you encounter If this was implemented by climbing down the tree, it would be an instruction to "ignore the accumulated offset so far, use the root level, then carry on accumulating" (which would be less efficient currently), for which If an Having said all that:
|
See the suggestion by @muan at #3499 (comment):
cc @whatwg/a11y
The text was updated successfully, but these errors were encountered: