Input
Displays a form field, or a component that looks like a text field.
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:
The input registry item installs these files:
-
app/components/ui_component.rb -
app/components/ui/input_component.rb -
app/helpers/ui/input_helper.rb -
vendor/shadwire/shadwire.css
Haven't installed the CLI yet? gem install shadwire, then shadwire init.
Usage
Use the ui_input helper
in any view. <input> is a void element, so the helper
takes no block: everything, including the value, goes in attributes.
Or render the component
Ui::InputComponent
directly:
Examples
Default
A text field in the shadcn style. Any HTML attribute you pass goes to the <input>.
With a label
Pair it with ui_label using for:/id: to tie the label to the field.
Disabled
Pass disabled: true as an HTML attribute.
File
type: :file styles the native file picker.
With form_with
Use form.field_name/form.field_id to wire it into Rails forms.
API reference
ui_input(**options)
wraps
Ui::InputComponent.new(**options).
| Argument | Type | Default | Description |
|---|---|---|---|
type |
Symbol/String | :text |
Any native input type (:email, :password, :file, :number, …). |
class / class_name |
String | nil |
Extra classes, merged after the base classes. |
**attrs |
Hash | {} |
Free HTML attributes (name, id, placeholder, disabled, required, data:, aria:, …). |