Skip to main content
Neighborhood Design System v5.1.0

Textarea

Ready

A multi-line text field for longer answers, such as comments and messages, with help and error text, resizing and form support.

Preview

Open in Storybook (opens in new tab)

Code

Install
npm install @fbin-web/neighborhood-core
Import
import { NbhdTextarea } from '@fbin-web/neighborhood-core';
Usage
<nbhd-textarea
  name="the-textarea"
  id="id"
  help-text="This is some help text for the textarea."
  error-text="This is an error message for the textarea."
  title="the textarea"
  label="Form Label"
  resize="vertical"
  maxlength="500"
  spellcheck="true">
</nbhd-textarea>

Properties

PropertyAttributeTypeDefaultDescription
surfacesurfacenoneprimarysecondaryinverseinverse-secondaryprimarySets the surface color treatment for the textarea.
placeholderplaceholderstring—Placeholder text displayed when the textarea is empty.
valuevaluestring—The current value of the textarea.
namenamestring—The form field name the textarea submits under.
formformstring—The id of a
elsewhere on the page to belong to, like a native field's `form` attribute.
labellabelstring—The label text for the textarea.
titletitlestring—The title attribute for the textarea.
ididstring—The id of the textarea element.
cssClasscss-classstring—Additional CSS classes to apply to the textarea.
ariaLabelaria-labelstring—Accessible label for screen readers. Use it when the design has no visible label.
resizeresizenoneverticalhorizontalbothbothWhich directions the visitor can drag to resize the textarea.
errorTexterror-textstring—Error message text to display when invalid. Defaults to "This field has an error." when empty.
helpTexthelp-textstring—Help text to provide additional context.
maxlengthmaxlengthnumber—Maximum length of the textarea value.
minlengthminlengthnumber—Minimum length of the textarea value.
invalidinvalidbooleanfalseShows the error state and error text. It doesn't block form submission; use `setCustomValidity()` for that.
disableddisabledbooleanfalseDisables the textarea.
requiredrequiredbooleanfalseMarks the textarea as required.
readonlyreadonlybooleanfalseMakes the textarea read-only.
autofocusautofocusbooleanfalseAutomatically focuses the textarea when the page loads.
spellcheckspellcheckbooleantrueWhether to enable spell checking.

Events

NameDescriptionEvent Detail
nbhd-changeEmitted as the value changes, while typing and when the textarea loses focus.{ value: string }
changeEmitted alongside nbhd-change.{ value: string }

Form methods

Form-associated: inside a it submits under its `name`, resets with the form, is disabled by a disabled

, and mirrors the native textarea’s validation (required, minlength, maxlength). Enter adds a new line rather than submitting the form. A page-level

Slots

NameDescription
labelCustom content for the textarea label. Defaults to the label property value.
helpHelp text content displayed below the textarea when not in an invalid state.
errorError message content displayed below the textarea when in an invalid state.

CSS Parts

NameDescription
labelThe label element for the textarea.
label-slotThe slot element inside the label.
label-textThe text element that displays the label content.
requiredThe required marker (*) shown in the label when required. Hidden from assistive technology, which announces the native required state.
fieldThe wrapper div containing the textarea element.
textareaThe textarea element.
textThe wrapper div for help and error text.
helpThe help slot element.
errorThe error slot element.
nbhd-textarea::part(label) {
  /* your styles */
}

CSS Properties

Set these on nbhd-textarea or an ancestor to override the defaults. Token is the design token a default comes from and Value is what it resolves to in core Neighborhood; brands may override them. Properties that adapt to surface follow the light or inverse surface they sit on until you set them.

Textarea

PropertyTokenValue Copy
--nbhd-textarea-backgroundColor--nbhd-context-color-control-backgroundAdapts to surface
--nbhd-textarea-borderColor--nbhd-context-color-control-borderAdapts to surface
--nbhd-textarea-borderRadius--nbhd-border-radius-none0
--nbhd-textarea-borderStyle—solid
--nbhd-textarea-borderWidth--nbhd-border-width-subtle1px
--nbhd-textarea-focus-outlineColor--nbhd-context-color-focus-outlineAdapts to surface
--nbhd-textarea-focus-outlineOffset--nbhd-space-00px
--nbhd-textarea-focus-outlineStyle--nbhd-focus-control-outlineStylesolid
--nbhd-textarea-focus-outlineWidth--nbhd-border-width-subtle1px
--nbhd-textarea-fontFamily--nbhd-typography-body-fontFamilysans-serif
--nbhd-textarea-fontSize--nbhd-typography-body-fontSize1rem
--nbhd-textarea-host-display—block
--nbhd-textarea-inlineSize—100%
--nbhd-textarea-lineHeight--nbhd-typography-body-lineHeight1.5
--nbhd-textarea-paddingBlock--nbhd-space-28px
--nbhd-textarea-paddingInline--nbhd-space-312px
--nbhd-textarea-resize—both

Form control

PropertyTokenValue Copy
--nbhd-formControl-display—inline
--nbhd-formControl-field-appearance—none
--nbhd-formControl-field-borderRadius--nbhd-border-radius-none0
--nbhd-formControl-field-color--nbhd-context-color-control-foregroundAdapts to surface
--nbhd-formControl-field-display—inline-block
--nbhd-formControl-field-fontFamily--nbhd-typography-body-fontFamilysans-serif
--nbhd-formControl-field-fontSize--nbhd-typography-body-fontSize1rem
--nbhd-formControl-field-inlineSize—100%
--nbhd-formControl-field-position—relative
--nbhd-formControl-fontFamily--nbhd-typography-body-fontFamilysans-serif
--nbhd-formControl-host-display—block
--nbhd-formControl-label-color--nbhd-context-color-text-primaryAdapts to surface
--nbhd-formControl-label-display—block
--nbhd-formControl-label-fontFamily--nbhd-typography-label-fontFamilysans-serif
--nbhd-formControl-label-fontSize--nbhd-typography-label-fontSize1rem
--nbhd-formControl-label-fontWeight--nbhd-typography-label-fontWeight600
--nbhd-formControl-label-letterSpacing—inherit
--nbhd-formControl-label-marginBlock--nbhd-space-0 --nbhd-space-050px 2px
--nbhd-formControl-label-position—relative
--nbhd-formControl-label-textTransform—inherit
--nbhd-formControl-marginBlock--nbhd-space-00px
--nbhd-formControl-maxInlineSize—100%
--nbhd-formControl-paddingBlock--nbhd-space-00px
--nbhd-formControl-paddingInline--nbhd-space-00px
--nbhd-formControl-position—relative
--nbhd-formControl-required-gap--nbhd-space-052px
--nbhd-formControl-text-marginBlock--nbhd-space-1 --nbhd-space-04px 0px

Dependencies

Child components <nbhd-textarea> renders internally. Import them too when you tree-shake.

Esc
↑ ↓ to move↵ to open