Form

Forms allow users to enter data that can be submitted while providing alignment and styling for form fields.

installyarn add @adobe/react-spectrum
version3.2.1
usageimport {Form} from '@adobe/react-spectrum'

Example#


<Form maxWidth="size-3600">
  <TextField label="Email" placeholder="abc@adobe.com" />
  <TextField label="Password" placeholder="1234" />
  <Checkbox>Remember me</Checkbox>
</Form>
<Form maxWidth="size-3600">
  <TextField label="Email" placeholder="abc@adobe.com" />
  <TextField label="Password" placeholder="1234" />
  <Checkbox>Remember me</Checkbox>
</Form>
<Form maxWidth="size-3600">
  <TextField
    label="Email"
    placeholder="abc@adobe.com"
  />
  <TextField
    label="Password"
    placeholder="1234"
  />
  <Checkbox>
    Remember me
  </Checkbox>
</Form>

Content#


Form accepts one or more children to render as its form elements. Label alignment, positioning, and other properties are set on the Form itself and propagated to its children to generate a cohesive design. To override these top level Form props on individual children, set them directly on the child instead.

<Form maxWidth="size-3600" isRequired necessityIndicator="label">
  <TextField label="Name" placeholder="Jane Smith" />
  <TextField label="Email" placeholder="abc@adobe.com" />
  <TextField
    label="Address"
    placeholder="123 Any Street"
    isRequired={false}
  />
</Form>
<Form
  maxWidth="size-3600"
  isRequired
  necessityIndicator="label">
  <TextField label="Name" placeholder="Jane Smith" />
  <TextField label="Email" placeholder="abc@adobe.com" />
  <TextField
    label="Address"
    placeholder="123 Any Street"
    isRequired={false}
  />
</Form>
<Form
  maxWidth="size-3600"
  isRequired
  necessityIndicator="label">
  <TextField
    label="Name"
    placeholder="Jane Smith"
  />
  <TextField
    label="Email"
    placeholder="abc@adobe.com"
  />
  <TextField
    label="Address"
    placeholder="123 Any Street"
    isRequired={false}
  />
</Form>

Labeling#


Accessibility#

A label should be provided to the Form by adding either the aria-label or aria-labelledby prop, so that the element will be identified to assistive technology as a form landmark region to which assistive technology can navigate.

<h3 id="label-3">Personal Information</h3>
<Form maxWidth="size-3600" aria-labelledby="label-3">
  <TextField label="First Name" placeholder="John" />
  <TextField label="Last Name" placeholder="Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
    <Radio value="dragons">Dragons</Radio>
  </RadioGroup>
</Form>
<h3 id="label-3">Personal Information</h3>
<Form maxWidth="size-3600" aria-labelledby="label-3">
  <TextField label="First Name" placeholder="John" />
  <TextField label="Last Name" placeholder="Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
    <Radio value="dragons">Dragons</Radio>
  </RadioGroup>
</Form>
<h3 id="label-3">
  Personal Information
</h3>
<Form
  maxWidth="size-3600"
  aria-labelledby="label-3">
  <TextField
    label="First Name"
    placeholder="John"
  />
  <TextField
    label="Last Name"
    placeholder="Smith"
  />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">
      Dogs
    </Radio>
    <Radio value="cats">
      Cats
    </Radio>
    <Radio value="dragons">
      Dragons
    </Radio>
  </RadioGroup>
</Form>

Props#


NameTypeDefaultDescription
childrenReactElement<SpectrumLabelableProps>ReactElement<SpectrumLabelableProps>[]The contents of the Form.
isQuietbooleanWhether the Form elements are displayed with their quiet style.
isEmphasizedbooleanWhether the Form elements are rendered with their emphasized style.
isDisabledbooleanWhether the Form elements are disabled.
isRequiredbooleanWhether user input is required on each of the Form elements before Form submission.
isReadOnlybooleanWhether the Form elements can be selected but not changed by the user.
validationStateValidationState'valid'Whether the Form elements should display their "valid" or "invalid" visual styling.
actionstringWhere to send the form-data when the form is submitted.
encType'application/x-www-form-urlencoded''multipart/form-data''text/plain'The enctype attribute specifies how the form-data should be encoded when submitting it to the server.
method'get''post'The form-data can be sent as URL variables (with method="get") or as HTTP post transaction (with method="post").
target'_blank''_self''_parent''_top'The target attribute specifies a name or a keyword that indicates where to display the response that is received after submitting the form.
labelPositionLabelPosition'top'The label's overall position relative to the element it is labeling.
labelAlignAlignment'start'The label's horizontal alignment relative to the element it is labeling.
necessityIndicatorNecessityIndicator'icon'Whether the required state should be shown as an icon or text.
labelReactNodeThe content to display as the label.
Events
NameTypeDefaultDescription
onSubmitFormEventHandlerFired on form submission.
Layout
NameTypeDefaultDescription
flexstringnumberbooleanWhen used in a flex layout, specifies how the element will grow or shrink to fit the space available. See MDN.
flexGrownumberWhen used in a flex layout, specifies how the element will grow to fit the space available. See MDN.
flexShrinknumberWhen used in a flex layout, specifies how the element will shrink to fit the space available. See MDN.
flexBasisnumberstringWhen used in a flex layout, specifies the initial main size of the element. See MDN.
alignSelf'auto''normal''start''end''center''flex-start''flex-end''self-start''self-end''stretch'Overrides the alignItems property of a flex or grid container. See MDN.
justifySelf'auto''normal''start''end''flex-start''flex-end''self-start''self-end''center''left''right''stretch'Specifies how the element is justified inside a flex or grid container. See MDN.
ordernumberThe layout order for the element within a flex or grid container. See MDN.
gridAreastringWhen used in a grid layout, specifies the named grid area that the element should be placed in within the grid. See MDN.
gridColumnstringWhen used in a grid layout, specifies the column the element should be placed in within the grid. See MDN.
gridRowstringWhen used in a grid layout, specifies the row the element should be placed in within the grid. See MDN.
gridColumnStartstringWhen used in a grid layout, specifies the starting column to span within the grid. See MDN.
gridColumnEndstringWhen used in a grid layout, specifies the ending column to span within the grid. See MDN.
gridRowStartstringWhen used in a grid layout, specifies the starting row to span within the grid. See MDN.
gridRowEndstringWhen used in a grid layout, specifies the ending row to span within the grid. See MDN.
Spacing
NameTypeDefaultDescription
marginDimensionValueThe margin for all four sides of the element. See MDN.
marginTopDimensionValueThe margin for the top side of the element. See MDN.
marginBottomDimensionValueThe margin for the bottom side of the element. See MDN.
marginStartDimensionValueThe margin for the logical start side of the element, depending on layout direction. See MDN.
marginEndDimensionValueThe margin for the logical end side of an element, depending on layout direction. See MDN.
marginXDimensionValueThe margin for both the left and right sides of the element. See MDN.
marginYDimensionValueThe margin for both the top and bottom sides of the element. See MDN.
Sizing
NameTypeDefaultDescription
widthDimensionValueThe width of the element. See MDN.
minWidthDimensionValueThe minimum width of the element. See MDN.
maxWidthDimensionValueThe maximum width of the element. See MDN.
heightDimensionValueThe height of the element. See MDN.
minHeightDimensionValueThe minimum height of the element. See MDN.
maxHeightDimensionValueThe maximum height of the element. See MDN.
Positioning
NameTypeDefaultDescription
position'static''relative''absolute''fixed''sticky'Specifies how the element is positioned. See MDN.
topDimensionValueThe top position for the element. See MDN.
bottomDimensionValueThe bottom position for the element. See MDN.
leftDimensionValueThe left position for the element. See MDN. Consider using start instead for RTL support.
rightDimensionValueThe right position for the element. See MDN. Consider using start instead for RTL support.
startDimensionValueThe logical start position for the element, depending on layout direction. See MDN.
endDimensionValueThe logical end position for the element, depending on layout direction. See MDN.
zIndexnumberThe stacking order for the element. See MDN.
isHiddenbooleanHides the element.
Accessibility
NameTypeDefaultDescription
idstringThe element's unique identifier. See MDN.
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
Advanced
NameTypeDefaultDescription
UNSAFE_classNamestringSets the CSS className for the element. Only use as a last resort. Use style props instead.
UNSAFE_styleCSSPropertiesSets inline style for the element. Only use as a last resort. Use style props instead.

Visual options#


Label position and alignment#

Top label position, start label alignment

<Form
  labelPosition="top"
  labelAlign="start"
  aria-label="Top position, start alignment example"
  maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  labelPosition="top"
  labelAlign="start"
  aria-label="Top position, start alignment example"
  maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  labelPosition="top"
  labelAlign="start"
  aria-label="Top position, start alignment example"
  maxWidth="size-3600">
  <TextField
    label="Name"
    placeholder="John Smith"
  />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">
      Dogs
    </Radio>
    <Radio value="cats">
      Cats
    </Radio>
  </RadioGroup>
</Form>

Side label position, start label alignment

<Form
  labelPosition="side"
  labelAlign="start"
  aria-label="Side position, start alignment example"
  maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  labelPosition="side"
  labelAlign="start"
  aria-label="Side position, start alignment example"
  maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  labelPosition="side"
  labelAlign="start"
  aria-label="Side position, start alignment example"
  maxWidth="size-3600">
  <TextField
    label="Name"
    placeholder="John Smith"
  />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">
      Dogs
    </Radio>
    <Radio value="cats">
      Cats
    </Radio>
  </RadioGroup>
</Form>

Side label position, end label alignment

<Form
  labelPosition="side"
  labelAlign="end"
  aria-label="Side position, end alignment example"
  maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  labelPosition="side"
  labelAlign="end"
  aria-label="Side position, end alignment example"
  maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  labelPosition="side"
  labelAlign="end"
  aria-label="Side position, end alignment example"
  maxWidth="size-3600">
  <TextField
    label="Name"
    placeholder="John Smith"
  />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">
      Dogs
    </Radio>
    <Radio value="cats">
      Cats
    </Radio>
  </RadioGroup>
</Form>

Quiet#

<Form isQuiet aria-label="Quiet example" maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <TextField label="Address" placeholder="123 Any Street" />
</Form>
<Form
  isQuiet
  aria-label="Quiet example"
  maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <TextField
    label="Address"
    placeholder="123 Any Street"
  />
</Form>
<Form
  isQuiet
  aria-label="Quiet example"
  maxWidth="size-3600">
  <TextField
    label="Name"
    placeholder="John Smith"
  />
  <TextField
    label="Address"
    placeholder="123 Any Street"
  />
</Form>

Emphasized#

<Form isEmphasized aria-label="Emphasized example" maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet" defaultValue="dogs">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  isEmphasized
  aria-label="Emphasized example"
  maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet" defaultValue="dogs">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  isEmphasized
  aria-label="Emphasized example"
  maxWidth="size-3600">
  <TextField
    label="Name"
    placeholder="John Smith"
  />
  <RadioGroup
    label="Favorite pet"
    defaultValue="dogs">
    <Radio value="dogs">
      Dogs
    </Radio>
    <Radio value="cats">
      Cats
    </Radio>
  </RadioGroup>
</Form>

Disabled#

<Form isDisabled aria-label="Disabled example" maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  isDisabled
  aria-label="Disabled example"
  maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  isDisabled
  aria-label="Disabled example"
  maxWidth="size-3600">
  <TextField
    label="Name"
    placeholder="John Smith"
  />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">
      Dogs
    </Radio>
    <Radio value="cats">
      Cats
    </Radio>
  </RadioGroup>
</Form>

Required and necessity indicator#

Optional label

<Form
  necessityIndicator="label"
  aria-label="Optional with label example"
  maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  necessityIndicator="label"
  aria-label="Optional with label example"
  maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  necessityIndicator="label"
  aria-label="Optional with label example"
  maxWidth="size-3600">
  <TextField
    label="Name"
    placeholder="John Smith"
  />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">
      Dogs
    </Radio>
    <Radio value="cats">
      Cats
    </Radio>
  </RadioGroup>
</Form>

Required label

<Form
  isRequired
  necessityIndicator="label"
  aria-label="Required with label example"
  maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  isRequired
  necessityIndicator="label"
  aria-label="Required with label example"
  maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  isRequired
  necessityIndicator="label"
  aria-label="Required with label example"
  maxWidth="size-3600">
  <TextField
    label="Name"
    placeholder="John Smith"
  />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">
      Dogs
    </Radio>
    <Radio value="cats">
      Cats
    </Radio>
  </RadioGroup>
</Form>

Required with asterisk

<Form
  isRequired
  necessityIndicator="icon"
  aria-label="Required with asterisk example"
  maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  isRequired
  necessityIndicator="icon"
  aria-label="Required with asterisk example"
  maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  isRequired
  necessityIndicator="icon"
  aria-label="Required with asterisk example"
  maxWidth="size-3600">
  <TextField
    label="Name"
    placeholder="John Smith"
  />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">
      Dogs
    </Radio>
    <Radio value="cats">
      Cats
    </Radio>
  </RadioGroup>
</Form>

Read only#

<Form isReadOnly aria-label="isReadOnly example" maxWidth="size-3600">
  <TextField label="Name" value="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  isReadOnly
  aria-label="isReadOnly example"
  maxWidth="size-3600">
  <TextField label="Name" value="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  isReadOnly
  aria-label="isReadOnly example"
  maxWidth="size-3600">
  <TextField
    label="Name"
    value="John Smith"
  />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">
      Dogs
    </Radio>
    <Radio value="cats">
      Cats
    </Radio>
  </RadioGroup>
</Form>

Validation state#

<Form
  validationState="invalid"
  aria-label="Invalid validationState example"
  maxWidth="size-3600"
  marginBottom="size-300">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  validationState="invalid"
  aria-label="Invalid validationState example"
  maxWidth="size-3600"
  marginBottom="size-300">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  validationState="invalid"
  aria-label="Invalid validationState example"
  maxWidth="size-3600"
  marginBottom="size-300">
  <TextField
    label="Name"
    placeholder="John Smith"
  />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">
      Dogs
    </Radio>
    <Radio value="cats">
      Cats
    </Radio>
  </RadioGroup>
</Form>
<Form
  validationState="valid"
  aria-label="Valid validationState example"
  maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  validationState="valid"
  aria-label="Valid validationState example"
  maxWidth="size-3600">
  <TextField label="Name" placeholder="John Smith" />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">Dogs</Radio>
    <Radio value="cats">Cats</Radio>
  </RadioGroup>
</Form>
<Form
  validationState="valid"
  aria-label="Valid validationState example"
  maxWidth="size-3600">
  <TextField
    label="Name"
    placeholder="John Smith"
  />
  <RadioGroup label="Favorite pet">
    <Radio value="dogs">
      Dogs
    </Radio>
    <Radio value="cats">
      Cats
    </Radio>
  </RadioGroup>
</Form>