# TimeField **Category**: react **URL**: https://heroui.com/en/docs/react/components/time-field **Source**: https://raw.githubusercontent.com/heroui-inc/heroui/refs/heads/v3/apps/docs/content/docs/en/react/components/(date-and-time)/time-field.mdx > Time input field with labels, descriptions, and validation built on React Aria TimeField *** ## Usage ```tsx import { TimeField } from '@heroui/react'; ``` ```tsx "use client"; import {Label, TimeField} from "@heroui/react"; export function Basic() { return ( {(segment) => } ); } ``` ## Anatomy ```tsx import {TimeField, Label, Description, FieldError} from '@heroui/react'; export default () => ( ) ``` > **TimeField** combines label, time input, description, and error into a single accessible component. ## Examples ### With Icons Add prefix or suffix icons to enhance the time field. ```tsx "use client"; import {Clock} from "@gravity-ui/icons"; import {Label, TimeField} from "@heroui/react"; export function WithPrefixIcon() { return ( {(segment) => } ); } ``` ```tsx "use client"; import {Clock} from "@gravity-ui/icons"; import {Label, TimeField} from "@heroui/react"; export function WithSuffixIcon() { return ( {(segment) => } ); } ``` ```tsx "use client"; import {ChevronDown, Clock} from "@gravity-ui/icons"; import {Description, Label, TimeField} from "@heroui/react"; export function WithPrefixAndSuffix() { return ( {(segment) => } Enter a time ); } ``` ### On Surface When used inside a [Surface](/docs/react/components/surface) component, use `variant="secondary"` on TimeField.Group to apply the lower emphasis variant suitable for surface backgrounds. ```tsx "use client"; import {Clock} from "@gravity-ui/icons"; import {Description, Label, Surface, TimeField} from "@heroui/react"; export function OnSurface() { return ( {(segment) => } Enter a time {(segment) => } Enter a time for your appointment ); } ``` ### With Description ```tsx "use client"; import {Description, Label, TimeField} from "@heroui/react"; export function WithDescription() { return (
{(segment) => } Enter the start time {(segment) => } Enter the end time
); } ``` ### Required Field ```tsx "use client"; import {Description, Label, TimeField} from "@heroui/react"; export function Required() { return (
{(segment) => } {(segment) => } Required field
); } ``` ### Disabled State ```tsx "use client"; import {Description, Label, TimeField} from "@heroui/react"; import {Time, getLocalTimeZone, now} from "@internationalized/date"; export function Disabled() { const currentTime = now(getLocalTimeZone()); const timeValue = new Time(currentTime.hour, currentTime.minute, currentTime.second); return (
{(segment) => } This time field is disabled {(segment) => } This time field is disabled
); } ``` ### Full Width ```tsx "use client"; import {ChevronDown, Clock} from "@gravity-ui/icons"; import {Label, TimeField} from "@heroui/react"; export function FullWidth() { return (
{(segment) => } {(segment) => }
); } ``` ### Validation Use `isInvalid` together with `FieldError` to surface validation messages. ```tsx "use client"; import {FieldError, Label, TimeField} from "@heroui/react"; export function Invalid() { return (
{(segment) => } Please enter a valid time {(segment) => } Time must be within business hours
); } ``` ### Controlled Control the value to synchronize with other components or state management. ```tsx "use client"; import type {TimeValue} from "@heroui/react"; import {Button, Description, Label, TimeField} from "@heroui/react"; import {Time, getLocalTimeZone, now} from "@internationalized/date"; import {useState} from "react"; export function Controlled() { const [value, setValue] = useState(null); return (
{(segment) => } Current value: {value ? value.toString() : "(empty)"}
); } ``` ### Form Example Complete form example with validation and submission handling. ```tsx "use client"; import type {Time} from "@internationalized/date"; import {Clock} from "@gravity-ui/icons"; import {Button, Description, FieldError, Form, Label, TimeField} from "@heroui/react"; import {parseTime} from "@internationalized/date"; import {useState} from "react"; export function FormExample() { const [value, setValue] = useState