import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';
import '@vaadin/time-picker';
import { applyTheme } from 'Frontend/generated/theme';
@customElement('time-picker-basic')
export class Example extends LitElement {
protected override createRenderRoot() {
const root = super.createRenderRoot();
// Apply custom theme (only supported if your app uses one)
applyTheme(root);
return root;
}
protected override render() {
return html`
<!-- tag::snippet[] -->
<vaadin-time-picker label="Alarm" value="07:00"></vaadin-time-picker>
<!-- end::snippet[] -->
`;
}
}
TimePickerBasic.java
package com.vaadin.demo.component.timepicker;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.timepicker.TimePicker;
import com.vaadin.flow.router.Route;
import java.time.LocalTime;
@Route("time-picker-basic")
public class TimePickerBasic extends Div {
public TimePickerBasic() {
// tag::snippet[]
TimePicker timePicker = new TimePicker();
timePicker.setLabel("Alarm");
timePicker.setValue(LocalTime.of(7, 0));
add(timePicker);
// end::snippet[]
}
}
The time can be entered directly using a keyboard or by choosing a value from a set of predefined options presented in an overlay.
The overlay opens when the field is clicked or any input is entered when the field is focused.
Common Input Field Features
Time Picker includes all
Text Field and
shared input field features.
Time Picker’s step parameter defines the interval (in seconds) between the items displayed in the overlay.
It also specifies the amount by which the time increases/decreases using the Up/Down arrow keys (when the overlay is disabled).
The default step is one hour (that is, 3600).
Unlike Number Field, Time Picker accepts values that don’t align with the specified step.
package com.vaadin.demo.component.timepicker;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.timepicker.TimePicker;
import com.vaadin.flow.router.Route;
import java.time.Duration;
import java.time.LocalTime;
@Route("time-picker-seconds-step")
public class TimePickerSecondsStep extends Div {
public TimePickerSecondsStep() {
// tag::snippet[]
TimePicker timePicker = new TimePicker();
timePicker.setLabel("Message received");
timePicker.setStep(Duration.ofSeconds(1));
timePicker.setValue(LocalTime.of(15, 45, 8));
add(timePicker);
// end::snippet[]
}
}
Step
Format
Less than 60 seconds
HH:MM:SS
Less than 1 second
HH:MM:SS:FFF
Note
Limit the number of steps
The overlay doesn’t appear for steps less than 900 seconds (15 minutes), to avoid showing an impractical number of choices.
Auto Open
The overlay opens automatically when the field is focused using a pointer (mouse or touch), or when the user types in the field.
You can disable this, to open the overlay only when the toggle button or Up/Down arrow keys are pressed.