ByLabelText
import Tabs from '@theme/Tabs' import TabItem from '@theme/TabItem'
getByLabelText, queryByLabelText, getAllByLabelText, queryAllByLabelText, findByLabelText, findAllByLabelText
This will search for the label that matches the given TextMatch, then find the element associated with that label.
The example below will find the input node for the following DOM structures:
<Tabs defaultValue="native" values={[ { label: 'Native', value: 'native', }, { label: 'React', value: 'react', }, { label: 'Cypress', value: 'cypress', }, ] }>
The example above does NOT find the input node for label text broken up by elements. You can use getByRole('textbox', { name: 'Username' }) instead which is robust against switching to aria-label or aria-labelledby.
If it is important that you query an actual <label> element you can provide a selector in the options:
Note
getByLabelText will not work in the case where a for attribute on a <label> element matches an id attribute on a non-form element.