Skip to main content
Tw Twintrinsic
  • Getting Started
  • Components
  • Theming
  • Completion
Examples
Data Dashboard Game Map
Core
App
Layout
Accordion AccordionItem Card Container Panel Separator Sidebar Splitter
Navigation
AppHeader BottomBar Breadcrumb BreadcrumbItem Menu MenuItem Tabs Tab TabList TabPanel TreeMenu
Data Display
Avatar AvatarGroup Badge Carousel CarouselItem Chip ChipGroup CodeBlock CodeBlockSpeed CodeEditor DataTable Map Progress Skeleton Table TableBody TableCell TableHead TableHeader TableRow Tag TagGroup Timeline TimelineItem Tooltip Tree TreeNode
Metrics
DonutChart PieChart LineChart BarChart HorizontalBarChart AreaChart StatsCard MetricGrid KPICard GaugeChart ProgressMetric MetricTrend
Form
AutoComplete Button ButtonGroup Calendar Checkbox ColorPicker Combobox Dropdown FileUpload FloatLabel Form FormField Input InputSwitch InvalidState Knob ListInput Listbox NumberInput Radio RadioGroup Rating Select SelectGroup Slider Switch TextInput Textarea
Feedback
Modal Stepper StepperStep Toast
Utility
Icon Lazy LazyPanel Masonry ThemeToggle

FloatLabel

The FloatLabel component creates form inputs with animated floating labels that move out of the way when the input is focused or has a value. This provides a modern, space-efficient design while maintaining clear labeling for improved user experience.

Examples

Basic Usage

<FloatLabel label="Username">
  <TextInput name="username" />
</FloatLabel>

With Different Input Types

<FloatLabel label="Email">
  <TextInput type="email" name="email" />
</FloatLabel>

<FloatLabel label="Password">
  <TextInput type="password" name="password" />
</FloatLabel>

<FloatLabel label="Message">
  <Textarea name="message" rows={3} />
</FloatLabel>

<FloatLabel label="Country">
  <Select 
    name="country"
    options={[
      { label: 'United States', value: 'us' },
      { label: 'Canada', value: 'ca' },
      { label: 'United Kingdom', value: 'uk' }
    ]}
  />
</FloatLabel>

Required Field

<FloatLabel label="Email" required={true}>
  <TextInput type="email" name="email" required={true} />
</FloatLabel>

With Error Message

Please enter a valid email address
<FloatLabel 
  label="Email" 
  error="Please enter a valid email address"
>
  <TextInput type="email" name="email" />
</FloatLabel>

With Help Text

Password must be at least 8 characters long
<FloatLabel 
  label="Password" 
  helpText="Password must be at least 8 characters long"
>
  <TextInput type="password" name="password" />
</FloatLabel>

Disabled State

<FloatLabel label="Username" disabled={true}>
  <TextInput name="username" disabled={true} />
</FloatLabel>

With Initial Value

<FloatLabel label="Username">
  <TextInput name="username" value="johndoe" />
</FloatLabel>

Props

PropTypeDefaultDescription
labelstringRequiredLabel text for the input
requiredbooleanfalseWhether the input is required (adds an asterisk)
disabledbooleanfalseWhether the input is disabled
errorstringRequiredError message to display below the input
helpTextstringRequiredHelp text to display below the input (not shown when there is an error)
idstringauto-generatedHTML id for accessibility
classstring''Additional CSS classes

Slots

NameDescription
defaultThe input component to wrap with the floating label

Accessibility

The FloatLabel component follows accessibility best practices:

  • Associates labels with inputs using proper for attributes
  • Maintains visible labels at all times
  • Properly indicates required fields with both visual and screen reader cues
  • Error messages are announced to screen readers using role="alert"
  • Preserves the accessibility features of the wrapped input components

Best Practices

  • Use clear, concise labels that describe the input's purpose
  • Keep labels short to avoid overflow when floating
  • Ensure error messages are descriptive and actionable
  • Use help text to provide additional context or requirements
  • Maintain consistent styling across your form by using FloatLabel for all inputs

Form Integration

The FloatLabel component works with the Form component for validation and submission:

<Form onSubmit={handleSubmit}>
  <FloatLabel label="Email" required={true}>
    <TextInput 
      type="email"
      name="email"
      required={true}
    />
  </FloatLabel>
  
  <FloatLabel label="Password" required={true}>
    <TextInput 
      type="password"
      name="password"
      required={true}
    />
  </FloatLabel>
  
  <Button type="submit">Sign In</Button>
</Form>