Overview
HasThemeElement provides methods for reading and asserting the theme attribute on Vaadin components. The theme attribute is used to apply visual variants to components, such as different button styles (primary, secondary, tertiary) or field appearances (small, minimal).
Interface Location: org.vaadin.addons.dramafinder.element.shared.HasThemeElement
Methods
getTheme()
theme attribute.
Returns: String - The theme attribute value, or null if not set
assertTheme()
theme attribute matches the expected value. When null is provided, asserts that the theme attribute is absent.
The expected theme value, or
null to assert absenceAssertionError if the theme does not match or is present when null is expected
Implementing Classes
The following element classes implementHasThemeElement:
TextFieldElement(and all subclasses)AvatarElementCardElementDetailsElementDialogElementGridElementMenuBarElementMenuElementMenuItemElementMessageListElementNotificationElementPopoverElementProgressBarElementSplitLayoutElement
Usage Example
Theme Variants
Vaadin components support various theme variants through thetheme attribute. Common variants include:
Button Themes
primary- Primary action button (prominent styling)secondary- Secondary action (less prominent)tertiary- Tertiary action (minimal styling)error- Destructive actions (red)success- Positive actions (green)contrast- High contrast stylingicon- Icon-only button stylingsmall- Smaller size variant
Field Themes
small- Compact field sizehelper-above-field- Helper text above fieldalways-float-label- Label always in floating position
Grid Themes
no-border- Remove bordersno-row-borders- Remove row borders onlycolumn-borders- Add column bordersrow-stripes- Alternating row colorscompact- Reduced paddingwrap-cell-content- Allow text wrapping
Component-Specific Themes
- Avatar:
large,small,xsmall - Details:
filled,reverse,small - Notification:
primary,success,warning,error
Implementation Details
Null Handling
TheassertTheme() method properly handles null values to assert the absence of a theme attribute:
Multiple Theme Values
Vaadin components can have multiple theme variants applied simultaneously, separated by spaces:theme attribute works like CSS classes, allowing multiple space-separated values.
Testing Patterns
Test Theme Variants
Test Combined Themes
Test Default (No Theme)
Theme-Based Visual Testing
Best Practices
Use Semantic Theme Names
When testing themes, use the semantic names that match your UI design system:Test Responsive Variants
Some themes may change based on screen size or container:Verify Theme Consistency
Ensure related components use consistent theming:Related Interfaces
- HasStyleElement - For CSS class-based styling