Gecko UIGecko UI

Label

Form field labels with required indicators and tooltips

Label

A label component for input fields with support for required indicators and tooltips. When required is true, displays a red asterisk (*) after the label text. When tooltip is provided, displays a tooltip icon with helpful information.

Installation

import { Label } from '@geckoui/geckoui';

Basic Usage

<Label htmlFor="username">Username</Label>

Props API

PropTypeDefaultDescription
htmlForstring-ID of the associated input element
requiredbooleanfalseShow red asterisk indicator
tooltipstring-Tooltip text to display
tooltipIconReactNode | FC-Custom tooltip icon
tooltipBackgroundColorstring-Tooltip background color
tooltipClassNamestring-CSS class for tooltip
classNamestring-CSS class for label
...restLabelHTMLAttributes-All standard label attributes

Examples

Required Field

<Label htmlFor="email" required>
  Email Address
</Label>
<Input id="email" type="email" />

With Tooltip

<Label
  htmlFor="password"
  tooltip="Password must be at least 8 characters long"
>
  Password
</Label>
<Input id="password" type="password" />

Required with Tooltip

<Label
  htmlFor="apiKey"
  required
  tooltip="You can find your API key in the settings page"
>
  API Key
</Label>
<Input id="apiKey" type="text" />

Custom Tooltip Styling

<Label
  htmlFor="info"
  tooltip="This information helps us personalize your experience"
  tooltipBackgroundColor="#3b82f6"
  tooltipClassName="text-sm"
>
  Display Name
</Label>
<Input id="info" type="text" />

Form with Multiple Labels

<div className="space-y-1">
  <Label htmlFor="username" required>Username</Label>
  <Input id="username" />
</div>

<div className="space-y-1">
  <Label htmlFor="email" required>Email</Label>
  <Input id="email" type="email" />
</div>

<div className="space-y-1">
  <Label htmlFor="bio" tooltip="Tell us about yourself">Bio</Label>
  <Textarea id="bio" />
</div>

Custom Styling

<Label htmlFor="field1" className="text-lg font-bold text-blue-600">
  Large Bold Label
</Label>

<Label htmlFor="field2" className="text-sm text-gray-500">
  Small Gray Label
</Label>

Features

Required Indicator

When required={true}, a red asterisk (*) is appended to the label text:

<Label required>Email Address</Label>
// Displays: Email Address *

Note: This is just a visual indicator and does not enforce validation. You must still add validation logic to your form.

Tooltip

When tooltip prop is provided, an icon appears next to the label. Hovering over it shows the tooltip:

<Label tooltip="Additional help text">
  Field Name
</Label>

You can customize the tooltip with:

  • tooltipBackgroundColor - Change background color
  • tooltipClassName - Add custom CSS classes
  • tooltipIcon - Use a custom icon instead of default

Accessibility

  • Uses semantic <label> element
  • Associates with input via htmlFor attribute
  • Tooltip has proper ARIA attributes
  • Required indicator is visible
  • Works with screen readers
  • Keyboard accessible tooltip

Styling

The component uses BEM-style class names:

  • GeckoUILabel - Main label element
  • GeckoUILabel__required-indicator - Red asterisk
  • GeckoUILabel__tooltip - Tooltip wrapper
  • GeckoUILabel__tooltip-icon - Default tooltip icon

Dependencies

This component uses the internal Tooltip component for tooltip functionality.