Filter and submit native values
Combine a search input, status choices and an explicit native submit action. Other toolbar actions keep type=button.
Keyboard
- Tab enters the toolbar. Arrow keys move between actions and choices; the search input keeps native text editing.
- Enter in the search field submits the form. Apply filters is also an explicit submit button.
- Clear filters changes the draft without submitting.
States covered
- native form values
- search input
- controlled toggle choice
- explicit submit
- clear without submit
Install this complete example and its component dependencies.
npx shadcn@latest add https://ui.bld8.dev/r/example-toolbar-filter-actions.jsonComplete source
/*!
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,ToggleGroup} from '@bld8/ui';
import {Toolbar,ToolbarButton,ToolbarInput,ToolbarSeparator} from '@bld8/ui/toolbar';
const issues=[{title:'Review keyboard flow',status:'open'},{title:'Publish release notes',status:'closed'},{title:'Review mobile spacing',status:'open'}];
export default function FilterToolbarExample(){
const [query,setQuery]=useState(''),[status,setStatus]=useState<string[]>(['all']),[applied,setApplied]=useState({query:'',status:'all'}),[submitted,setSubmitted]=useState('No filter submission');
const visible=issues.filter(issue=>issue.title.toLowerCase().includes(applied.query.toLowerCase())&&(applied.status==='all'||issue.status===applied.status));
return <form aria-label="Issue filters" style={{display:'grid',gap:16,maxWidth:760}} onSubmit={event=>{event.preventDefault();const data=new FormData(event.currentTarget);const next={query:String(data.get('query')??''),status:String(data.get('status')??'all')};setApplied(next);setSubmitted(next.query+' | '+next.status);}}>
<Toolbar label="Issue filter actions"><ToolbarInput aria-label="Search issues" type="search" name="query" value={query} onChange={event=>setQuery(event.target.value)} placeholder="Search issues"/>
<ToolbarSeparator/><ToggleGroup label="Issue status" name="status" options={[{value:'all',label:'All'},{value:'open',label:'Open'},{value:'closed',label:'Closed'}]} value={status} onValueChange={next=>setStatus(next.length?next:['all'])}/>
<ToolbarButton type="submit" name="action" value="apply" render={<Button size="sm"/>}>Apply filters</ToolbarButton>
<ToolbarButton onClick={()=>{setQuery('');setStatus(['all']);}}>Clear filters</ToolbarButton>
</Toolbar>
<ul>{visible.map(issue=><li key={issue.title}>{issue.title} · {issue.status}</li>)}</ul><output aria-label="Submitted filters">{submitted}</output><p className="bui-hint">Choices and search are drafts until Apply filters. Results are local sample data.</p>
</form>;
}