Skip to main content

What are you looking for?

Try searching for…

Components

Input

Input is a form element used to collect user data. It offers basic functionality and is ideal when you need full control over the component's layout and validation, making it suitable for building custom elements.

HTML

Press Enter to start editing
Unable to parse html
const Preview = () => {
  return <Input aria-label='input' />;
};

render(<Preview />)

Usage

The class ds-input is used on most form controls, such as <input>, <textarea>, and <select>.

For a valid form element, we recommend using <ds-field> together with a <label>.

CSS variables and data attributes

Sizes are controlled with data-size and colors with data-color. The component will inherit from the closest parent where these are set.

CSS Variables
NameValue
--dsc-input-padding-blockvar(--ds-size-2)
--dsc-input-padding-inlinevar(--ds-size-3)
--dsc-input-paddingvar(--dsc-input-padding-block) var(--dsc-input-padding-inline)
--dsc-input-size--togglevar(--ds-size-6)
--dsc-input-sizevar(--ds-size-12)
--dsc-input-background--readonlyvar(--ds-color-neutral-surface-tinted)
--dsc-input-backgroundvar(--ds-color-neutral-surface-default)
--dsc-input-border-color--readonlyvar(--ds-color-neutral-border-subtle)
--dsc-input-border-colorvar(--ds-color-neutral-border-default)
--dsc-input-border-stylesolid
--dsc-input-border-width--togglemax(var(--ds-border-width-default),calc(var(--ds-size-1)/2))
--dsc-input-border-widthvar(--ds-border-width-default)
--dsc-input-outline-color--hovervar(--ds-color-neutral-border-default)
--dsc-input-outline-color--toggle--hovervar(--dsc-input-accent-color)
--dsc-input-outline-width--hovervar(--ds-border-width-default)
--dsc-input-outline-style--hoversolid
--dsc-input-color--readonlyvar(--ds-color-neutral-text-default)
--dsc-input-colorvar(--ds-color-neutral-text-default)
--dsc-input-stroke-colorvar(--ds-color-base-contrast-default)
--dsc-input-stroke-color--invalidvar(--ds-color-danger-base-contrast-default)
--dsc-input-stroke-width0.05em
--dsc-input-accent-colorvar(--ds-color-base-default)
--dsc-input-accent-color--invalidvar(--ds-color-danger-text-subtle)
--dsc-input-line-heightvar(--ds-line-height-md)
Data Attributes
NameValue
data-widthauto

Examples

ReadOnly

React

type
Description

Supported `input` types

Type
"number" | "hidden" | "color" | "checkbox" | "date" | "datetime-local" | "email" | "file" | "month" | "password" | "radio" | "search" | "tel" | "text" | "time" | "url" | "week"
Default
text
size
Description

Defines the width of `Input` in count of characters.

Type
number
disabled
Description

Disables element @note Avoid using if possible for accessibility purposes

Type
boolean
readOnly
Description

Toggle `readOnly`

Type
boolean
role
Description

Set role, i.e. `switch` when `checkbox` or `radio`

Type
AriaRole
data-indeterminate
Description

Indeterminate state for checkbox inputs Only works when used inside `Field` component

Type
boolean
Default
false
NameTypeDefaultDescription
type"number" | "hidden" | "color" | "checkbox" | "date" | "datetime-local" | "email" | "file" | "month" | "password" | "radio" | "search" | "tel" | "text" | "time" | "url" | "week"text

Supported `input` types

sizenumber-

Defines the width of `Input` in count of characters.

disabledboolean-

Disables element @note Avoid using if possible for accessibility purposes

readOnlyboolean-

Toggle `readOnly`

roleAriaRole-

Set role, i.e. `switch` when `checkbox` or `radio`

data-indeterminatebooleanfalse

Indeterminate state for checkbox inputs Only works when used inside `Field` component

Type values

Input exposes only supported type values. You can see the valid type values in the dropdown below.

Edit this page on github.com (opens in a new tab)