ComponentsField
Field
Implementation of a fieldset
Muted
Base
import { Field, Input, Label } from '@vtex/shoreline'
export default function Example() {
return (
<Field>
<Label>Label</Label>
<Input />
</Field>
)
}
Examples
Error
Muted
Base
Error message
import { Field, FieldError, Input, Label } from '@vtex/shoreline'
export default function Example() {
return (
<Field error>
<Label>Label</Label>
<Input />
<FieldError>Error message</FieldError>
</Field>
)
}
Description text
Muted
Base
Short description
import { Field, FieldDescription, Input, Label } from '@vtex/shoreline'
export default function Example() {
return (
<Field>
<Label>Label</Label>
<Input />
<FieldDescription>Short description</FieldDescription>
</Field>
)
}
With large spacing
Muted
Base
Short description
Error message
import {
Field,
FieldDescription,
FieldError,
Input,
Label,
} from '@vtex/shoreline'
export default function Example() {
return (
<Field space="large" error>
<Label>Label</Label>
<Input />
<FieldDescription>Short description</FieldDescription>
<FieldError>Error message</FieldError>
</Field>
)
}
With text area
Muted
Base
Short description
import { Field, FieldDescription, Textarea, Label } from '@vtex/shoreline'
export default function Example() {
return (
<Field>
<Label>Text area field</Label>
<Textarea />
<FieldDescription>Short description</FieldDescription>
</Field>
)
}
Controlled
Muted
Base
Value shouldn't be "error"
import { useState } from 'react'
import {
Field,
FieldError,
FieldDescription,
Input,
Label,
} from '@vtex/shoreline'
export default function Example() {
const [value, setValue] = useState('Initial value')
const [error, setError] = useState<string | null>(null)
return (
<Field error={!!error}>
<Label>Controlled input field</Label>
<Input
value={value}
onChange={(val) => {
if (val === 'error') {
setError("Please use a value that isn't 'error'")
setValue(val)
return
}
setError(null)
setValue(val)
}}
/>
<FieldDescription>Value shouldn't be "error"</FieldDescription>
<FieldError>{error}</FieldError>
</Field>
)
}
With char counter
Muted
Base
Short description
0 / 120
import { useState } from 'react'
import {
Field,
FieldDescription,
Textarea,
Label,
FieldCharCounter,
FieldError,
Flex,
} from '@vtex/shoreline'
export default function Example() {
const [value, setValue] = useState('')
return (
<Field>
<Label>Count</Label>
<Textarea value={value} onChange={setValue} maxLength={120} />
<Flex justify="space-between">
<FieldDescription>Short description</FieldDescription>
<FieldCharCounter count={String(value).length} limit={120} />
</Flex>
<FieldError>Error Message</FieldError>
</Field>
)
}
Optional props
asChild
Enables component composition
type
boolean
default
false
error
Whether the field is in an error state
type
boolean
default
false
space
Space between the field's children
type
large
normal
default
normal