Skip to main content

Common Examples

import { TimeField } from "@servicetitan/anvil2";

function ExampleComponent() {
  return (
    <TimeField
      label="Label Text"
      step={60}
      onChange={(change) => {
        // change function
      }}
    />
  );
}

With Suggestions Enabled (Default)

By default, time fields use a 12-hour format and present suggested times in a dropdown based on the step prop. The dropdown is only present if there is more than one valid option to select from. Whether the dropdown is present or not, the input allows typing in the field itself to get to your desired time.There is autocomplete for best guess assumptions of the time you might be going for based on a partial input value. If both AM and PM times both are possible options, AM takes precedence over PM for autocomplete.

Without Suggestions

When disableSuggestions is set to true, the suggestions dropdown will no longer appear. All other features, including autocomplete, will continue to work as the user types.

Auto-Rounding

If the autoround prop is set to true, the time field will attempt to round to the next valid time on blur based on the step and max props. Note: rounding will always go to the future, never the past.If suggestions are enabled, the suggestions will display the auto rounded options available, even if the time currently typed in the input is not yet rounded.Add a description to allow users to know auto rounding is enabled for the field.

Min and Max Constraints

Use the min and max props to set a time frame constraint. When the props are present, a time outside the time frame can not be entered into the field.Autocomplete will adjust to a time within the time frame if the partial value can fall within the constraint. For example, 02:— will autocomplete to 02:00 PM for a 09:00 AM - 05:00 PM time frame instead of the default 02:00 AM since 02:00 AM does not fall between 09:00 AM and 05:00 PM.autoround will cap at the max time even if it doesn’t fully align with the step prop. For example: In a field with a 09:00 AM - 05:00 PM time frame and a step of 30 minutes, if 4:45 is entered it will round to 5:00 PM.Add a description to allow users to know there is a time constraint.

24 Hour Format

Set the format prop to 24 to change to the time format. When using this format, ensure min and max times are also set to 24 hour format.

Validation

Validation needs to be handled with the onChange. isInputValid and isInputEmpty are boolean props returned with the time so that custom validation can be applied. Note: Because of the use of the mask acts as a value for the input, native html validation will not occur.
Last modified on January 23, 2026