Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

Components / Controls

PathField

A file or folder path: a text field with a Browse button inside its end that asks your app's picker for a path, and a clear button. The path can also be typed. It is for apps with their own file dialog (Electron), where a browser file input gives no path.

Browse fills the path

When to useLink to "When to use"

  • A setting or form value that is a path on disk: a database file, an export folder, a binary.
  • Your app has a native dialog that returns a path (Electron's dialog.showOpenDialog over IPC).

Use something else when:

UsageLink to "Usage"

tsx
Copy
import { PathField } from "@arshad-shah/cynosure";

<PathField
  label="Database file"
  name="db"
  value={path}
  onChange={setPath}
  onPick={() => window.api.pickFile({ filters: [{ name: "SQLite", extensions: ["db"] }] })}
/>

onPick returns a promise of the chosen path, or null when the dialog was cancelled. While it is open the Browse button is busy and cannot be pressed again; a cancel, or a picker that fails (the promise rejects), leaves the path as it was. FileDrop's onPick works the same way.

Cancelling changes nothing

Controlled use and formsLink to "Controlled use and forms"

value and onChange control the path; onChange is called when it is typed, picked or cleared. With name, the path is submitted with its form, and required blocks the form while it is empty. The Browse button never submits.

Controlled value

Sizes, icon and labelsLink to "Sizes, icon and labels"

size (xs, sm, md, lg) sets the field, and the Browse button is one step smaller so it fits inside. iconStart leads the field with an icon (a folder). labels replaces the button text ("Browse…", "Clear").

PropsLink to "Props"

Every prop of PathField
PropWhat it doesTypeDefault
labelRequired
The field's label and accessible name.ReactNode
onPickRequired
Opens your picker (Electron's dialog.showOpenDialog over IPC, a file system access handle) and resolves with the chosen path, or null when it was cancelled. The button is busy until it settles; a cancel or a failure (the promise rejects) leaves the path as it was.() => Promise<string | null>
labelHidden
Visually hide the label (it still names the field). Prefer visible labels.boolean
description
Help text shown below the field and read with it.ReactNode
error
Your own error message, shown below the field.ReactNode
value
The path (controlled).string
defaultValue
The path at first, when uncontrolled.string
onChange
Called with the new path when it is typed, picked or cleared.((value: string) => void)
name
Name the path is submitted under in a form.string
form
Id of the form it belongs to, when it is not inside that form.string
required
The form cannot be submitted while the path is empty.boolean
disabled
Turns off the field and its buttons; the path is not submitted.boolean
placeholder
Hint shown in the field while it is empty.string
iconStart
Icon at the start of the field.IconData
size
Field height and text size. Default "md".DenseSize"md"
variant
outline or soft (tinted, borderless until focus). Default "outline"."soft" | "outline""outline"
labels
Replace the built-in English text: the Browse and clear buttons.Partial<PathFieldLabels>
className
Added to the root element, for layout.string
style
Layout only. Restyle through --cy-path-field-* tokens.CSSProperties
layout
stack puts the label above the control and the description and error below it. split puts the label and description at the start and the control at the end of one row (a settings row); when the field is too narrow for both, the control moves under the text. Default "stack"."stack" | "split""stack"
width
Width of the control, so the controls of a column of fields line up: "sm", "md" and "lg" are the --cy-field-control-width-* tokens (never wider than the field), "full" is the whole field. Default: the control's own width (the whole field in the stacked layout for TextField and the other fields).FieldWidth

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

Behaviour and accessibilityLink to "Behaviour and accessibility"

Behaviour and accessibility, table 1
InputResult
TypingEdits the path
TabThe input, then the clear button (while there is a path), then Browse
Enter or a press on BrowseCalls onPick; the chosen path fills the field
A press on the clear buttonEmpties the field and focuses it
  • Roles: a labelled text box, a "Clear" button and a "Browse…" button, aria-busy while the picker is open.
  • Disabled: the field and Browse are disabled and the clear button is gone; the path is not submitted.
  • Right to left: the buttons end the field, on the left.

TouchLink to "Touch"

The Browse button has a 44px hit area on touch screens (the clear button is TextField's, sized the same way).

ThemingLink to "Theming"

Tokens: --cy-path-field-browse-inset (space between the Browse button and the field's end), and TextField's and Button's for the field and the button.

TextField · FileDrop · Button

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog