@carbon/react
Version:
React components for the Carbon Design System
116 lines (115 loc) • 3.64 kB
TypeScript
/**
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import React, { type ReactNode } from 'react';
type ExcludedAttributes = 'defaultValue' | 'id' | 'size' | 'value';
export interface TextInputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, ExcludedAttributes> {
/**
* Specify an optional className to be applied to the `<input>` node
*/
className?: string;
/**
* **Experimental**: Provide a `decorator` component to be rendered inside the `TextInput` component
*/
decorator?: ReactNode;
/**
* Optionally provide the default value of the `<input>`
*/
defaultValue?: string | number;
/**
* Specify whether the `<input>` should be disabled
*/
disabled?: boolean;
/**
* Specify whether to display the character counter
*/
enableCounter?: boolean;
/**
* Provide text that is used alongside the control label for additional help
*/
helperText?: ReactNode;
/**
* Specify whether you want the underlying label to be visually hidden
*/
hideLabel?: boolean;
/**
* Specify a custom `id` for the `<input>`
*/
id: string;
/**
* `true` to use the inline version.
*/
inline?: boolean;
/**
* Specify whether the control is currently invalid
*/
invalid?: boolean;
/**
* Provide the text that is displayed when the control is in an invalid state
*/
invalidText?: ReactNode;
/**
* Provide the text that will be read by a screen reader when visiting this
* control
*/
labelText: ReactNode;
/**
* `true` to use the light version. For use on $ui-01 backgrounds only.
* Don't use this to make tile background color same as container background color.
* 'The `light` prop for `TextInput` has ' +
'been deprecated in favor of the new `Layer` component. It will be removed in the next major release.'
*/
light?: boolean;
/**
* Max character count allowed for the input. This is needed in order for enableCounter to display
*/
maxCount?: number;
/**
* Optionally provide an `onChange` handler that is called whenever `<input>`
* is updated
*/
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
/**
* Optionally provide an `onClick` handler that is called whenever the
* `<input>` is clicked
*/
onClick?: (event: React.MouseEvent<HTMLElement>) => void;
/**
* Specify the placeholder attribute for the `<input>`
*/
placeholder?: string;
/**
* Whether the input should be read-only
*/
readOnly?: boolean;
/**
* Specify the size of the Text Input. Currently supports the following:
*/
size?: 'sm' | 'md' | 'lg' | 'xl';
/**
* @deprecated please use `decorator` instead.
* **Experimental**: Provide a `Slug` component to be rendered inside the `TextInput` component
*/
slug?: ReactNode;
/**
* Specify the type of the `<input>`
*/
type?: string;
/**
* Specify the value of the `<input>`
*/
value?: string | number | undefined;
/**
* Specify whether the control is currently in warning state
*/
warn?: boolean;
/**
* Provide the text that is displayed when the control is in warning state
*/
warnText?: ReactNode;
}
declare const TextInput: React.ForwardRefExoticComponent<TextInputProps & React.RefAttributes<unknown>>;
export default TextInput;