TextField
This component allows users to write or edit text.
Basic Usage
import { TextField } from '@krakentech/coral';
<TextField label="Text field" />;Properties
defaultValue
<TextField label="Text field" defaultValue="Roger Nesbit" />disabled
<TextField label="Text field" disabled />endIcon
<TextField label="Text field" endIcon={<IconCircleQuestionFilled />} />error / errorMessage
<TextField label="Text field" error errorMessage="Please fill out this field" />Please fill out this field
min / max
Note: There is no validation on this field so you will be able to type a value greater than 10 or less than 5, however, if you use the built-in number incrementers you cannot select a value greater than 10 or a value lower than 5.
<TextField label="Number field" type="number" min="5" max="10" />optional
<TextField label="Text field" optional />placeholder
<TextField label="Text field" placeholder="Placeholder text" />startIcon
<TextField label="Text field" startIcon={<IconCircleQuestionFilled />} />step
<TextField label="Number field" type="number" step="5" />theme
<TextField label="Number field" theme="base100" />
<TextField label="Number field" theme="secondary500" />type
<TextField label="Number field" type="number" />value
const [inputValue, setInputValue] = useState('Some value');
<TextField label="Text field" value={inputValue} />
<Button
size="small"
onClick={() => setInputValue('A different value')}
>
Change Value
</Button>disableScroll
<TextField label="Number Input (Scroll disabled)" type="number" disableScroll />Event Handling
<TextField
label="Text field"
onBlur={() => {}}
onFocus={() => {}}
onChange={(e) => {}}
/>Responsiveness
<TextField label="Text field" theme="base100" lg={{ theme: 'secondary500' }} />Full API
| Name | Type | Default |
|---|---|---|
defaultValue | stringIf set, a default value will be set for the input. | |
disabled | booleanIf | false |
disableScroll | booleanShould the field blur on wheel events, to prevent an input change? This is useful for number fields. | false |
endIcon | ReactNodeThe icon displayed at the end of the TextField. | |
error | booleanIf | |
errorMessage | stringIf set, the | 'Invalid input' |
id | stringThe id of the input element. If unspecified, an id will be generated internally. | |
inputProps | Omit<InputHTMLAttributes<HTMLInputElement>, "className" | "style">Additional props to be passed directly to the input element, e.g. | |
label | stringThe accessible label for the text field. | |
name | stringThe field name used on the POST request when the form is submitted. | |
onBlur | FocusEventHandler<HTMLInputElement>Callback fired when the text field loses user focus. | |
onChange | ChangeEventHandler<HTMLInputElement>Callback fired each time the user types in the text field. | |
onFocus | FocusEventHandler<HTMLInputElement>Callback fired when the text field receives user focus. | |
min | string | number | undefinedThe min attribute specifies the minimum value for a number field. | |
max | string | number | undefinedThe max attribute specifies the maximum value for a number field. | |
placeholder | stringOptionally displays a text hint in the field, before it is populated. | |
optional | booleanAdd an optional flag to the label for this field (controlled by https://coral-oe.vercel.app/?path=/docs/guides-configurationโdocs#overrides-optional-indicatorย optionalIndicator). This should be set to true if you have set this field to be optional in your validation schema. | false |
startIcon | ReactNodeThe icon displayed at the start of the TextField. | |
step | string | number | undefinedThe | |
type | HTMLInputTypeAttributeThe HTML input type of this text field. | text |
value | string | null
| |
theme | ResponsiveVariant<ConditionalValue<"secondary500" | "base100"> | undefined>The colourway applied to this component. | base100 |
autocomplete | AutoFillThe HTML autocomplete attribute lets web developers specify what if any permission the user agent has to provide automated assistance in filling out form field values, as well as guidance to the browser as to the type of information expected in the field. | on |
attributes | AttributesThis prop can be used to pass HTML attributes directly to the component.
We currently allow passing Example usage: | |
ref | Ref<HTMLInputElement> | undefinedAllows getting a ref to the component instance.
Once the component unmounts, React will set | |
key | Key | null | undefined |
Design
Good to know
Choose a text field if you want to indicate to a user that they need to or can input information. A text field should make it clear what information is being requested and address any errors related to that info.
Why donโt we indicate mandatory fields?
It is a better user experience when forms are explicit about optional fields by labelling them so, that way the user can be reassured they can proceed without completing it. Therefore in Coral our mandatory fields are the default and optional fields are marked as such.
Why do I need to use a different text field for Hemocyanin and Siphon, they look the same?
When the text field is interacted with the label moves up to the top of the field. This label now sits within a label container which gives the illusion of the cut out at the top. This container matches the colour of the background youโre using, therefore you need to use the text field corresponding to the background colour it is going on.
Customisation
Our text field component has a couple variations you can play with. Our components default with all properties turned on, however you can choose to toggle on and off the following:
- Optional label
- Icons
Component breakdown
- Corner radius: 12px
- Border: 2px
- Input text: Body 1
- Label container: Caption text
- Left padding: 16px | Right padding: 80px
- Horizontal padding: 16px | Vertical padding: 16px