question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Erroneous: "List items (<li>) are not contained within <ul> or <ol> parent elements."

See original GitHub issue

Provide the steps to reproduce

  1. Run an accessibility audit on https://app.nxtboard.com/meetings/nxtboard-sqa/

What is the current behavior?

Error:

List items (<li>) are not contained within <ul> or <ol> parent elements.

Screen Shot 2019-09-06 at 1 11 14 PM

What is the expected behavior?

This error does not appear. The <li>s in question are definitely contained inside a <ul> element.

Screen Shot 2019-09-06 at 1 21 14 PM

Environment Information

  • Affected Channels: DevTools
  • Lighthouse version: I don’t know. Chrome version is 76.0.3809.132 (Official Build) (64-bit).
  • Node.js version: n/a
  • Operating System: macOS 10.14.6

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
robdodsoncommented, Sep 7, 2019

It does appear their guide is incorrect according to axe. If the role=“tab” were on the li elements instead of the a elements it would pass.

What happens if you put role=presentation on the li element? That should essentially remove it from the accessibility tree.

By manually annotating role=X we are providing that semantic meaning for screen readers, so there should not be a disadvantage compared to ul/li AFAIK.

Yep, that’s correct. It’s also worth noting that, in Safari at least, if you change the display of a list then they throw out its semantics anyway (see the last comment in this ticket).

I think over the years it became a common practice to put navigation into ul/li elements, but that practice probably predates ARIA and has just stuck around. Since you’re redefining the semantics with ARIA it doesn’t matter much what the underlying HTML element is in this case.

1reaction
elijah-schowcommented, Sep 6, 2019

@patrickhulce It looks like Axe reports the same issue. I think your hypothesis might be right. Setting their role to "tab" fixes the issue, but I think the anchor tags are supposed to have that role instead of the list items.

I can also work around the issue by using div’s instead of list items:

Replacing the <ul> and <li> elements with <div>s fixes the issue:

<div role="tablist" class="nav nav-tabs card-header-tabs">
    <div class="nav-item">
        <a href="#"  class="nav-link active" role="tab">Upcoming</a>
    </div>
    <div class="nav-item">
        <a href="#" class="nav-link" role="tab">Previous</a>
    </div>
</div>

This doesn’t match Bootstrap 4’s suggested markup, but maybe their guide is wrong? Is there is disadvantage to using divs instead of list items?

Read more comments on GitHub >

github_iconTop Results From Across the Web

<li> elements must be contained in a <ul> or <ol> | Axe Rules
List items may be contained in either unordered (bullet) lists or ordered ... All list items ( li ) must be contained within...
Read more >
Failing accessibility audit when a ol element has a role
List items ( <li> ) are not contained within <ul> or <ol> parent elements. This error message is not explicit. Implicit role for...
Read more >
List items (<li>) are not contained within <ul> or <ol> parent ...
At first glance it makes sense to me that the role=group is there on the ul element, yet such attributes and roles are...
Read more >
Why should li be contained within ul or ol parent elements?
List items such as <li> must be contained within parent <ul> or <ol>. ... If list elements <li> are not contained in parent...
Read more >
Accessibility rule: <ul> and <ol> must only directly contain <li ...
Lists must be correctly marked up, which means they cannot contain content components other than li elements. Lists are read aloud in a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found