import type { ChangeEventHandler, ReactNode } from 'react'; import React from 'react'; import type { EitherInclusive, ForwardedRefComponent, IconOrContent } from '../../util/utility-types'; import type { Status } from '../../util/variant-types'; import FieldLabel from '../FieldLabel'; import Input from '../Input'; export type InputFieldProps = React.InputHTMLAttributes & { /** * CSS class names that can be appended to the component. */ className?: string; /** * Default value passed down from higher levels for initial state */ defaultValue?: string | number; /** * Disables the field and prevents editing the contents */ disabled?: boolean; /** * HTML id for the component */ id?: string; /** * Gives a hint as to the type of data needed for text input (e.g., to render the correct input keyboard on mobile). */ inputMode?: React.InputHTMLAttributes['inputMode']; /** * Node(s) that can be nested within the input field (e.g., secondary and tertiary `Button` components) * * The space reserved for this content is measured from what you pass in, so the content is free * to be as wide as it needs. To reserve a fixed amount instead, set * `--input-field__input-within-width` via `style`. */ inputWithin?: ReactNode; /** * Maximum value allowed for the input, if type is 'number'. */ max?: number | string; /** * Minimum value allowed for the input, if type is 'number'. */ min?: number | string; /** * HTML name attribute for the input */ name?: string; /** * Function that runs on change of the input */ onChange?: ChangeEventHandler; /** * Toggles the form control's interactivity. When `readOnly` is set to `true`, the form control is not interactive */ readOnly?: boolean; /** * CSS properties defined for the input element. Includes the component's CSS Custom Properties: * * - `--input-field__input-within-width` */ style?: InputFieldCSSProperties; /** * Title attribute on input */ title?: string; /** * HTML type attribute, allowing switching between text, password, and other HTML5 input field types * * **NOTE**: this excludes types that correspond to non-text controls, like `checkbox`, `radio`, etc. */ type?: Extract['type'], 'text' | 'password' | 'datetime-local' | 'date' | 'month' | 'time' | 'week' | 'number' | 'email' | 'url' | 'search' | 'tel'>; /** * Value passed down from higher levels for initial state */ value?: string | number; /** * Text under the textarea used to provide validation hints or error message to describe the input error. */ fieldNote?: ReactNode; /** * Content that prefixes the field input. Pass an EDS icon name to render a decorative * icon, or a node to render it as-is. */ leadingContent?: IconOrContent; /** * Placeholder attribute for input. Note: placeholder should be used sparingly */ placeholder?: string; /** * Behaves similar to `maxLength` but allows the user to continue typing more text. * Should not be larger than `maxLength`, if present. */ recommendedMaxLength?: number; /** * Indicates that field is required for form to be successfully submitted. Consumers must implement handling for error states using `status="critical"` */ required?: boolean; /** * Whether it should show the field hint or not * * **Default is `"false"`**. */ showHint?: boolean; /** * Status for the field state. Use `"critical"` for an error state. * * **Default is `"default"`**. */ status?: 'default' | Extract; /** * Add additional descriptive text for the field name. */ subLabel?: ReactNode; } & EitherInclusive<{ /** * Visible text label for the component. */ label: string; }, { /** * Aria-label to provide an accesible name for the text input if no visible label is provided. */ 'aria-label': string; }>; export interface InputFieldCSSProperties extends React.CSSProperties { /** * The space reserved at the trailing edge of the input for `inputWithin` content. The component * measures this from the rendered content, so it only needs setting to override that measurement * with a fixed size. */ '--input-field__input-within-width'?: string; } type InputFieldType = ForwardedRefComponent & { Input?: typeof Input; Label?: typeof FieldLabel; }; /** * ## Usage * * **NOTE**: This component requires a `label` or `aria-label` prop. * * | Type/Use | Description | Example | * |----------|-------------|---------| * | Text | Standard single-line input for free-form text. | Name fields, search bars, tags. | * | Search | Optimized for searching, often with a search icon or clear button. | Site/app search bars, filter queries. | * | Date/Time | Opens a date/time picker depending on browser support. | Scheduling. | * | Masked | Formats input while typing. | Passwords, phone numbers, credit card entries. | * | Disabled/Read-Only | Prevents user interaction or editing. | Prefilled info, summary/review forms. | * | Validation | Displays real-time validation (e.g., success, error states). | Required fields, format enforcement. | * * ## Interaction * * When the text exceeds the available space, it scrolls to show the end of the string. * * ## Content & Accessibility * * ### Do's * * * Use short, precise labels in sentence case. * * Use helper text only when necessary, preferring examples (e.g., yourname@emaildomain.com) over instructions. * * For errors, provide instructions for fixing the issue and explain what is happening. * * Use `fieldNote` for examples or instructions explaining what should be entered. * * Set `maxLength` on every free-text field (`text`, `search`, `email`, `url`, `tel`, `password`) so there's a hard cap on what can be entered. Use `recommendedMaxLength` alongside it to show a lower, soft limit. Enforce the same limit on the server, since `maxLength` only constrains the browser. * * ### Don'ts * * * Don't use colons or periods at the end of labels, and don't omit labels. * * Don't use placeholder text within the field; it can cause accessibility issues. * * Don't stack field notes on top of error messages. */ export declare const InputField: InputFieldType; export {};