Date picker example

Controlled dates remain host owned.

External updates and native reset preserve the controlled value. Native text errors are linked to the actual input.

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

Interactive example

Controlled dates remain host owned

External updates and native reset preserve the controlled value. Native text errors are linked to the actual input.

Keyboard

  • Edit a date and leave the field to report the valid change.
  • Reset leaves the controlled value with the host.
  • External update buttons change or clear the committed date.

States covered

  • Controlled value
  • External update
  • Controlled null
  • Reset

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-date-controlled-entry.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 {useState} from 'react';
import {Button,DatePicker,formatDateValue,parseDateValue,UIProvider} from '@bld8/ui';
export default function ControlledDateEntry(){
  const [value,setValue]=useState<Date|null>(parseDateValue('2026-11-12')),[status,setStatus]=useState('Controlled date: 2026-11-12');
  return <UIProvider><form style={{display:'grid',gap:16}} onSubmit={event=>{event.preventDefault();setStatus('Controlled submitted: '+new FormData(event.currentTarget).get('controlledDate'));}}>
    <DatePicker label="Controlled review date" editable name="controlledDate" value={value} onValueChange={next=>{setValue(next);setStatus('Controlled date: '+formatDateValue(next));}}/>
    <div style={{display:'flex',gap:8,flexWrap:'wrap'}}><Button onClick={()=>setValue(parseDateValue('2026-11-24'))}>Set controlled date</Button><Button variant="ghost" onClick={()=>setValue(null)}>Clear controlled date</Button><Button variant="secondary" type="reset">Reset controlled date form</Button><Button type="submit">Read controlled date</Button></div><p role="status">{status}</p>
  </form></UIProvider>;
}