@@ -625,6 +625,7 @@ getByRole(
625
625
checked?: boolean ,
626
626
pressed?: boolean ,
627
627
queryFallbacks?: boolean ,
628
+ level?: number ,
628
629
}): HTMLElement
629
630
```
630
631
@@ -635,7 +636,7 @@ attribute. Here you can see
635
636
[ a table of HTML elements with their default and desired roles] ( https://www.w3.org/TR/html-aria/#docconformance ) .
636
637
637
638
Please note that setting a ` role ` and/or ` aria-* ` attribute that matches the
638
- implicit ARIA semantics is unnecessary and is ** not recomended ** as these
639
+ implicit ARIA semantics is unnecessary and is ** not recommended ** as these
639
640
properties are already set by the browser, and we must not use the ` role ` and
640
641
` aria-* ` attributes in a manner that conflicts with the semantics described. For
641
642
example, a ` button ` element can't have the ` role ` attribute of ` heading ` ,
@@ -787,6 +788,8 @@ cy.findByRole('dialog').should('exist')
787
788
788
789
<!-- END_DOCUSAURUS_CODE_TABS-->
789
790
791
+ #### ` queryFallbacks `
792
+
790
793
By default, it's assumed that the first role of each element is supported, so
791
794
only the first role can be queried. If you need to query an element by any of
792
795
its fallback roles instead, you can use ` queryFallbacks: true ` .
@@ -803,6 +806,53 @@ roles and therefore match the same element.
803
806
> roles get introduced and you want to start supporting those as well as older
804
807
> environments that don't understand that role (yet).
805
808
809
+ #### ` level `
810
+
811
+ An element with the ` heading ` role can be queried by any heading level
812
+ ` getByRole('heading') ` or by a specific heading level using the ` level ` option
813
+ ` getByRole('heading', { level: 2 }) ` .
814
+
815
+ The ` level ` option queries the element(s) with the ` heading ` role matching the
816
+ indicated level determined by the semantic HTML heading elements ` <h1>-<h6> ` or
817
+ matching the ` aria-level ` attribute.
818
+
819
+ Given the example below,
820
+
821
+ ``` html
822
+ <body >
823
+ <section >
824
+ <h1 >Heading Level One</h1 >
825
+ <h2 >First Heading Level Two</h2 >
826
+ <h3 >Heading Level Three</h3 >
827
+ <div role =" heading" aria-level =" 2" >Second Heading Level Two</div >
828
+ </section >
829
+ </body >
830
+ ```
831
+
832
+ you can query the ` Heading Level Three ` heading using
833
+ ` getByRole('heading', { level: 3 }) ` .
834
+
835
+ ``` js
836
+ getByRole (' heading' , { level: 1 })
837
+ // <h1>Heading Level One</h1>
838
+
839
+ getAllByRole (' heading' , { level: 2 })
840
+ // [
841
+ // <h2>First Heading Level Two</h2>,
842
+ // <div role="heading" aria-level="2">Second Heading Level Two</div>
843
+ // ]
844
+ ```
845
+
846
+ While it is possible to explicitly set ` role="heading" ` and ` aria-level `
847
+ attribute on an element, it is ** strongly encouraged** to use the semantic HTML
848
+ headings ` <h1>-<h6> ` .
849
+
850
+ To learn more about the ` aria-level ` property, see
851
+ [ ARIA ` aria-level ` ] ( https://www.w3.org/TR/wai-aria-1.2/#aria-level ) .
852
+
853
+ > The ` level ` option is _ only_ applicable to the ` heading ` role. An error will
854
+ > be thrown when used with any other role.
855
+
806
856
### ` ByTestId `
807
857
808
858
> getByTestId, queryByTestId, getAllByTestId, queryAllByTestId, findByTestId,
0 commit comments