@element-public/react-textfield
v5.68.10-alpha.1
Published
Textfield component for Element React
Downloads
356
Keywords
Readme
Textfield
Description
Text fields let users enter and edit text into a UI.
See live demos on storybook
Install from Artifactory
- Verify that you have access to (https://docs.int.bayer.com/cloud/devops/artifactory/)[Bayer Artifactory]
- Verify your token is correctly set up in your .npmrc as per the link above
- Verify you have the @element scope configured in your .npmrc
@element:registry=https://artifactory.bayer.com/artifactory/api/npm/npm-platforms-engineering/
- Install the component and themes bundles
npm i @element/react-components @element/themes- alternatively install the component individually along with the themes bundle
npm i @element/react-textfield @element/themes
- alternatively install the component individually along with the themes bundle
Notes
Textfield is an open text box that allows users to enter and/or edit text into a UI.
There are numerous Textfield props to enable customization of the component. Textfield has multiple different variants to choose from such as outlined, filled, and embedded - a special borderless textfield for inclusion in TopAppBar or TableTopBar.
Textfield Props
| Name | Type | Default | Required | Description |
| -------------------- | ----------------------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| alignment | string | 'left' | false | For dense textfield this aligns the contents of the text-field to left or rightAccepted Values: left, right |
| className | string | undefined | false | The css class name to be passed through to the component markup. |
| containerProps | object | undefined | false | Properties to be added to the container of the textfield. |
| counter | boolean | false | false | Enables a character count. Warning requires maxlength to be set. |
| defaultValue | string | number | undefined | false | The starting value of the Textfield when working in uncontrolled mode. |
| dense | boolean | false | false | The size of the Textfield will be reduced. |
| disabled | boolean | false | false | Textfield will be disabled. |
| focused | boolean | false | false | Sets the Textfield to the focused state. |
| fullWidth | boolean | false | false | The Textfield will expand to 100% width. |
| helperTextId | string | undefined | false | Randomly generated id for the helper text container element. May be overwritten. |
| helperTextPersistent | boolean | false | false | Set the helper text to be permanently visible. |
| helperTextValidation | boolean | false | false | Set the helper text to use validation styles. Helper text changes with valid (e.g., helper text will appear red when valid is set to 'false'). |
| id | string | undefined | false | Randomly generated id for the input element. May be overwritten. |
| label | string | null | false | Floating input label. Note: full-width Textfields do not support floating labels - any label on a full-width Textfield will be automatically mapped to a placeholder. |
| labelId | string | undefined | false | Randomly generated id for the label element. May be overwritten. |
| leadingIcon | string|React.ReactNode | null | false | Adds the given Icon or Icon Button to the left of the Textfield. Expects the name of a valid Material.io icon, however in React an icon or icon button component may be passed in instead for more control, |
| maxlength | number | null | false | Restricts the number of characters that can be entered, best used with counter. |
| noResize | boolean | true | false | Prevents resizing when using textarea. |
| placeholder | string | null | false | Non-floating label text, will be replaced when the user starts typing. |
| prefixText | string | null | false | Text that will appear before the label or value of the Textfield. It will be shown on focus. An example use-case might be a currency symbol such as $. Warning: This cannot be used with leadingIcon or textarea. |
| suffixText | string | null | false | Text that will appear after the label or value of the Textfield. It will be shown on focus. An example use-case might be .00 if handling currency. Warning: This cannot be used with trailingIcon or textarea. |
| textarea | boolean | false | false | Enabled multi-line text input. Note textarea cannot be used with the embedded variant. |
| tooltip | boolean|object | null | false | If defined, a Tooltip will appear on the Textfield. Useful to show the full value, if the value is too long for the Textfield width. The object should be the needed Tooltip properties. Tooltip text prop will be set to the current value of the Textfield. See Tooltip docs for available props. |
| trailingIcon | string|React.ReactNode | null | false | Adds the given Icon or Icon Button to the right of the Textfield . Expects the name of a valid Material.io icon, however in React an icon icon button component may be passed in instead for more control. |
| type | string | 'text' | false | Support for built-in input types. Browser support for some advanced types such as color or date may be limited or appear differently between browsers. Note the Datepicker component should be preferred over the built-in date/time types as it offers more consistency and features.Note Slider type is not support, please use the Element Slider component instead.Accepted Values: button, checkbox, color, date, datetime-local, email, file, hidden, image, month, number, password, radio, range, reset, search, submit, tel, text, time, url, week |
| valid | boolean | true | false | Applies an invalid style to the Textfield. |
| value | string | number | undefined | false | The current value of the Textfield component. |
| variant | string | 'filled' | false | Applies the selected styling to the Textfield. Note textarea does not support the embedded variant.Accepted Values: filled, outlined, embedded |
Textfield Deprecated Props
| Name | Type | Default | Required | Deprecated | Description |
| -------------- | ------- | --------- | -------- | --------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| block | boolean | undefined | false | Use fullWidth instead. | Applies a full-width style where the Textfield will fill its container. |
| containerClass | string | undefined | false | See containerProps. | Add a custom class to the Textfield container. |
| embedded | boolean | undefined | false | Use variant='embedded' | An unfilled, non-outlined and full-width variant of Textfield, intended to be embedded in other components such as TopAppBar or TableHeader. |
| filled | boolean | undefined | false | Use variant='filled' instead. | Apply filled style to the Textfield. Previously called primary. |
| maxLength | number | undefined | false | Use maxlengthinstead. The case of this prop has changed to be more consistent. | Restricts the number of characters that can be entered, best used with counter. |
| outlined | boolean | undefined | false | Usevariant='outlined'instead | Apply outlined style to the Textfield. Previously called secondary. |
| primary | boolean | undefined | false | This feature is no longer supported. Usevariant='filled'instead. | Enable filled styling. |
| search | boolean | undefined | false | Usevariant='embedded' | Enabled search bar styling, including a full width style. |
| secondary | boolean | undefined | false | Usevariant='outlined'` instead. | Apply secondary style to the Textfield. |
Textfield Render Props
| Name | Type | Default | Required | Description | | --------------- | --------------- | ------- | -------- | ------------------------------------------------------------------------------ | | helperText | React.ReactNode | null | false | Helper text to be displayed below Textfield, by default only visible on focus. | | leadingContent | React.ReactNode | null | false | Custom content to appear before the input. | | trailingContent | React.ReactNode | null | false | Custom content to appear after the input. |
Textfield Events
| Name | Default | Required | Params | Description | | -------- | ------- | -------- | ------ | -------------------------------------------------------- | | onBlur | null | false | | Fired when focus leaves the input. | | onChange | null | false | | Fired when each character is entered into the Textfield. | | onFocus | null | false | | Fired when the input gains focus. |
Textfield Breaking Changes
| Description |
| ------------------------------------------------------------------------------------------------------------------------------------------- |
| children (removed): Please use value prop instead. |
| containerStyle (removed): See containerProps. |
| defaultContent (removed): This feature never quite worked correctly and is no longer supported. |
| errorChecking (removed): Use valid instead. |
| fullWidth: The behavior of fullWidth has changed since the previous version. If you need that original behavior use variant='embedded'. |
