Async multi-select example

Controlled remote choices stay host owned.

The host owns selected IDs through form reset and external updates. A read-only toggle prevents edits without disabling native submission.

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

Interactive example

Controlled remote choices stay host owned

The host owns selected IDs through form reset and external updates. A read-only toggle prevents edits without disabling native submission.

Keyboard

  • Choose people with the keyboard, then reset the form without replacing the controlled values.
  • Lock the fields to read selections without opening a picker or removing a chip.
  • Host update replaces both controlled values explicitly.

States covered

  • Controlled reset ownership
  • Explicit host update
  • Read-only without mutation
  • Native stable IDs

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-async-controlled-form.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 {useCallback,useState} from 'react';
import {AsyncCombobox,AsyncMultiSelect,Button,Checkbox,UIProvider,type AsyncOptionsLoader} from '@bld8/ui';
const people=[{value:'maya',label:'Maya Chen'},{value:'sam',label:'Sam Rivera'},{value:'oliver',label:'Oliver Reed'}];
export default function AsyncControlledForm(){
  const [owner,setOwner]=useState<string|null>('maya'),[reviewers,setReviewers]=useState(['sam']),[locked,setLocked]=useState(false),[status,setStatus]=useState('Controlled values belong to this component.');
  const load=useCallback<AsyncOptionsLoader>(async({query,signal})=>{if(signal.aborted)throw new DOMException('Cancelled','AbortError');return {items:people.filter(person=>person.label.toLowerCase().includes(query.toLowerCase())),nextCursor:null};},[]);
  return <UIProvider><form style={{display:'grid',gap:20}} onReset={()=>setStatus('Native reset kept host values.')} onSubmit={event=>{event.preventDefault();setStatus(JSON.stringify([...new FormData(event.currentTarget).entries()]));}}>
    <AsyncCombobox label="Controlled assignee" name="owner" value={owner} onValueChange={setOwner} loadOptions={load} selectedOptions={people} readOnly={locked} debounceMs={0}/>
    <AsyncMultiSelect label="Controlled reviewers" name="reviewers" value={reviewers} onValueChange={setReviewers} loadOptions={load} selectedOptions={people} readOnly={locked} debounceMs={0}/>
    <Checkbox label="Lock controlled choices" checked={locked} onCheckedChange={setLocked}/>
    <div style={{display:'flex',gap:8,flexWrap:'wrap'}}><Button type="submit">Read controlled choices</Button><Button type="reset" variant="secondary">Reset controlled choices</Button><Button variant="ghost" onClick={()=>{setOwner('oliver');setReviewers(['maya','oliver']);}}>Host update</Button></div>
    <p role="status" aria-label="Controlled directory result">{status}</p>
  </form></UIProvider>;
}