Time picker example

Typed times with native form ownership.

Type strict HH:mm text, choose a slot and keep invalid drafts visible. External forms, prevented reset, read-only values and disabled exclusion use the same contract.

Complete React client module · MIT · Next.js and Vite

Interactive example

Typed times with native form ownership

Type strict HH:mm text, choose a slot and keep invalid drafts visible. External forms, prevented reset, read-only values and disabled exclusion use the same contract.

Keyboard

  • Enter or leaving the control commits a valid time. Escape restores the previous committed time.
  • Alt+ArrowDown opens slots. Arrow keys, Home and End move; Enter chooses.
  • Native submit focuses invalid text. Reset restores uncontrolled defaults unless cancelled.

States covered

  • Editable HH:mm
  • External native form
  • Required and unavailable slots
  • Controlled and uncontrolled
  • Prevented reset
  • Read only and disabled

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-time-entry-form-lifecycle.json
Complete source
React / TypeScript
/*!
MIT License

Copyright (c) 2026 Jaison

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import {useId,useState} from 'react';
import {Button,Checkbox,TimePicker,UIProvider} from '@bld8/ui';
export default function TimeEntryFormExample(){const id=useId(),[prevent,setPrevent]=useState(false),[changes,setChanges]=useState(0),[owned,setOwned]=useState<string|null>('10:00'),[status,setStatus]=useState('No time submitted.');
  return <UIProvider><div style={{display:'grid',gap:20,maxWidth:600}}>
    <TimePicker label="Session time" name="session" form={id} editable defaultValue="09:30" required minTime="09:00" maxTime="17:00" interval={15} hourCycle="h23" disabledTimes={['12:00']} onValueChange={()=>setChanges(count=>count+1)}/>
    <TimePicker label="Host-owned time" name="owned" form={id} editable value={owned} onValueChange={setOwned} minTime="09:00" maxTime="17:00"/>
    <TimePicker label="Locked time" name="locked" form={id} editable defaultValue="11:00" readOnly/>
    <TimePicker label="Unavailable time" name="disabled" form={id} editable defaultValue="11:00" disabled/>
    <Checkbox label="Prevent time reset" checked={prevent} onCheckedChange={setPrevent}/>
    <form id={id} aria-label="Time form" onReset={event=>{if(prevent){event.preventDefault();setStatus('Time reset prevented.');}else setStatus('Time defaults restored.');}} onSubmit={event=>{event.preventDefault();const data=new FormData(event.currentTarget);setStatus('Time: '+data.get('session')+' | Owned: '+data.get('owned')+' | Locked: '+data.get('locked')+' | Disabled: '+data.has('disabled'));}}>
      <div style={{display:'flex',gap:12,flexWrap:'wrap'}}><Button type="submit">Read time values</Button><Button type="reset" variant="secondary">Reset times</Button><Button variant="ghost" onClick={()=>setOwned(null)}>Clear host time</Button></div>
    </form><p role="status">{status}</p><p data-time-changes>{'Changes: '+changes}</p>
  </div></UIProvider>;
}