Skip to main content

Overview

HasPlaceholderElement provides methods for interacting with the placeholder text of Vaadin input components. Placeholders provide hints to users about what to enter in a field and are displayed when the field is empty. Interface Location: org.vaadin.addons.dramafinder.element.shared.HasPlaceholderElement

Methods

setPlaceholder()

Sets the placeholder attribute via JavaScript evaluation.
String
required
The placeholder text to set

getPlaceholder()

Retrieves the current placeholder text by evaluating the element’s placeholder property. Returns: String - The placeholder text

assertPlaceholder()

Asserts that the placeholder attribute matches the expected text.
String
required
The expected placeholder text
Throws: AssertionError if the placeholder does not match

Implementing Classes

The following element classes implement HasPlaceholderElement:
  • TextFieldElement (and all subclasses: TextAreaElement, PasswordFieldElement, EmailFieldElement)
  • All text input components that support placeholder text

Usage Example

Implementation Details

DOM Property vs Attribute

The implementation uses JavaScript evaluation to get and set the placeholder:
However, the assertion uses the HTML attribute:
This works because Vaadin synchronizes the DOM property with the HTML attribute.

Placeholder Visibility

Placeholders are only visible when:
  • The field is empty
  • The field does not have focus (in some browsers)
  • The field is not disabled

Testing Patterns

Test Placeholder Content

Test Placeholder Disappears on Input

Test Placeholder as Documentation

Test Placeholder in Different Languages

Test Dynamic Placeholder Changes

Best Practices

Don’t Over-Rely on Placeholders

Placeholders should supplement, not replace, field labels:

Test Placeholder Clarity

Ensure placeholders provide clear guidance:

Use Placeholders for Examples

Placeholders work well for showing format examples:

Accessibility Considerations

Placeholders should not be the only way to convey important information:

Common Use Cases

Search Fields

Format Examples

Optional Fields