Shadwire

Search the documentation

Search the documentation and component pages by title and by content.

Get started
Introduction
Installation
shadwire.json
Theming
Dark mode
Tools
CLI
Agent skill
Registry
llms.txt
Guides
Composition
Styling
Forms
Icons
Accessibility
Localisation
Blocks
Overview
Components
Overview
Accordion
Alert
Alert Dialog
Aspect Ratio
Avatar
Badge
Breadcrumb
Button
Button Group
Calendar
Card
Carousel
Chart
Checkbox
Collapsible
Combobox
Command
Context Menu
Data Table
Date Picker
Dialog
Drawer
Dropdown Menu
Empty
Field
Hover Card
Icon
Input
Input Group
Input OTP
Item
Kbd
Label
Menubar
Native Select
Navigation Menu
Pagination
Popover
Progress
Radio Group
Resizable
Scroll Area
Select
Separator
Sheet
Sidebar
Skeleton
Slider
Sonner
Spinner
Switch
Table
Tabs
Textarea
Toggle
Toggle Group
Tooltip

Label

Renders an accessible label tied to a form control.

Installation

Shadwire follows shadcn/ui's open code model: the component's source is copied into your application and becomes yours. Install it with the CLI:

shadwire add label --yes

The label registry item installs these files:

  • app/components/ui_component.rb
  • app/components/ui/label_component.rb
  • app/helpers/ui/label_helper.rb
  • vendor/shadwire/shadwire.css

Haven't installed the CLI yet? gem install shadwire, then shadwire init.

Usage

Use the ui_label helper. for is a reserved word in Ruby, so it is passed as an ordinary HTML attribute. Point it at the id of the control.

<%= ui_label(for: "email") { "Email" } %>
<%= ui_input(type: :email, id: "email") %>

Or render the component Ui::LabelComponent directly:

<%= render Ui::LabelComponent.new(for: "email") do %>
  Email
<% end %>

Examples

Default

Tie the label to the field with for: pointing at the control's id.

<div class="grid w-full max-w-sm gap-2">
  <%= ui_label(for: "label-demo-username") { "Username" } %>
  <%= ui_input(id: "label-demo-username", placeholder: "shadwire") %>
</div>

Disabled group

Inside a group carrying data-disabled, the label dims automatically.

<div class="group grid w-full max-w-sm gap-2" data-disabled="true">
  <%= ui_label(for: "label-demo-disabled") { "Email" } %>
  <%= ui_input(type: :email, id: "label-demo-disabled", placeholder: "you@example.com", disabled: true) %>
</div>

API reference

ui_label(**options, &block) wraps Ui::LabelComponent.new(**options).

Argument Type Default Description
class / class_name String nil Extra classes, merged after the base classes.
**attrs Hash {} Free HTML attributes (for, id, data:, aria:, …).
&block Block — The label's content: text, icons or both.