Back to Tldraw

Options

apps/docs/content/sdk-features/options.mdx

5.4.021.2 KB
Original Source

The tldraw editor accepts two kinds of configuration: editor options for core behavior (timing, limits, performance) and component props for UI, persistence, and content handling. Editor options are fixed after initialization; component props configure how the editor sets up.

Editor options

The options prop accepts a Partial<TldrawOptions> object that configures core editor behavior: limits like maximum pages and shapes, timing for interactions and animations, sizing for handles and hit testing, and feature toggles.

Options are set once when the editor initializes and cannot change afterward. Pass a partial options object to override specific values; everything else uses the defaults.

tsx
import { Tldraw, TldrawOptions } from 'tldraw'

const options: Partial<TldrawOptions> = {
	maxPages: 3,
	maxShapesPerPage: 1000,
}

function App() {
	return <Tldraw options={options} />
}

Reading options at runtime

After the editor initializes, access options through editor.options:

typescript
const maxPages = editor.options.maxPages
const animationDuration = editor.options.animationMediumMs

The options object is readonly. Attempting to modify it has no effect and TypeScript will flag the error.

Editor option categories

Limits

Cap shape, page, and file counts:

OptionDefaultDescription
maxShapesPerPage4000Maximum shapes allowed on one page
maxPages40Maximum pages in a document
maxFilesAtOnce100Maximum files to handle in one drop

Setting maxPages to 1 effectively disables multi-page functionality and removes the page menu from the UI.

Interaction timing

Configure how the editor interprets user input timing:

OptionDefaultDescription
doubleClickDurationMs450Maximum interval for double-click detection
multiClickDurationMs200Window for triple- and quadruple-click detection
longPressDurationMs500Duration to trigger long press
animationMediumMs320Duration for camera animations (zoom, pan to fit)

Drag detection

Control when pointer movement becomes a drag operation:

OptionDefaultDescription
dragDistanceSquared16Distance² threshold for mouse drag (4px)
coarseDragDistanceSquared36Distance² threshold for touch drag (6px)
uiDragDistanceSquared16Distance² for UI element drag (4px)
uiCoarseDragDistanceSquared625Distance² for touch UI drag (25px)

Values are squared to avoid computing square roots during drag detection. The larger touch thresholds prevent accidental drags on mobile devices.

Handle and hit testing

Configure selection handles and click target areas:

OptionDefaultDescription
handleRadius12Radius of selection handles
coarseHandleRadius20Handle radius for touch input
hitTestMargin3Additional margin around shapes for hit tests
coarseHitTestMargin4Hit test margin when using a coarse pointer

Edge scrolling

Configure auto-scroll behavior when dragging near viewport edges:

OptionDefaultDescription
edgeScrollDelay200Milliseconds before scroll starts
edgeScrollEaseDuration200Milliseconds to accelerate to full speed
edgeScrollSpeed25Base scroll speed, multiplied by the user's edge scroll speed preference
edgeScrollDistance8Width of the edge scroll trigger zone
coarsePointerWidth12Pointer width used to widen the trigger zone for touch

See Edge scrolling for details on how these options affect behavior.

Camera

Control camera movement and viewport behavior:

OptionDefaultDescription
cameraSlideFriction0.09Friction applied to camera momentum
cameraMovingTimeoutMs64Time before camera is considered stopped
followChaseViewportSnap2Snap threshold when following collaborators
spacebarPanningtrueEnable spacebar to activate pan mode
rightClickPanningtrueEnable right-click and drag to pan the camera
zoomToFitPadding128Padding around content when zooming to fit bounds
cameraDEFAULT_CAMERA_OPTIONSInitial TLCameraOptions; change at runtime with Editor#setCameraOptions
deepLinksundefinedSync camera state with the URL: true or a TLDeepLinkOptions object

The camera and deepLinks options replace the deprecated cameraOptions and deepLinks props on the component. See Camera for the camera options.

Snapping

OptionDefaultDescription
snapThreshold8Distance in pixels at which snapping engages
selectLockedShapesfalseAllow left-clicking and brushing to select locked shapes (they still can't be moved or edited)

Collaboration

Configure timing for collaborator presence:

OptionDefaultDescription
collaboratorInactiveTimeoutMs60000Time before collaborator marked inactive
collaboratorIdleTimeoutMs3000Time before collaborator marked idle
collaboratorCheckIntervalMs1200Interval for checking collaborator status

Export

Configure image and SVG export behavior:

OptionDefaultDescription
defaultSvgPadding32Padding around exported SVG content
maxExportDelayMs5000Maximum wait time for export completion
flattenImageBoundsExpand64Expansion when flattening images
flattenImageBoundsPadding16Padding when flattening images
exportProviderFragmentReact provider wrapping exported content

The exportProvider option wraps exported content in a React component. Use this when your custom shapes depend on context providers that must be present during rendering:

tsx
const options: Partial<TldrawOptions> = {
	exportProvider: ({ children }) => <ThemeProvider theme={myTheme}>{children}</ThemeProvider>,
}

Grid

Configure the alignment grid:

typescript
gridSteps: [
	{ min: -1, mid: 0.15, step: 64 },
	{ min: 0.05, mid: 0.375, step: 16 },
	{ min: 0.15, mid: 1, step: 4 },
	{ min: 0.7, mid: 2.5, step: 1 },
]

Each entry defines a grid step size based on zoom level. The min and mid values define the zoom range where the step applies. Zoomed out, the grid uses larger steps; zoomed in, finer ones.

Performance

Options that affect rendering performance:

OptionDefaultDescription
debouncedZoomtrueUse cached zoom while camera is moving
debouncedZoomThreshold500Shape count threshold for debounced zoom
maxFontsToLoadBeforeRenderInfinityFonts to load before showing canvas
textShadowLod0.35Zoom threshold for text shadow rendering

When debouncedZoom is enabled and the page has more shapes than debouncedZoomThreshold, the editor returns a cached zoom level during camera movement. This reduces re-renders of complex documents.

UI and features

OptionDefaultDescription
createTextOnCanvasDoubleClicktrueCreate text shape on empty canvas double-click
enableToolbarKeyboardShortcutstrueEnable number keys (1-9, 0) for toolbar items
actionShortcutsLocation'swap'Where the quick actions (undo, redo, delete, duplicate) render
tooltipDelayMs700Delay before showing tooltips
laserDelayMs1200Duration laser pointer remains visible
laserFadeoutMs500Duration for laser pointer fadeout animation
quickZoomPreservesScreenBoundstrueWhether quick zoom brush keeps viewport scale
brandingundefinedApp name for accessibility labels
nonceundefinedCSP nonce for inline styles
adjacentShapeMargin10Gap used when placing adjacent notes, duplicating, stacking, and packing shapes
text{}TLTextOptions: TipTap configuration and font handling (replaces the deprecated textOptions prop)

The actionShortcutsLocation option controls where the quick actions render:

  • 'menu' - Always in the menu panel
  • 'toolbar' - Always in the toolbar
  • 'swap' - In the menu panel on tablet-sized screens and up, in the toolbar below that

Asset handling

OptionDefaultDescription
temporaryAssetPreviewLifetimeMs180000How long temporary asset previews persist (3 min)

Clipboard hooks

These callbacks let you intercept and customize clipboard operations:

OptionDescription
onBeforeCopyToClipboardCalled before content is written to the clipboard during copy or cut. Return modified TLContent to transform, false to cancel, or void to pass through.
onBeforePasteFromClipboardCalled before pasted content is processed and shapes are created. Return false to cancel, a modified content object to transform, or void to pass through. Only fires for paste, not file drops.
onClipboardPasteRawCalled first for keyboard and menu paste, before tldraw parses clipboard data. Return false to cancel default paste handling, or void to continue.

See Clipboard for more details on clipboard operations.

Drop handling

OptionDescription
experimental__onDropOnCanvasCalled when content is dropped on the canvas. Receives the page position and drag event. Return true to prevent default drop handling.

Default values

The defaultTldrawOptions export provides all default values:

typescript
import { defaultTldrawOptions } from 'tldraw'

console.log(defaultTldrawOptions.maxPages) // 40

Use this to check defaults or spread into your own options:

typescript
const options: Partial<TldrawOptions> = {
	...defaultTldrawOptions,
	maxPages: 10,
}

Tldraw component props

The <Tldraw> component accepts additional props beyond those available on <TldrawEditor>. These props configure the UI layer, external content handling, and other features that the full SDK provides.

UI configuration

PropTypeDescription
hideUibooleanHide all UI elements, showing only the canvas
forceMobilebooleanForce mobile breakpoints regardless of screen size
overridesTLUiOverridesOverride actions, tools, and translations
onUiEventTLUiEventHandlerCallback for UI interaction events
componentsTLComponentsOverride or disable UI and canvas components
assetUrlsTLUiAssetUrlOverridesCustom URLs for fonts, icons, and other UI assets

The hideUi prop is useful when building custom interfaces around the canvas:

tsx
function CustomEditor() {
	return (
		<Tldraw hideUi>
			<MyCustomToolbar />
		</Tldraw>
	)
}

External content handling

These props control how the editor handles dropped or pasted files:

PropDefaultDescription
maxImageDimension5000Maximum width/height for images (larger images resized)
maxAssetSize10485760Maximum file size in bytes (10 MB)
acceptedImageMimeTypesDEFAULT_SUPPORTED_IMAGE_TYPESAllowed image MIME types
acceptedVideoMimeTypesDEFAULT_SUPPORT_VIDEO_TYPESAllowed video MIME types
tsx
function App() {
	return (
		<Tldraw
			maxImageDimension={2000}
			maxAssetSize={5 * 1024 * 1024} // 5 MB
			acceptedImageMimeTypes={['image/png', 'image/jpeg']}
		/>
	)
}

Embeds

Customize which embed types the editor recognizes using EmbedShapeUtil.configure():

tsx
import { Tldraw, EmbedShapeUtil, DEFAULT_EMBED_DEFINITIONS } from 'tldraw'

const shapeUtils = [
	EmbedShapeUtil.configure({
		embedDefinitions: [
			...DEFAULT_EMBED_DEFINITIONS,
			{
				type: 'custom-video',
				title: 'Custom Video',
				hostnames: ['videos.example.com'],
				width: 560,
				height: 315,
				doesResize: true,
				toEmbedUrl: (url) => url.replace('/watch/', '/embed/'),
				fromEmbedUrl: (url) => url.replace('/embed/', '/watch/'),
			},
		],
	}),
]

function App() {
	return <Tldraw shapeUtils={shapeUtils} />
}

See Embed shape for the full embed definition API.

Editor setup

These props configure how the editor initializes:

PropTypeDescription
autoFocusbooleanAutomatically focus the editor on mount
initialStatestringInitial tool state (<Tldraw> defaults to 'select')
shapeUtilsTLAnyShapeUtilConstructor[]Custom shape utilities
bindingUtilsTLAnyBindingUtilConstructor[]Custom binding utilities
overlayUtilsTLAnyOverlayUtilConstructor[]Custom overlay utilities
toolsTLStateNodeConstructor[]Custom tools
onMountTLOnMountHandlerCallback when editor mounts
getShapeVisibility(shape, editor) => 'visible' | 'hidden' | 'inherit'Conditionally hide shapes
userTLCurrentUserCurrent user information
colorScheme'light' | 'dark' | 'system'Color scheme (defaults to 'light')
licenseKeystringLicense key to remove watermark
themesPartial<TLThemes>Named themes for the editor
initialThemeTLThemeIdInitially active theme (defaults to 'default')
localestringUI locale; overrides browser and user preferences

The cameraOptions, deepLinks, textOptions, and embeds props are deprecated. Use options.camera, options.deepLinks, options.text, and EmbedShapeUtil.configure instead.

The getShapeVisibility callback lets you conditionally hide shapes based on their properties:

tsx
<Tldraw
	getShapeVisibility={(shape, editor) => {
		// Hide shapes marked as hidden in meta
		if (shape.meta.hidden) return 'hidden'
		// Force-show shapes regardless of parent visibility
		if (shape.meta.alwaysVisible) return 'visible'
		// Default: visible unless parent is hidden
		return 'inherit'
	}}
/>

Store configuration

When not providing your own store, these props configure automatic store creation:

PropTypeDescription
persistenceKeystringKey for IndexedDB persistence (enables local storage)
sessionIdstringSession identifier for persistence
snapshotTLEditorSnapshotInitial document state
migrationsMigrationSequence[]Additional migrations for custom schemas
tsx
function App() {
	return <Tldraw persistenceKey="my-document" snapshot={savedSnapshot} />
}

Alternatively, provide your own store with the store prop for full control over data management.

Examples

  • Editor options - Override default options like max pages and animation speed.
  • Disable pages - Set maxPages to 1 to create a single-page editor.