Skip to main content

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()

Retrieves the current value of the theme attribute. Returns: String - The theme attribute value, or null if not set

assertTheme()

Asserts that the theme attribute matches the expected value. When null is provided, asserts that the theme attribute is absent.
String
The expected theme value, or null to assert absence
Throws: AssertionError if the theme does not match or is present when null is expected

Implementing Classes

The following element classes implement HasThemeElement:
  • TextFieldElement (and all subclasses)
  • AvatarElement
  • CardElement
  • DetailsElement
  • DialogElement
  • GridElement
  • MenuBarElement
  • MenuElement
  • MenuItemElement
  • MessageListElement
  • NotificationElement
  • PopoverElement
  • ProgressBarElement
  • SplitLayoutElement

Usage Example

Theme Variants

Vaadin components support various theme variants through the theme 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 styling
  • icon - Icon-only button styling
  • small - Smaller size variant

Field Themes

  • small - Compact field size
  • helper-above-field - Helper text above field
  • always-float-label - Label always in floating position

Grid Themes

  • no-border - Remove borders
  • no-row-borders - Remove row borders only
  • column-borders - Add column borders
  • row-stripes - Alternating row colors
  • compact - Reduced padding
  • wrap-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

The assertTheme() method properly handles null values to assert the absence of a theme attribute:
This allows you to verify that no theme has been applied to a component.

Multiple Theme Values

Vaadin components can have multiple theme variants applied simultaneously, separated by spaces:
The 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: