Note actions with mixed controls
Save a short note, choose emphasis and open secondary actions from one toolbar. The example keeps its data in memory.
Keyboard
- Tab enters the toolbar once; Left and Right Arrow move across buttons, toggle choices, links and the menu trigger.
- Enter or Space activates an action. The menu keeps its own keyboard navigation and restores its trigger on Escape.
- Tab leaves the toolbar for the note field. Every icon action has an accessible name.
States covered
- mixed roving focus
- Button and IconButton composition
- ToggleGroup composition
- DropdownMenu composition
- controlled formatting
- local save
Install this complete example and its component dependencies.
npx shadcn@latest add https://ui.bld8.dev/r/example-toolbar-editor-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 {Bold,Italic,MoreHorizontal,Save} from 'lucide-react';
import {Button,DropdownMenu,Icon,IconButton,Textarea,ToggleGroup,UIProvider} from '@bld8/ui';
import {Toolbar,ToolbarButton,ToolbarLink,ToolbarSeparator} from '@bld8/ui/toolbar';
export default function NoteToolbarExample(){
const [note,setNote]=useState('A clear release note starts with the outcome.'),[format,setFormat]=useState<string[]>([]),[status,setStatus]=useState('Unsaved note');
return <UIProvider><div style={{display:'grid',gap:16,maxWidth:680}}>
<Toolbar label="Note actions">
<ToolbarButton render={<IconButton label="Save note" icon={Save} variant="ghost" size="sm"/>} onClick={()=>setStatus('Saved '+note.length+' characters in memory')}/>
<ToolbarSeparator/>
<ToggleGroup label="Note emphasis" multiple options={[{value:'bold',label:'Bold',icon:Bold},{value:'italic',label:'Italic',icon:Italic}]} value={format} onValueChange={setFormat}/>
<ToolbarSeparator/>
<ToolbarLink href="#note-toolbar-help">Writing guide</ToolbarLink>
<DropdownMenu trigger={<ToolbarButton render={<Button variant="ghost" size="sm"/>}>More<Icon icon={MoreHorizontal} size={16}/></ToolbarButton>} items={[
{label:'Restore example note',onSelect:()=>{setNote('A clear release note starts with the outcome.');setStatus('Example note restored');}},
{label:'Clear emphasis',onSelect:()=>setFormat([]),disabled:!format.length}
]}/>
</Toolbar>
<Textarea aria-label="Release note" value={note} onChange={event=>setNote(event.target.value)} style={{fontWeight:format.includes('bold')?700:400,fontStyle:format.includes('italic')?'italic':'normal'}}/>
<p role="status">{status}</p><p id="note-toolbar-help" className="bui-hint">Lead with the changed behaviour. This small note preview does not provide a rich text editor or persistence service.</p>
</div></UIProvider>;
}