Interface HasAriaLabel
- All Superinterfaces:
HasElement
,Serializable
- All Known Implementing Classes:
AbstractNumberField
,Anchor
,BigDecimalField
,Button
,Checkbox
,CheckboxGroup
,ComboBox
,ComboBoxBase
,DatePicker
,DrawerToggle
,EmailField
,GridMenuItem
,Image
,Input
,IntegerField
,ListBox
,ListBoxBase
,Main
,MenuItem
,MenuItemBase
,MultiSelectComboBox
,MultiSelectListBox
,NativeButton
,Nav
,NumberField
,PasswordField
,RadioButtonGroup
,RangeInput
,Select
,Tab
,TextArea
,TextField
,TextFieldBase
,TimePicker
The default implementation set the aria-label and aria-labelledby of the
component to the given HasElement.getElement()
. Override all methods in this
interface if the aria-label and aria-labelledby should be added to some other
element.
The purpose of aria-label is to provide the user with a recognizable name of the component. If the label text is visible on screen, aria-labelledby should be used and aria-label should not be used. There may be instances where the name of an element cannot be determined programmatically from the content of the element, and there are cases where providing a visible label is not the desired user experience. In the cases where a visible label or visible tooltip is undesirable, aria-label may be used to set the accessible name of the component.
Don't include both. If both are present on the same element, aria-labelledby will take precedence over aria-label.
See: https://www.w3.org/TR/wai-aria/#aria-label
See: https://www.w3.org/TR/wai-aria/#aria-labelledby
Note: The aria-label and aria-labelledby attributes are not valid on every component, see https://www.w3.org/TR/using-aria/#label-support for more details.
- Since:
- Author:
- Vaadin Ltd
-
Method Summary
Modifier and TypeMethodDescriptionGets the aria-label of the component.Gets the aria-labelledby of the componentdefault void
setAriaLabel
(String ariaLabel) Set the aria-label of the component to the given text.default void
setAriaLabelledBy
(String ariaLabelledBy) Set the aria-labelledby of the component.Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
-
Method Details
-
setAriaLabel
Set the aria-label of the component to the given text.This method should not be used if
setAriaLabelledBy(String)
is also used. If both attributes are present, aria-labelledby will take precedence over aria-label.- Parameters:
ariaLabel
- the aria-label text to set ornull
to clear
-
getAriaLabel
Gets the aria-label of the component.- Returns:
- an optional aria-label of the component if no aria-label has been set
-
setAriaLabelledBy
Set the aria-labelledby of the component. The value must be a valid id attribute of another element that labels the component. The label element must be in the same DOM scope of the component, otherwise screen readers may fail to announce the label content properly.This method should not be used if
setAriaLabel(String)
is also used. If both attributes are present, aria-labelledby will take precedence over aria-label.- Parameters:
ariaLabelledBy
- the string with the id of the element that will be used as label ornull
to clear
-
getAriaLabelledBy
Gets the aria-labelledby of the component- Returns:
- an optional aria-labelledby of the component if no aria-labelledby has been set
-