TextInput
- Library
- UDS Base
- Repository
- github.com/telus/universal-design-system
- Package
- npmjs.com/package/@telus-uds/components-base
- Package version
- 1.6.1
Introduction
import { TextInput } from '@telus-uds/components-base'
A basic text input component. Use in forms or individually to receive user's input.
Guidance
Controlled component
If it is required that the state of the TextInput be controlled by the application or other external methods,
value and onChange props must be passed to the TextInput.
If the TextInput value should not be changed by user input, a readOnly prop must be provided.
Uncontrolled component
If it is not necessary to control the TextInput state, you can create one without a value prop.
In this case its value can be accessed within the onChange callback.
Getting feedback for entered values
Use the feedback prop to give the user feedback regarding their input (keep it as brief as possible).
You can affirm that the user's input was correct, or highlight errors that must be corrected by setting the
validation prop.
This component does not perform input validations, as that is an application level concern. You will need to track the value of your form fields and perform any required data validations either client side or server side, depending on the context.
Supplying a hint
Use a hint to succinctly clarify attributes of the expected input data, such as the expected format, or an indicator
that the field is optional. It is a more usable and accessible option than the HTML placeholder attribute.
hintcan be used beside the label (inline) or below- Label and inline hint text should not exceed 40 characters total, otherwise, use hint text below the label
- The
hintshould not be longer than 85 characters - The
hintshould not wrap more than 3 lines on all viewport sizes - Developers can use
hintPositionto re-position thehintbelow thelabelif the text supplied to the inlinehintwraps
Using a tooltip
When a more in-depth explanation is needed to fill out a TextInput properly, additional instructions may be provided
to the tooltip prop.
info
In order to support more advanced usages all additional props will be passed down to the React Native's
TextInput component. See React Native documentation for
supported props and React Native Web documentation for
their implementation on the web.
Appearance
TextInput has no visual variants, but its appearance may change based on the validation and inactive props.
Accessibility
TextInput is accessible to screen readers on both native platforms and Web. It will be announced with the label prop
if it is provided, and optionally described with the hint, tooltip and feedback.
info
Due to React Native's implementation of TextInput it's not possible to access the current value of the input by
passing a ref. You can only access it within the onChange callback.
Props
| Name | Type | Default | Description |
|---|---|---|---|
| variant | objectOf | {} | System variant prop, see variants for more details |
| value | string | If the input's state is to be controlled by a parent component, use this prop together with the `onChange` to pass down and update the lifted state. | |
| initialValue | string | Use this to set the initial value of an uncontrolled input. Updating `initialValue` will **not** update the actual value. | |
| inactive | bool | Disables all user interactions with the input. | |
| readOnly | bool | Makes it impossible to change the input's value. | |
| onChange | func | Use to react upon input's value changes. Required when the `value` prop is set. Will receive the input's value as an argument. | |
| tokens | custom | System tokens prop, see tokens for more details |