Input
Overview
The Input component provides a Bulma-styled text input, supporting colors, sizes, rounded corners, static state, hover/focus/loading states, and Bulma helper props.
It is suitable for all standard text input types.
Import
import {
Input,
Field,
Control,
Button,
Select,
Icon,
} from '@allxsmith/bestax-bulma';
Usage
Input is a convenience component that internally composes Field and Control. For most form fields, use <Input> directly with its props (label, color, size, iconLeftName, message, horizontal, etc.). Reach for explicit <Field> + <Control> composition only when you need a layout the convenience props can't express — most commonly form addons, grouped controls, or horizontal layouts that mix multiple sub-fields.
Default Input
A standard text input. The placeholder prop provides hint text for the user.
<Input label="Default" placeholder="Default input" />
Color Inputs
The color prop applies Bulma color modifiers to the input. Use it to visually distinguish input fields based on context or validation state.
<> <Input label="Primary" color="primary" placeholder="Primary input" /> <Input label="Link" color="link" placeholder="Link input" /> <Input label="Info" color="info" placeholder="Info input" /> <Input label="Success" color="success" placeholder="Success input" /> <Input label="Warning" color="warning" placeholder="Warning input" /> <Input label="Danger" color="danger" placeholder="Danger input" /> </>
Sizes
The size prop controls the input's size. Options: "small", "medium", "large" (default is normal).
<> <Input label="Small" size="small" placeholder="Small input" /> <Input label="Normal" placeholder="Normal input" /> <Input label="Medium" size="medium" placeholder="Medium input" /> <Input label="Large" size="large" placeholder="Large input" /> </>
Style: Rounded
The isRounded prop gives the input rounded corners for a softer appearance.
<Input label="Rounded" isRounded placeholder="Rounded input" />
States
isHovered, isFocused, and isLoading force the corresponding state on the input. A screen reader doesn't hear the spinner, so the loading one says so in its message as well.
<> <Input label="Normal" placeholder="Normal state" /> <Input label="Hover" isHovered placeholder="Hovered state" /> <Input label="Focus" isFocused placeholder="Focused state" /> <Input label="Loading" isLoading message="Loading…" placeholder="Loading state" /> </>
Loading States by Size
The loading indicator at every input size. Use controlSize on <Input> to scale the spinner to match.
<> <Input label="Loading Small" size="small" controlSize="small" isLoading message="Loading…" placeholder="Loading small" /> <Input label="Loading Normal" isLoading message="Loading…" placeholder="Loading normal" /> <Input label="Loading Medium" size="medium" controlSize="medium" isLoading message="Loading…" placeholder="Loading medium" /> <Input label="Loading Large" size="large" controlSize="large" isLoading message="Loading…" placeholder="Loading large" /> </>
Disabled & Read Only
Disabled inputs cannot be interacted with; read-only inputs can be focused but not edited.
<> <Input label="Disabled" disabled placeholder="Disabled input" /> <Input label="Read Only" readOnly value="Read only value" /> </>
Static State
The isStatic prop styles the input as static text, useful for displaying values alongside editable fields. It changes only the styling, so the example adds readOnly to stop edits.
<> <Input horizontal label="Username" isStatic readOnly value="Static value" /> <Input horizontal label="Password" placeholder="Editable value" /> </>
With Icons (Left and Right)
Add icons via the iconLeftName / iconRightName shortcuts on <Input>.
<> <Input label="Username" iconLeftName="user" iconRightName="check" placeholder="With icons" /> <Input label="Email" iconLeftName="envelope" iconRightName="exclamation-triangle" placeholder="Another input" /> </>
With Icons and Size Variations
Match the input size to the icon size via the size + iconLeftSize / iconRightSize props.
<> <Input label="Small" size="small" iconLeftName="user" iconLeftSize="small" iconRightName="check" iconRightSize="small" placeholder="Icons left/right small" /> <Input label="Normal" iconLeftName="user" iconRightName="check" placeholder="Icons left/right normal" /> <Input label="Medium" size="medium" iconLeftName="user" iconLeftSize="medium" iconRightName="check" iconRightSize="medium" placeholder="Icons left/right medium" /> <Input label="Large" size="large" iconLeftName="user" iconLeftSize="large" iconRightName="check" iconRightSize="large" placeholder="Icons left/right large" /> </>
Help Text Colors
Pair color and messageColor to produce success and danger validation states with matching help text.
<> <Input autoComplete="username" label="Username" color="success" value="bulma" message="This username is available" messageColor="success" iconLeftName="user" iconRightName="check" onChange={() => {}} /> <Input autoComplete="email" label="Email" type="email" color="danger" value="hello@" message="This email is invalid" messageColor="danger" iconLeftName="envelope" iconRightName="exclamation-triangle" onChange={() => {}} /> </>
Visually Hidden Label for Screen Readers
A field the design shows with no label still needs one for screen readers. Keep the label and hide it from view with labelProps={{ className: 'is-sr-only' }}. It stays the input's name and takes no space. visibility="sr-only" on the Input won't do it: Input puts its helper props on the <input>, so that hides the input instead.
<Input autoComplete="email" label="Email" labelProps={{ className: 'is-sr-only' }} type="email" placeholder="[email protected]" />
Form Addons
For multi-control rows like input + button, drop down to manual Field + Control composition. Use <Field hasAddons> with multiple <Control> children. Use <Control isExpanded> on the input so it fills the available space.
A hasAddons Field names none of the controls it holds, and a placeholder disappears once the reader starts typing, so give each input a name of its own: a visible label on an outer Field, wired to it with labelProps={{ htmlFor }} and a matching id, as these examples do, or an aria-label, as the country code Select below has.
Input + Button
<Field label="Repository" labelProps={{ htmlFor: 'addons-repository' }}> <Field hasAddons> <Control isExpanded> <Input id="addons-repository" placeholder="Find a repository" /> </Control> <Control> <Button color="info">Search</Button> </Control> </Field> </Field>
Input + Static Suffix
A static button draws a fixed prefix or suffix, such as an email domain. isStatic only styles it, so render it as="span", which Tab skips and a screen reader reads as text.
<Field label="Email" labelProps={{ htmlFor: 'addons-email-username' }}> <Field hasAddons> <Control isExpanded> <Input id="addons-email-username" placeholder="Your email" /> </Control> <Control> <Button as="span" isStatic> @gmail.com </Button> </Control> </Field> </Field>
Select + Input + Button
<Field label="Phone number" labelProps={{ htmlFor: 'addons-phone' }}> <Field hasAddons> <Control> <Select autoComplete="tel-country-code" aria-label="Country code"> <option>+1</option> <option>+44</option> <option>+33</option> </Select> </Control> <Control isExpanded> <Input autoComplete="tel-national" id="addons-phone" type="tel" placeholder="Your phone number" /> </Control> <Control> <Button color="primary">Call</Button> </Control> </Field> </Field>
Centered Addons
Pass hasAddons="centered" to center the addon group on the row.
<Field hasAddons="centered"> <Control> <Button>Yes</Button> </Control> <Control> <Button>Maybe</Button> </Control> <Control> <Button>No</Button> </Control> </Field>
Right-Aligned Addons
Pass hasAddons="right" to right-align the group.
<Field hasAddons="right"> <Control> <Button>Yes</Button> </Control> <Control> <Button>Maybe</Button> </Control> <Control> <Button>No</Button> </Control> </Field>
Password Reveal
A password field with a button that shows what was typed is PasswordInput. Its button sits inside the field and leaves focus there, and the field asks for autocomplete="current-password", turns spellcheck off and hides the password again when its form submits.
<PasswordInput label="Password" />
Copy Button
A copy field is an addon: a read-only Input holding the text, and a CopyButton in the second Control. The button writes the text, falling back to the older copy command where the Clipboard API is missing or refused, reads "Copied" for a moment, and announces the result itself. Its announcement is portaled out of the Control, so Bulma still joins the two.
When nothing can write, a line under the field explains, and the input takes focus with its text selected, so the reader can copy it themselves. The line is the input's description (aria-describedby), and the field takes focus only once it's in the page, so a screen reader reads the instruction with the field. The button's own short failure status is the only announcement.
function ShareLink() { const id = React.useId(); const helpId = `${id}-help`; const inputRef = React.useRef<HTMLInputElement>(null); // Counts the failed copies in a row, so each one moves focus. const [failures, setFailures] = useState(0); const link = 'https://bestax.io/docs/api/form/input'; // Focus the field once its description is in the page, so a screen // reader reads the instruction with the field. useEffect(() => { if (failures === 0) return; inputRef.current?.focus(); inputRef.current?.select(); }, [failures]); return ( <Field label="Share link" labelProps={{ htmlFor: id }}> <Field hasAddons> <Control isExpanded> <Input ref={inputRef} id={id} value={link} readOnly aria-describedby={failures > 0 ? helpId : undefined} /> </Control> <Control> <CopyButton value={link} labels={{ failedStatus: "Couldn't copy the link" }} onCopiedChange={() => setFailures(0)} onCopyError={() => setFailures(count => count + 1)} /> </Control> </Field> {failures > 0 && ( <p id={helpId} className="help is-danger"> Couldn't copy automatically. The link is selected, so copy it from the field. </p> )} </Field> ); }
Choosing a Color
type="color" is the browser's own color well, with no JavaScript: a click opens the system's color dialog, and the value is a hex color such as #1e6b99. It always holds a color, so it can't be left empty, and required and placeholder don't apply to it. It takes alpha only in Safari, and Firefox for Android offers only preset colors. For an empty value, alpha, swatches, HSL, or one look on every device, use ColorPicker.
<Input type="color" label="Brand color" defaultValue="#1e6b99" />
Form Group
Use <Field grouped> to lay multiple controls out on a single row with consistent spacing — common for form action buttons and search-style rows.
Grouped Buttons
<Field grouped> <Control> <Button color="link">Submit</Button> </Control> <Control> <Button>Cancel</Button> </Control> </Field>
Centered Group
<Field grouped="centered"> <Control> <Button color="link">Submit</Button> </Control> <Control> <Button>Cancel</Button> </Control> </Field>
Right-Aligned Group
<Field grouped="right"> <Control> <Button color="link">Submit</Button> </Control> <Control> <Button>Cancel</Button> </Control> </Field>
Expanded Input + Button
<Field label="Repository" labelProps={{ htmlFor: 'grouped-repository' }}> <Field grouped> <Control isExpanded> <Input id="grouped-repository" placeholder="Find a repository" /> </Control> <Control> <Button color="info">Search</Button> </Control> </Field> </Field>
Multiline Group
grouped="multiline" allows the row to wrap onto multiple lines.
<Field grouped="multiline"> {[ 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve', 'Thirteen', ].map(label => ( <Control key={label}> <Button>{label}</Button> </Control> ))} </Field>
Horizontal — Validation Error
Place a color="danger" Input and a danger help message inside the horizontal field body.
<Field horizontal label="Email" labelProps={{ htmlFor: 'invalid-email' }}> <Field.Body> <Field> <Control iconLeftName="envelope" iconRightName="exclamation-triangle"> <Input autoComplete="email" id="invalid-email" type="email" color="danger" value="hello@" onChange={() => {}} /> </Control> <p className="help is-danger">This email is invalid</p> </Field> </Field.Body> </Field>
Horizontal — Addons (Phone with Country Code)
Combine Field horizontal with a nested Field hasAddons inside the body to mix layouts.
<Field horizontal label="Phone" labelProps={{ htmlFor: 'phone-number' }}> <Field.Body> <Field hasAddons> <Control> <Button as="span" isStatic> +44 </Button> </Control> <Control isExpanded> <Input autoComplete="tel-national" id="phone-number" type="tel" placeholder="Your phone number" /> </Control> </Field> </Field.Body> </Field>
Horizontal — Submit Row
Use an empty Field.Label to align the submit button under the inputs above it.
<> <Field horizontal label="Name" labelProps={{ htmlFor: 'submit-row-name' }}> <Field.Body> <Field> <Control> <Input autoComplete="name" id="submit-row-name" placeholder="Your name" /> </Control> </Field> </Field.Body> </Field> <Field horizontal> <Field.Label /> <Field.Body> <Field> <Control> <Button color="primary">Submit</Button> </Control> </Field> </Field.Body> </Field> </>
Disabled Fieldset
Wrap several Inputs in a disabled Fieldset to disable every field at once.
<Fieldset variant="unstyled" disabled> <Input autoComplete="name" label="Name" placeholder="Your name" /> <Input autoComplete="email" label="Email" type="email" placeholder="Your email" /> </Fieldset>
Context-Aware Rendering
The Input component is context-aware: it detects whether it is already inside a Field or Control and adjusts its rendering accordingly. This means you can use it standalone with a label prop (it wraps itself in Field+Control), inside a Field (it skips its own Field), or inside both Field and Control (it renders only the raw input).
Default (with label)
The simplest usage — the component automatically renders its own Field and Control wrappers.
<Input autoComplete="username" label="Username" placeholder="Enter username" />
With Field Wrapper
When you need manual control over the Field layout (e.g., horizontal forms), wrap the component in Field. The component detects it's inside a Field and skips rendering its own.
A labeled Field that holds the Input directly names it with no extra wiring. In a horizontal form the label sits on the outer Field and the Input in an inner one, which starts its own scope, so these examples wire the label by hand with labelProps={{ htmlFor }} and a matching id.
function example() { return ( <Field horizontal label="Username" labelProps={{ htmlFor: 'username-field' }} > <Field.Body> <Field> <Input autoComplete="username" id="username-field" placeholder="Enter username" /> </Field> </Field.Body> </Field> ); }
With Field and Control Wrappers
For full manual control (e.g., adding icons via Control), wrap in both Field and Control. The component detects both and renders only its raw element.
function example() { return ( <Field horizontal label="Username" labelProps={{ htmlFor: 'username-field-control' }} > <Field.Body> <Field> <Control iconLeftName="user"> <Input autoComplete="username" id="username-field-control" placeholder="Enter username" /> </Control> </Field> </Field.Body> </Field> ); }
Inside a Control, Input renders no Control of its own, so the props it would hand one, such as isLoading, the icon props, controlSize and controlClassName, do nothing there and warn in development. Set them on that Control instead, as iconLeftName is above.
Inside a Control with no Field around it, Input renders no Field of its own either, unless you give it label, message, horizontal or fieldClassName. Those need a Field, so with any of them it keeps its own Field inside the Control and warns in development. Wrap the Control in a Field, as above, and set the label, horizontal and class name on that Field instead.
Accessibility
- Always provide a label. The
labelprop is automatically associated with the input (htmlForplus a generatedid, or your ownidif you pass one), so clicking the label focuses the input and assistive technology announces it. - When composing with
Fieldinstead, theField's ownlabelassociates with the input automatically when the input sits directly in that labeledFieldand has noidof its own. A nested unlabeledField(as in horizontal multi-field layouts) starts its own scope. With anidof your own, or across a nestedField, the label names the input only when you pass thatidaslabelProps={{ htmlFor }}. - Use the correct input
typefor semantics (text,email, etc.). - Help and errors: the
messagedescribes the input througharia-describedby, after any ids you pass there, so a screen reader reads it when the input takes focus. A redcolorsays nothing to a screen reader, so on an error also setaria-invalid, and put the error in themessage.
Related Components
Additional Resources
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | React.ReactNode | — | Field label. Automatically associated with the input via htmlFor — uses your id when provided, otherwise a generated one. Dropped inside an outer Field, whose own label associates instead when that Field generates a target id (not grouped/hasAddons, no explicit labelProps.htmlFor) and you set no id here. |
labelSize | 'small' | 'normal' | 'medium' | 'large' | — | Size for the label. |
labelProps | React.LabelHTMLAttributes<HTMLLabelElement> & { [key: string]: unknown; } | — | Props for the label element when the component renders its own Field; dropped inside an outer Field (use that Field's labelProps instead). An explicit htmlFor key — even undefined — overrides the automatic association and no id is generated. |
horizontal | boolean | false | Horizontal field layout. |
iconLeft | IconProps | React.ReactNode | — | Icon props for left icon. Bulma gives control icons pointer-events: none, so a clickable node here never receives a click. Put a button beside the input in its own addon Control instead. |
iconRight | IconProps | React.ReactNode | — | Icon props for right icon. Bulma gives control icons pointer-events: none, so a clickable node here never receives a click. Put a button beside the input in its own addon Control instead. |
iconLeftName | string | — | Shortcut for left icon name. |
iconRightName | string | — | Shortcut for right icon name. |
iconLeftSize | 'small' | 'medium' | 'large' | — | Shortcut for left icon size. |
iconRightSize | 'small' | 'medium' | 'large' | — | Shortcut for right icon size. |
hasIconsLeft | boolean | false | Force left icon container. |
hasIconsRight | boolean | false | Force right icon container. |
isLoading | boolean | false | Shows a loading spinner on the Control it renders. Under prefers-reduced-motion: reduce the spinner stops and stays drawn (with bestax's CSS loaded). The spinner sits at the right edge, where iconRight also sits, and the two overlap; leave the right icon out while loading. The spinner is only drawn, so a screen reader hears nothing of it. Say that the field is loading in text that describes it, tied to it with aria-describedby, which a screen reader reads when the field takes focus. A load that starts while the user is in the field, such as a search as they type, isn't reliably heard without a live region, such as a role="status" element. |
isExpanded | boolean | false | Expand the control. |
controlSize | 'small' | 'medium' | 'large' | — | Control size. |
message | React.ReactNode | — | Help or validation text under the input. It describes the input through aria-describedby, after any ids you pass there. |
messageColor | 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger' | — | Bulma color for the message. |
fieldClassName | string | — | Additional CSS classes for the Field. |
controlClassName | string | — | Additional CSS classes for the Control. |
color | 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger' | 'black' | 'dark' | 'light' | 'white' | — | Bulma color modifier for the input. |
size | 'small' | 'medium' | 'large' | — | Size modifier for the input. |
isRounded | boolean | false | Rounded input corners. |
isStatic | boolean | false | Styles the input as static text. It stays editable; add readOnly to stop edits. |
isHovered | boolean | false | Applies hovered state. |
isFocused | boolean | false | Applies focused state. |
className | string | — | Additional CSS classes to apply. |
disabled | boolean | false | Disabled input. |
readOnly | boolean | false | Read-only input. |
ref | React.Ref<HTMLInputElement> | — | Forwarded to the underlying element. |
... | All standard <input> attributes and Bulma helper props | — | See Helper Props |
CSS & Sass Variables
Input registers these variables on its own .input element. Override them there (or via className) — a value set on an ancestor is only inherited, and loses to the component-level declaration. See Theme.
| CSS Variable | Sass Variable | Default |
|---|---|---|
--bulma-input-h | $input-h | var(--bulma-scheme-h) |
--bulma-input-s | $input-s | var(--bulma-scheme-s) |
--bulma-input-l | $input-l | var(--bulma-scheme-main-l) |
--bulma-input-border-style | $input-border-style | solid |
--bulma-input-border-width | $input-border-width | var(--bulma-control-border-width) |
--bulma-input-border-l | $input-border-l | var(--bulma-border-l) |
--bulma-input-border-l-delta | $input-border-l-delta | 0% |
--bulma-input-border-color | $input-border-color | hsl(var(--bulma-input-h), var(--bulma-input-s), calc(var(--bulma-input-border-l) + var(--bulma-input-border-l-delta))) |
--bulma-input-hover-border-l-delta | $input-hover-border-l-delta | var(--bulma-hover-border-l-delta) |
--bulma-input-active-border-l-delta | $input-active-border-l-delta | var(--bulma-active-border-l-delta) |
--bulma-input-focus-h | $input-focus-h | var(--bulma-focus-h) |
--bulma-input-focus-s | $input-focus-s | var(--bulma-focus-s) |
--bulma-input-focus-l | $input-focus-l | var(--bulma-focus-l) |
--bulma-input-focus-shadow-size | $input-focus-shadow-size | var(--bulma-focus-shadow-size) |
--bulma-input-focus-shadow-alpha | $input-focus-shadow-alpha | var(--bulma-focus-shadow-alpha) |
--bulma-input-color-l | $input-color-l | var(--bulma-text-strong-l) |
--bulma-input-background-l | $input-background-l | var(--bulma-scheme-main-l) |
--bulma-input-background-l-delta | $input-background-l-delta | 0% |
--bulma-input-height | $input-height | var(--bulma-control-height) |
--bulma-input-shadow | $input-shadow | inset 0 0.0625em 0.125em hsla(var(--bulma-scheme-h), var(--bulma-scheme-s), var(--bulma-scheme-invert-l), 0.05) |
--bulma-input-placeholder-color | $input-placeholder-color | hsla(var(--bulma-text-h), var(--bulma-text-s), var(--bulma-text-strong-l), 0.3) |
--bulma-input-disabled-color | $input-disabled-color | var(--bulma-text-weak) |
--bulma-input-disabled-background-color | $input-disabled-background-color | var(--bulma-background) |
--bulma-input-disabled-border-color | $input-disabled-border-color | var(--bulma-background) |
--bulma-input-disabled-placeholder-color | $input-disabled-placeholder-color | hsla(var(--bulma-text-h), var(--bulma-text-s), var(--bulma-text-weak-l), 0.3) |
--bulma-input-arrow | $input-arrow | var(--bulma-link) |
--bulma-input-icon-color | $input-icon-color | var(--bulma-text-light) |
--bulma-input-icon-hover-color | $input-icon-hover-color | var(--bulma-text-weak) |
--bulma-input-icon-focus-color | $input-icon-focus-color | var(--bulma-link) |
--bulma-input-radius | $input-radius | var(--bulma-radius) |