The reason to use role=“list” and role=“listitem”?

后端 未结 2 1919
你的背包
你的背包 2021-02-20 14:42

Are there any benefits of using the following code?

2条回答
  •  旧时难觅i
    2021-02-20 15:12

    The answer is yes, assistive technologies work well when correct semantic markup is used for structuring the document. If it is a simple static list then there is no need to mark them with the roles.

    For example: Consider the role="listitem" whose baseConcept is defined as HTML li. And the baseConcept HTML li is almost identical to the role="listitem" definition except for the fact that it does not inherit any properties. More info

    Thus, consider the following example:

    
       
    • Carrot
    • Tomato
    • Lettuce
    Asparagus

    Here the page author wants to use aria-level property for the li. Even though aria-labelledby and aria-owns can be applied to all elements of base markup, aria-level property requires that the element have some role. Since ARIA spec uses Web Ontology Language (OWL) to represent the roles in a class hierarchy. OWL describes these roles as classes along with their states and properties. So inorder to use a aria-level the element has to be defined some role as plain HTML li will not inherit any properties or limitations. Once you mark the role as listitem it requires that listitem be owned by an element with role="list". So you end up using both the roles.

    On the other hand roles are also useful if semantic markup is also not used. For example:

    dog
    cat
    sparrow
    wolf!

    Here the screen reader software will indicate the ARIA list (made up of divs) as any other normal HTML list.

提交回复
热议问题