G
Tokens
TypographySpacingColorRadiusShadowMotion

TextInput

Label


    <Stack gap="m">
      <TextInput label="Label" placeholder="With label" id="wLabelExample"/>
      <TextInput placeholder="Without label" id="woLabelExample"/>
    </Stack>
  

Hint


    <TextInput label="Label" hint="Hint" id="wHintExample"/>
  

Icon


    <TextInput icon={<IconSearch />} label="City" placeholder="Search" id="iconExample"/>
  

Type


    <Stack gap="m">
      <TextInput
        label="Email"
        placeholder="Email"
        id="emailExample"
        type="email"
        value="grain@flodesk.com"
        onChange={() => {}}
      />
      <TextInput
        label="Password"
        placeholder="Password"
        id="passwordExample"
        type="password"
        value="0123456789"
        onChange={() => {}}
      />
    </Stack>

With error


    <TextInput
      id="errorExample"
      label="City"
      value="Netherlands"
      hasError
      errorMessage="Netherlands is not a city"
      onChange={() => {}}
    />
  

Read only and disabled


    <Stack gap="m">
      <TextInput
        id="isReadOnlyExample"
        label="City"
        value="Netherlands"
        isReadOnly
        onChange={() => {}}
      />

      <TextInput
        id="disabledExample"
        label="City"
        value="Netherlands"
        isDisabled
        onChange={() => {}}
      />
    </Stack>


Clearable


    () => {
      const [value, setValue] = useState('Default value');
      return (
        <TextInput
          id="withClearExample"
          value={value}
          icon={<IconSearch />}
          onChange={(e) => setValue(e.target.value)}
          onClear={() => setValue('')}
        />
      )
    }


Background color


    <Box padding="l2" backgroundColor="background2" borderSide="all" radius="m">
      <TextInput 
        backgroundColor="background" 
        label="City" 
        id="colorExample"
      />
    </Box>
  

Examples

With state


    () => {
      const [value, setValue] = useState('Default value');
      return (
        <Stack gap="l">
          <div>{value}</div>

          <TextInput
            id="withStateExample"
            value={value}
            onChange={(e) => setValue(e.target.value)}
          />
        </Stack>
      )
    }


Custom composition


    <>
      <TextInput.Label htmlFor="customLabelExample">Label</TextInput.Label>
      <TextInput.Hint>Hint</TextInput.Hint>
      <Arrange gap="s" alignItems="start" columns="1fr auto" marginTop="var(--grn-form-control-label-gap)">
        <TextInput
          id="customLabelExample"
          errorMessage="Error message"
        />
        <Arrange gap="s">
          <Button>Cancel</Button>
          <Button variant="accent">Save</Button>
        </Arrange>
      </Arrange>
    </>

Props

Name
Type
Default
type
oneOf
'text' 'password' 'email' 'date' 'datetime-local' 'email' 'month' 'number' 'password' 'search' 'tel' 'time' 'url' 'week'
'text'
idREQUIRED
string
placeholder
string
value
oneOfType
string
number
label
oneOfType
string
node
icon
node
hasError
bool
errorMessage
string
isReadOnly
bool
isDisabled
bool
hint
oneOfType
string
node
backgroundColor
oneOfType
Object.keys(vars.colors)
string
onClear
func