Select example

External forms and native reset.

Associate choices with a separate form. Native reset restores uncontrolled defaults; the application owns controlled values.

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

Interactive example

External forms and native reset

Associate choices with a separate form. Native reset restores uncontrolled defaults; the application owns controlled values.

Keyboard

  • Choose a different value with the normal list keyboard controls.
  • Submit reads the canonical IDs from the external form.
  • Reset restores uncontrolled defaults without reporting a user change.

States covered

  • external form
  • required
  • uncontrolled defaults
  • native reset
  • controlled reset ownership

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-choice-native-form-reset.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 { useId, useState } from 'react';
import { Button, Combobox, MultiSelect, Select, type Option } from '@bld8/ui';
import '@bld8/ui/styles.css';
const choices: Option[] = [{ value: 'alpha-id', label: 'Alpha environment' }, { value: 'beta-id', label: 'Beta environment' }];
export default function ExternalChoiceFormExample() {
  const formId = useId();
  const [controlled, setControlled] = useState<string | null>('alpha-id');
  const [changes, setChanges] = useState(0);
  const [result, setResult] = useState('Not submitted');
  const changed = () => setChanges(count => count + 1);
  return <div style={{ display: 'grid', gap: 16, maxWidth: 440 }}>
    <Select label="Resettable environment" name="nativeSelect" form={formId} options={choices} defaultValue="alpha-id" required onValueChange={changed} />
    <Combobox label="Resettable search" name="nativeCombo" form={formId} options={choices} defaultValue="alpha-id" required onValueChange={changed} />
    <MultiSelect label="Resettable reviewers" name="nativeMulti" form={formId} options={choices} defaultValue={['alpha-id']} required onValueChange={changed} />
    <Combobox label="Application-owned environment" name="controlledCombo" form={formId} options={choices} value={controlled} onValueChange={setControlled} />
    <form id={formId} aria-label="External choice form" onSubmit={event => {
      event.preventDefault(); const data = new FormData(event.currentTarget);
      setResult(['nativeSelect', 'nativeCombo', 'nativeMulti', 'controlledCombo'].map(name => data.getAll(name).map(String).join(',')).join(' | '));
    }} style={{ display: 'grid', gap: 12 }}>
      <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}><Button type="submit">Read external choice values</Button><Button type="reset" variant="secondary">Reset external choices</Button></div>
      <output aria-label="External choice values">{result}</output>
      <output aria-label="Choice change count">{changes}</output>
    </form>
  </div>;
}