Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tldraw/tldraw/llms.txt
Use this file to discover all available pages before exploring further.
The tldraw UI provides primitive components that can be used to build custom interfaces. These components are styled and designed to work seamlessly with the tldraw editor.
A styled button component with support for different visual types.
import { TldrawUiButton } from 'tldraw'
function CustomToolbar() {
return (
<div>
<TldrawUiButton type="primary" onClick={() => console.log('clicked')}>
Primary
</TldrawUiButton>
<TldrawUiButton type="normal" onClick={() => console.log('clicked')}>
Normal
</TldrawUiButton>
<TldrawUiButton type="danger" onClick={() => console.log('clicked')}>
Delete
</TldrawUiButton>
</div>
)
}
Props
type
'normal' | 'primary' | 'danger' | 'low' | 'icon' | 'tool' | 'menu' | 'help'
required
Visual style of the button.
Whether the button is disabled.
Whether the button appears in an active state.
htmlButtonType
'button' | 'submit' | 'reset'
HTML button type attribute.
onClick
(e: React.MouseEvent) => void
Click handler.
Icon component for use inside buttons.
import { TldrawUiButton, TldrawUiButtonIcon } from 'tldraw'
function IconButton() {
return (
<TldrawUiButton type="icon">
<TldrawUiButtonIcon icon="tool-pencil" />
</TldrawUiButton>
)
}
Label component for use inside buttons.
import { TldrawUiButton, TldrawUiButtonLabel } from 'tldraw'
function LabelButton() {
return (
<TldrawUiButton type="normal">
<TldrawUiButtonLabel>Click me</TldrawUiButtonLabel>
</TldrawUiButton>
)
}
A styled text input component with support for icons, labels, and keyboard shortcuts.
import { TldrawUiInput } from 'tldraw'
function SearchInput() {
const [value, setValue] = React.useState('')
return (
<TldrawUiInput
label="Search"
icon="search"
value={value}
onValueChange={setValue}
onComplete={(val) => console.log('Completed with:', val)}
placeholder="Type to search..."
/>
)
}
Props
Label text displayed above the input.
Icon displayed on the right side of the input.
Icon displayed on the left side of the input.
Accessible label for the icon.
Uncontrolled default value.
Auto-focus the input on mount.
Auto-select input text on focus.
Whether the input is disabled.
Called when the input value changes.
Called when Enter is pressed.
Called when Escape is pressed.
Called when the input loses focus.
Called when the input gains focus.
Icon component
TldrawUiIcon
Displays an icon from the tldraw icon set.
import { TldrawUiIcon } from 'tldraw'
function CustomUI() {
return (
<div>
<TldrawUiIcon icon="tool-pencil" label="Pencil" />
<TldrawUiIcon icon="check" label="Checked" small />
<TldrawUiIcon icon="trash" label="Delete" color="red" />
</div>
)
}
Props
icon
string | TLUiIconType | ReactElement
required
Icon identifier or custom React element.
Accessible label for the icon.
Display icon at small size.
Icon color (CSS color value).
Horizontally flip the icon.
Additional CSS class names.
Root container for a dropdown menu.
import {
TldrawUiDropdownMenuRoot,
TldrawUiDropdownMenuTrigger,
TldrawUiDropdownMenuContent,
TldrawUiDropdownMenuItem,
TldrawUiButton,
} from 'tldraw'
function CustomMenu() {
return (
<TldrawUiDropdownMenuRoot id="custom-menu">
<TldrawUiDropdownMenuTrigger>
<TldrawUiButton type="menu">Menu</TldrawUiButton>
</TldrawUiDropdownMenuTrigger>
<TldrawUiDropdownMenuContent>
<TldrawUiDropdownMenuItem>
<TldrawUiButton type="menu" onClick={() => console.log('Item 1')}>
Item 1
</TldrawUiButton>
</TldrawUiDropdownMenuItem>
</TldrawUiDropdownMenuContent>
</TldrawUiDropdownMenuRoot>
)
}
Props
Unique identifier for the menu.
Whether the menu is modal.
Trigger button for the dropdown menu.
Props
Trigger content (typically a button).
Container for menu items.
Props
side
'bottom' | 'top' | 'right' | 'left'
default:"'bottom'"
Which side of the trigger to display the menu.
align
'start' | 'center' | 'end'
default:"'start'"
How to align the menu relative to the trigger.
Distance from the trigger.
Offset along the alignment axis.
Additional CSS class names.
Wrapper for individual menu items.
Props
Prevent closing the menu when this item is clicked.
Item content (typically a button).
Checkbox menu item.
import { TldrawUiDropdownMenuCheckboxItem } from 'tldraw'
function CheckboxMenuItem() {
const [checked, setChecked] = React.useState(false)
return (
<TldrawUiDropdownMenuCheckboxItem
checked={checked}
onSelect={() => setChecked(!checked)}
title="Enable feature"
>
Enable feature
</TldrawUiDropdownMenuCheckboxItem>
)
}
Props
Whether the checkbox is checked.
Called when the item is selected.
Whether the item is disabled.
Title attribute for accessibility.
Groups related menu items.
import { TldrawUiDropdownMenuGroup } from 'tldraw'
function GroupedMenu() {
return (
<TldrawUiDropdownMenuContent>
<TldrawUiDropdownMenuGroup>
{/* Group 1 items */}
</TldrawUiDropdownMenuGroup>
<TldrawUiDropdownMenuGroup>
{/* Group 2 items */}
</TldrawUiDropdownMenuGroup>
</TldrawUiDropdownMenuContent>
)
}
Submenu container.
import {
TldrawUiDropdownMenuSub,
TldrawUiDropdownMenuSubTrigger,
TldrawUiDropdownMenuSubContent,
} from 'tldraw'
function Submenu() {
return (
<TldrawUiDropdownMenuSub id="submenu">
<TldrawUiDropdownMenuSubTrigger label="More options" />
<TldrawUiDropdownMenuSubContent>
{/* Submenu items */}
</TldrawUiDropdownMenuSubContent>
</TldrawUiDropdownMenuSub>
)
}
Other primitive components
TldrawUiKbd
Displays keyboard shortcut hints.
import { TldrawUiKbd } from 'tldraw'
function ShortcutHint() {
return (
<div>
Press <TldrawUiKbd>Cmd+Z</TldrawUiKbd> to undo
</div>
)
}
TldrawUiSlider
Slider input component.
import { TldrawUiSlider } from 'tldraw'
function OpacitySlider() {
const [opacity, setOpacity] = React.useState(1)
return (
<TldrawUiSlider
value={opacity}
onValueChange={setOpacity}
min={0}
max={1}
step={0.1}
label="Opacity"
/>
)
}
TldrawUiSelect
Select dropdown component.
import { TldrawUiSelect } from 'tldraw'
function FontSelector() {
const [font, setFont] = React.useState('sans')
return (
<TldrawUiSelect
value={font}
onValueChange={setFont}
options={[
{ value: 'sans', label: 'Sans Serif' },
{ value: 'serif', label: 'Serif' },
{ value: 'mono', label: 'Monospace' },
]}
/>
)
}
Layout components
Toolbar container with automatic layout.
TldrawUiContextualToolbar
Floating toolbar that appears near selected shapes.
TldrawUiDialog
Modal dialog container.
TldrawUiPopover
Popover container for floating UI elements.
Usage patterns
import {
TldrawUiButton,
TldrawUiButtonIcon,
useTools,
useEditor,
} from 'tldraw'
function CustomToolbar() {
const tools = useTools()
const editor = useEditor()
return (
<div className="custom-toolbar">
{['select', 'draw', 'eraser'].map((toolId) => {
const tool = tools[toolId]
const isActive = editor.getCurrentToolId() === toolId
return (
<TldrawUiButton
key={toolId}
type="tool"
isActive={isActive}
onClick={() => tool.onSelect('toolbar')}
>
<TldrawUiButtonIcon icon={tool.icon} />
</TldrawUiButton>
)
})}
</div>
)
}
import {
TldrawUiDropdownMenuRoot,
TldrawUiDropdownMenuTrigger,
TldrawUiDropdownMenuContent,
TldrawUiDropdownMenuItem,
TldrawUiDropdownMenuGroup,
TldrawUiButton,
TldrawUiButtonIcon,
useActions,
} from 'tldraw'
function CustomMenu() {
const actions = useActions()
return (
<TldrawUiDropdownMenuRoot id="custom-menu">
<TldrawUiDropdownMenuTrigger>
<TldrawUiButton type="menu">
<TldrawUiButtonIcon icon="menu" />
</TldrawUiButton>
</TldrawUiDropdownMenuTrigger>
<TldrawUiDropdownMenuContent>
<TldrawUiDropdownMenuGroup>
<TldrawUiDropdownMenuItem>
<TldrawUiButton
type="menu"
onClick={() => actions['undo'].onSelect('menu')}
>
Undo
</TldrawUiButton>
</TldrawUiDropdownMenuItem>
<TldrawUiDropdownMenuItem>
<TldrawUiButton
type="menu"
onClick={() => actions['redo'].onSelect('menu')}
>
Redo
</TldrawUiButton>
</TldrawUiDropdownMenuItem>
</TldrawUiDropdownMenuGroup>
</TldrawUiDropdownMenuContent>
</TldrawUiDropdownMenuRoot>
)
}