Skip to content

Commit 6e25557

Browse files
author
Nils Henning
committed
add textarea component
1 parent 0b5bac8 commit 6e25557

File tree

6 files changed

+65
-2
lines changed

6 files changed

+65
-2
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
%input{ html_attributes,
2-
type: type }
1+
%input{ html_attributes }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
%textarea{ html_attributes }
2+
= text if text
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Matestack::Ui::Core::Textarea
2+
class Textarea < Matestack::Ui::Core::Component::Static
3+
4+
html_attributes :autofocus, :cols, :dirname, :disabled, :form, :maxlength,
5+
:name, :placeholder, :readonly, :required, :rows, :wrap
6+
7+
optional :text
8+
9+
end
10+
end

docs/components/textarea.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# matestack core component: Input
2+
3+
Show [specs](/spec/usage/components/input_spec.rb)
4+
5+
The HTML textarea tag implemented in ruby.
6+
7+
## Parameters
8+
9+
This component can take all w3c specified html attributes as parameters and a text parameter. All parameters are optional.
10+
11+
#### # text (optional)
12+
Expects a string specifying the content of the textarea.
13+
14+
## Example
15+
16+
```ruby
17+
textarea id: "foo", class: "bar", cols: 2, maxlength: 20, text: 'Hello World!'
18+
```
19+
20+
returns
21+
22+
```html
23+
<textarea type="text" id="foo" class="bar" cols="2" maxlength="20">Hello World!</textarea>
24+
```

lib/matestack/ui/core/components.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def self.require_core_component(name)
119119
require_core_component "tbody"
120120
require_core_component "td"
121121
require_core_component "template"
122+
require_core_component "textarea"
122123
require_core_component "tfoot"
123124
require_core_component "th"
124125
require_core_component "thead"
@@ -235,6 +236,7 @@ def self.require_core_component(name)
235236
tbody: Matestack::Ui::Core::Tbody::Tbody,
236237
td: Matestack::Ui::Core::Td::Td,
237238
template: Matestack::Ui::Core::Template::Template,
239+
textarea: Matestack::Ui::Core::Textarea::Textarea,
238240
tfoot: Matestack::Ui::Core::Tfoot::Tfoot,
239241
th: Matestack::Ui::Core::Th::Th,
240242
thead: Matestack::Ui::Core::Thead::Thead,

spec/0.8/components/textarea_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require_relative '../../support/utils'
2+
include Utils
3+
4+
describe 'Textarea Component', type: :feature, js: true do
5+
6+
it 'Example 1' do
7+
8+
class ExamplePage < Matestack::Ui::Page
9+
def response
10+
textarea
11+
textarea cols: 2, maxlength: 20
12+
textarea text: 'Prefilled'
13+
end
14+
end
15+
16+
visit "/example"
17+
static_output = page.html
18+
expected_static_output = <<~HTML
19+
<textarea></textarea>
20+
<textarea cols="2" maxlength="20"></textarea>
21+
<textarea>Prefilled</textarea>
22+
HTML
23+
expect(stripped(static_output)).to include(stripped(expected_static_output))
24+
end
25+
26+
end

0 commit comments

Comments
 (0)