whatwg / html

HTML Standard
https://html.spec.whatwg.org/multipage/
Other
8.11k stars 2.67k forks source link

Consider allowing <hr> within list elements (ol, ul, menu) #9126

Open scottaohara opened 1 year ago

scottaohara commented 1 year ago

I saw that https://github.com/whatwg/html/pull/9124 was made today, and it reminded me that I had been wanting to file this issue for some time.

Late last year, I was working with developers who wanted to 'group' their list items, but did not want to include nested lists as they reasonably did not want to expose 3 nested lists within a larger list. Rather, as they were visually delineating the groupings of list items by a horizontal separator, they thought to use an hr element. But as that was not valid HTML, they then did <li role=separator>. But that role is also an invalid child of a list element, or element with role=list.

Their other option was to nest the hr within an li element, but that included it in the total count of list items, which was not their intent.

They finally settled on <li aria-hidden=true><hr></li> to mitigate the validation errors, and to ensure the separator did not contribute to the list item count total, but at the loss of exposing any separator semantics.

As HTML updated to allow div to group dt and dd elements, and per the mentioned PR #9124 to allow hr within select, it seems reasonable that ol, ul and menu elements should also allow hr as a way to separate li elements into 'groups'. There doesn't appear to be a parsing issue with this now, but as my testing (from oct 2022) shows, there are presently some inconsistencies with how AT handles the separator. But these inconsistencies could be ironed out if this was an allowed pattern, as opposed to the current behavior which is essentially mitigating author 'error'.

iDad5 commented 1 year ago

I'm not sure if this is the right place to address my thoughts, so please excuse if I’m doing it wrong, and please don't hesitate to guide me into a better direction. I strongly second this proposal, but I'd like to suggest that a more flexible/powerful separator element inside list elements would be preferable.

In case you have a list of – for example – events that happen regularly, a separator that marks the start of a year or month could be very useful. Splitting the list, in my opinion, isn't semantically correct as the list elements are of the exact same nature, regardless of the date they are held. If the list gets long, a separator that can hold useful information like the year in my case would be preferable to a simple


.

shannonmoeller commented 6 months ago

As HTML updated to allow div to group dt and dd elements, and per the mentioned PR https://github.com/whatwg/html/pull/9124 to allow hr within select, it seems reasonable that ol, ul and menu elements should also allow hr as a way to separate li elements into 'groups'.

Couldn't agree more.

MGSimard commented 1 month ago

This should be a prime classic example which supports this idea, from nearly 30 years ago. image