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

Components / Foundations

HiddenValue

Lets a custom widget take part in a native form. It renders a visually and semantically hidden input that carries the widget's value, so the form sees it like any other field. It is a foundation: it has no visual output.

Who uses itLink to "Who uses it"

Select.

When to use it directlyLink to "When to use it directly"

When you build a custom widget (a listbox, a picker) that has no native input of its own but must submit a value, validate and reset with its form.

Use a component instead when a ready-made control fits: Select for choosing from a list, TextField for text.

Submits validates and resets

UsageLink to "Usage"

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

<HiddenValue
  name="plan"
  value={plan}
  required
  requiredMessage="Choose a plan."
  onReset={() => setPlan(defaultPlan)}
  onInvalid={(event) => {
    event.preventDefault();
    triggerRef.current?.focus();
  }}
/>

PropsLink to "Props"

Every prop of HiddenValue
PropWhat it doesTypeDefault
valueRequired
The value to submit.string
name
Form field name the value is submitted under.string
form
id of the form to submit with, when rendered outside it.string
required
Fails form validation while value is empty.boolean
requiredMessage
Message used when required and empty.string
onReset
Called when the owning form is reset, so the widget can restore its default.(() => void)
disabled
Disabled values are neither submitted nor validated (like native disabled controls).boolean
onInvalid
Called when validation fails. Call event.preventDefault() to stop the browser reporting on this hidden input, then focus and explain on the widget's visible control instead.((event: Event) => void)

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

GuaranteesLink to "Guarantees"

  • Submits: name and value appear in FormData. Use form to associate it with a form elsewhere in the page.
  • Validates: while required and the value is empty, the form is invalid with requiredMessage (default "Please choose a value.").
  • Resets: onReset is called when the owning form is reset, so the widget can restore its default.
  • Disabled: a disabled value is neither submitted nor validated, like a native disabled control.
  • Custom reporting: call event.preventDefault() in onInvalid to stop the browser reporting on the hidden input, then focus and explain on the widget's visible control.
  • It is a text input rather than type="hidden" so constraint validation applies, and it is out of the tab order and hidden from assistive technology.

Select

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