Textarea
Displays a textarea field.
Usage
Textarea
div(class: "grid w-full max-w-sm items-center gap-1.5") do
Textarea(placeholder: "Textarea")
end
Disabled
div(class: "grid w-full max-w-sm items-center gap-1.5") do
Textarea(disabled: true, placeholder: "Disabled")
end
Aria disabled
div(class: "grid w-full max-w-sm items-center gap-1.5") do
Textarea(aria: {disabled: "true"}, placeholder: "Aria Disabled")
end
With formfield
This is a textarea
div(class: "grid w-full max-w-sm items-center gap-1.5") do
FormField do
FormFieldLabel(for: "textarea") { "Textarea" }
FormFieldHint { "This is a textarea" }
Textarea(placeholder: "Textarea", id: "textarea")
FormFieldError()
end
end
Installation
Using RubyUI CLI
Run the install command
rails g ruby_ui:component Textarea
Manual installation
1
Add RubyUI::Textarea to app/components/ruby_ui/textarea/textarea.rb
# frozen_string_literal: true
module RubyUI
class Textarea < Base
def initialize(rows: 4, **attrs)
@rows = rows
super(**attrs)
end
def view_template(&)
textarea(rows: @rows, **attrs, &)
end
private
def default_attrs
{
data: {
ruby_ui__form_field_target: "input",
action: "input->ruby-ui--form-field#onInput invalid->ruby-ui--form-field#onInvalid"
},
class: [
"flex w-full rounded-md border bg-background px-3 py-1 text-sm shadow-sm transition-colors border-border",
"placeholder:text-muted-foreground",
"disabled:cursor-not-allowed disabled:opacity-50",
"file:border-0 file:bg-transparent file:text-sm file:font-medium",
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
"aria-disabled:cursor-not-allowed aria-disabled:opacity-50 aria-disabled:pointer-events-none"
]
}
end
end
end
2
Add RubyUI::TextareaDocs to app/components/ruby_ui/textarea/textarea_docs.rb
# frozen_string_literal: true
class Views::Docs::Textarea < Views::Base
def view_template
component = "Textarea"
div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do
render Docs::Header.new(title: "Textarea", description: "Displays a textarea field.")
Heading(level: 2) { "Usage" }
render Docs::VisualCodeExample.new(title: "Textarea", context: self) do
<<~RUBY
div(class: "grid w-full max-w-sm items-center gap-1.5") do
Textarea(placeholder: "Textarea")
end
RUBY
end
render Docs::VisualCodeExample.new(title: "Disabled", context: self) do
<<~RUBY
div(class: "grid w-full max-w-sm items-center gap-1.5") do
Textarea(disabled: true, placeholder: "Disabled")
end
RUBY
end
render Docs::VisualCodeExample.new(title: "Aria Disabled", context: self) do
<<~RUBY
div(class: "grid w-full max-w-sm items-center gap-1.5") do
Textarea(aria: {disabled: "true"}, placeholder: "Aria Disabled")
end
RUBY
end
render Docs::VisualCodeExample.new(title: "With FormField", context: self) do
<<~RUBY
div(class: "grid w-full max-w-sm items-center gap-1.5") do
FormField do
FormFieldLabel(for: "textarea") { "Textarea" }
FormFieldHint { "This is a textarea" }
Textarea(placeholder: "Textarea", id: "textarea")
FormFieldError()
end
end
RUBY
end
end
render Components::ComponentSetup::Tabs.new(component_name: component)
render Docs::ComponentsTable.new(component_files(component))
end
end
Components
| Component | Built using | Source |
|---|---|---|
Textarea | Phlex | |
TextareaDocs | Phlex |