TextInput
a control to input a single line of text, with optional suggestions
Using Grommet for HPE?See TextInput examples and guidance.
Default suggestion to highlight, as an index into the suggestions array.
number
If set, the suggestion at the specified index in the suggestions array will be highlighted by default when the suggestions drop opens.
0
How to align the drop.
object
{ top: "top" | "bottom", bottom: "top" | "bottom", right: "left" | "right", left: "left" | "right" }
{ top: "bottom", left: "left" }
Target where any suggestions drop will be aligned to.
object
This should be a React reference. Typically, this is not required as the drop will be aligned to the TextInput itself by default.
ref.current
An optional icon to show. This could be used to provide an indication of what kind of input is expected, like an email icon, or what the input will be used for, like a search icon.
element
<Search />
Custom messages for TextInput. Used for accessibility by screen readers.
object
{ enterSelect: "(Press Enter to Select)", suggestionsCount: "suggestions available", suggestionsExist: "This input has suggestions use arrow keys to navigate", suggestionIsOpen: "Suggestions drop is open, continue to use arrow keys to navigate" }
Note: This function is deprecated, use onSuggestionSelect instead. Function that will be called when the user selects a suggestion. The suggestion contains the object chosen from the supplied suggestions. When used in conjunction with onSuggestionSelect this will default to React's onSelect.
function
() => {}
Function that will be called when the user selects a suggestion. The suggestion contains the object chosen from the supplied suggestions.
function
() => {}
Whether this is a plain input with no border or outline.
boolean
true
false
string
Use "full" to remove padding in addition to removing border and outline. Only use this when the containing context provides sufficient affordance.
"full"
Makes the TextInput readOnly and adds a copy to clipboard button. Setting this to true will automatically set the readOnly prop to true.
boolean
true
false
Whether an icon should be reversed so that the icon is at the end of the input.
boolean
true
false
The size of the text.
string
"xsmall"
"small"
"medium"
"large"
"xlarge"
"xxlarge"
"2xl"
"3xl"
"4xl"
"5xl"
"6xl"
"string"
Suggestions to show. It is recommended to avoid showing too many suggestions and instead rely on the user to type more.
array[string]
["suggestion1", "suggestion2"]
array[object]
[ { label: node, value: any }, ]
At its core, the TextInput component is a regular <input> element. Thus, both DOM and React properties, methods, and events are accessible. To read up on all of the possible DOM attributes and types available for input elements, check out this MDN Web Documents page. To learn more about DOM events and methods, you can read more on the MDN Web Events documentation page.
Also, feel free to read about the types of React events available, or see how DOM attributes change in React. Working in tandem with Styled Components, you also have access to the as property.
The color of the border.
string
A hex, name, or rgb value.
"rgba(0, 0, 0, 0.33)"
object
An object with a color for dark and light modes.
{ dark: "rgba(255, 255, 255, 0.33)", light: "rgba(0, 0, 0, 0.33)" }
Background style for readOnly inputs.
string
A color or image url.
"neutral-1"
"url(//my.com/assets/img.png)"
object
{ color: "neutral-1", dark: true, image: "url(//my.com/assets/img.png)" position: "bottom", opacity: true, repeat: "no-repeat", size: "cover", light: "string" }
where opacity could be:
"weak"
"medium"
"strong"
boolean
number
where position could be:
any CSS for background-position
where repeat could be:
"no-repeat"
"repeat"
"string"
where size could be:
"cover"
"contain"
"string"
The possible sizes of the text in terms of its font-size and line-height.
object
{ xsmall: { size: '12px', height: '18px', }, small: { size: '14px', height: '20px', }, medium: { size: '18px', height: '24px', }, large: { size: '22px', height: '28px', }, xlarge: { size: '26px', height: '32px', }, xxlarge: { size: '34px', height: '40px', }, }
Any additional style for TextInput.
string
Any CSS.
css`color: 'blue'`
function
(props) => {}
Any additional style for TextInput container.
string
Any CSS.
css`color: 'blue'`
function
(props) => {}
Any additional style for non-string placeholder inside TextInput.
string
Any CSS.
css`color: 'blue'`
function
(props) => {}
Any additional style for TextInput suggestions.
string
Any CSS.
css`color: 'blue'`
function
(props) => {}
The border color of the component when in focus.
string
A hex, name, or rgb value.
"focus"
object
An object with a color for dark and light modes.
{ dark: "string", light: "string" }
The outline color around the component when in focus.
string
A hex, name, or rgb value.
"brand"
object
An object with a color for dark and light modes.
{ dark: "string", light: "string" }
The shadow color around the component when in focus.
string
"focus"
object
An object with a color for dark and light modes.
{ dark: "string", light: "string" }
The font-weight of the text. This value will only be applied if global.input.weight is undefined.
string
"bold"
number
600
This value has been deprecated and replaced by global.input.font.weight.
string
"bold"
number
300
The padding of the text.
string
"12px"
object
An object specifying padding for different sides of the component.
{ top: "string", bottom: "string", left: "string", right: "string", horizontal: "string", vertical: "string" }