Overview
FocusableElement provides methods for managing keyboard focus on Vaadin components. It allows you to programmatically focus and blur elements, retrieve tab index values, and assert focus state in tests.
Interface Location: org.vaadin.addons.dramafinder.element.shared.FocusableElement
Methods
getFocusLocator()
Locator - The locator to receive focus operations
focus()
blur()
getTabIndex()
tabIndex attribute.
Returns: String - The tab index value, or null if not set
assertIsFocused()
AssertionError if the component is not focused
assertIsNotFocused()
AssertionError if the component is focused
Implementing Classes
The following element classes implementFocusableElement:
ButtonElementCheckboxElementRadioButtonElementTextFieldElement(and all subclasses)ComboBoxElementMultiSelectComboBoxElementSelectElementMessageInputElementGridElementVirtualListElementAvatarElement
Usage Example
Implementation Details
Locator Delegation Pattern
Many components overridegetFocusLocator() to delegate focus operations to an internal element. For example, text fields delegate to their input element:
Tab Index Management
ThegetTabIndex() method retrieves the tabIndex attribute, which controls the tab order of focusable elements:
0- Natural tab order (default for interactive elements)- Positive number - Custom tab order (lower numbers are focused first)
-1- Programmatically focusable but not in tab order
Testing Patterns
Form Navigation Testing
Validation on Blur
Focus After Dialog Open
Testing Autofocus
Best Practices
Use blur() to Trigger Validation
Many Vaadin components perform validation when focus is lost. Always callblur() after setting a value if you want to test validation:
Check Focus State Before Interaction
Before performing keyboard input, ensure the element has focus:Test Tab Order
Verify that users can navigate through your form using the Tab key in the expected order:Related Interfaces
- HasEnabledElement - Disabled elements cannot receive focus
- HasInputFieldElement - Most input fields are focusable
- HasValidationPropertiesElement - Validation often triggers on blur