Input
ReadyA customizable text input component for collecting user data with support for various input types, validation, and styling options.
Preview
Code
Install
npm install @fbin-web/neighborhood-core
Import
import { NbhdInput } from '@fbin-web/neighborhood-core';
Usage
<nbhd-input
type="text"
inputmode="text"
name="the-input"
id="id"
help-text="This is some help text for the input."
error-text="This is an error message for the input."
title="the input"
label="Form Label"
autocomplete="off"
spellcheck="true">
</nbhd-input>
Install
npm install @fbin-web/neighborhood-react
Import
import { NbhdInput } from '@fbin-web/neighborhood-react';
Usage
import { NbhdInput } from '@fbin-web/neighborhood-react';
const App = () => (
<>
<NbhdInput
type="text"
inputmode="text"
name="the-input"
id="id"
title="the input"
label="Form Label"
helpText="This is some help text for the input."
errorText="This is an error message for the input."
autocomplete="off"
spellcheck={true}></NbhdInput>
</>
);
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
surface | surface | noneprimarysecondaryinverseinverse-secondary | primary | Sets the surface color treatment for the input. |
type | type | textdatedatetime-localtelnumbersearchemailpassword | text | The type of input element. |
inputmode | inputmode | nonetextdecimalnumerictelsearchemailurl | — | Hints at the type of data that might be entered for mobile keyboards. |
spellcheck | spellcheck | boolean | true | Whether to enable spell checking. |
placeholder | placeholder | string | — | Placeholder text displayed when the input is empty. |
value | value | string | — | The current value of the input. |
name | name | string | — | The name of the input for form submission. The form field name it submits under. |
label | label | string | — | The label text for the input. |
title | title | string | — | The title attribute for the input. |
id | id | string | — | The id of the input element. |
cssClass | css-class | string | — | Additional CSS classes to apply to the input. |
ariaLabel | aria-label | string | — | Descriptive text for additional context. |
errorText | error-text | string | — | Error message text to display when invalid. Defaults to "This field has an error." when empty. |
helpText | help-text | string | — | Help text to provide additional context. |
pattern | pattern | string | — | Regular expression pattern for validation. |
maxlength | maxlength | number | — | Maximum length of the input value. |
minlength | minlength | number | — | Minimum length of the input value. |
max | max | numberstring | — | Maximum value for number or date inputs. |
min | min | numberstring | — | Minimum value for number or date inputs. |
invalid | invalid | boolean | false | Marks the input as invalid for validation. |
disabled | disabled | boolean | false | Disables the input. |
required | required | boolean | false | Marks the input as required. |
autofocus | autofocus | boolean | false | Automatically focuses the input when the page loads. |
readonly | readonly | boolean | false | Makes the input read-only. |
autocomplete | autocomplete | string | — | Controls browser autocomplete behavior. |
autocorrect | autocorrect | boolean | true | Controls whether the browser may automatically correct input text. |
No properties match.
Events
| Name | Description | Event Detail |
|---|---|---|
nbhd-change | Emitted as the value changes, while typing and when the input loses focus. | { value: string } |
change | Emitted alongside nbhd-change. | { value: string } |
Form methods
Form-associated: inside a
Slots
| Name | Description |
|---|---|
label | Custom content for the input label. Defaults to the label property value. |
help | Help text content displayed below the input when not in an invalid state. |
error | Error message content displayed below the input when in an invalid state. |
CSS Parts
| Name | Description |
|---|---|
base | The form control wrapper div. |
label | The label element for the input. |
label-slot | The slot element inside the label. |
label-text | The text element that displays the label content. |
required | The required marker (*) shown in the label when required. Hidden from assistive technology, which announces the native required state. |
field | The wrapper div containing the input element. |
input | The input element. |
text | The wrapper div for help and error text. |
help | The help slot element. |
error | The error slot element. |
No css parts match.
nbhd-input::part(base) {
/* your styles */
}
CSS Properties
Set these on nbhd-input 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.
Input
| Property | Token | Value | Copy |
|---|---|---|---|
--nbhd-input-backgroundColor | --nbhd-context-color-control-background | Adapts to surface | |
--nbhd-input-borderColor | --nbhd-context-color-control-border | Adapts to surface | |
--nbhd-input-borderRadius | --nbhd-border-radius-none | 0 |
|
--nbhd-input-borderStyle | — | solid |
|
--nbhd-input-borderWidth | --nbhd-border-width-subtle | 1px |
|
--nbhd-input-focus-outlineColor | --nbhd-context-color-focus-outline | Adapts to surface | |
--nbhd-input-focus-outlineOffset | --nbhd-space-0 | 0px |
|
--nbhd-input-focus-outlineStyle | --nbhd-focus-control-outlineStyle | solid |
|
--nbhd-input-focus-outlineWidth | --nbhd-border-width-subtle | 1px |
|
--nbhd-input-fontFamily | --nbhd-typography-body-fontFamily | sans-serif |
|
--nbhd-input-fontSize | --nbhd-typography-body-fontSize | 1rem |
|
--nbhd-input-host-display | — | block |
|
--nbhd-input-inlineSize | — | 100% |
|
--nbhd-input-lineHeight | --nbhd-typography-body-lineHeight | 1.5 |
|
--nbhd-input-paddingBlock | --nbhd-space-2 | 8px |
|
--nbhd-input-paddingInline | --nbhd-space-3 | 12px |
No input match.
Form control
| Property | Token | Value | Copy |
|---|---|---|---|
--nbhd-formControl-display | — | inline |
|
--nbhd-formControl-field-appearance | — | none |
|
--nbhd-formControl-field-borderRadius | --nbhd-border-radius-none | 0 |
|
--nbhd-formControl-field-color | --nbhd-context-color-control-foreground | Adapts to surface | |
--nbhd-formControl-field-display | — | inline-block |
|
--nbhd-formControl-field-fontFamily | --nbhd-typography-body-fontFamily | sans-serif |
|
--nbhd-formControl-field-fontSize | --nbhd-typography-body-fontSize | 1rem |
|
--nbhd-formControl-field-inlineSize | — | 100% |
|
--nbhd-formControl-field-position | — | relative |
|
--nbhd-formControl-fontFamily | --nbhd-typography-body-fontFamily | sans-serif |
|
--nbhd-formControl-host-display | — | block |
|
--nbhd-formControl-label-color | --nbhd-context-color-text-primary | Adapts to surface | |
--nbhd-formControl-label-display | — | block |
|
--nbhd-formControl-label-fontFamily | --nbhd-typography-label-fontFamily | sans-serif |
|
--nbhd-formControl-label-fontSize | --nbhd-typography-label-fontSize | 1rem |
|
--nbhd-formControl-label-fontWeight | --nbhd-typography-label-fontWeight | 600 |
|
--nbhd-formControl-label-letterSpacing | — | inherit |
|
--nbhd-formControl-label-marginBlock | --nbhd-space-0 --nbhd-space-05 | 0px 2px |
|
--nbhd-formControl-label-position | — | relative |
|
--nbhd-formControl-label-textTransform | — | inherit |
|
--nbhd-formControl-marginBlock | --nbhd-space-0 | 0px |
|
--nbhd-formControl-maxInlineSize | — | 100% |
|
--nbhd-formControl-paddingBlock | --nbhd-space-0 | 0px |
|
--nbhd-formControl-paddingInline | --nbhd-space-0 | 0px |
|
--nbhd-formControl-position | — | relative |
|
--nbhd-formControl-required-gap | --nbhd-space-05 | 2px |
|
--nbhd-formControl-text-marginBlock | --nbhd-space-1 --nbhd-space-0 | 4px 0px |
No form control match.
Dependencies
Child components <nbhd-input> renders internally. Import them too when you tree-shake.