Skip to content

Commit 5bfbee9

Browse files
committed
label component for attribute added
1 parent 88effec commit 5bfbee9

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
module Matestack::Ui::Core::Label
22
class Label < Matestack::Ui::Core::Component::Static
3-
3+
def setup
4+
@tag_attributes.merge!({
5+
for: options[:for]
6+
})
7+
end
48
end
59
end

docs/components/label.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
11
# matestack core component: Label
22

33
Show [specs](/spec/usage/components/label_spec.rb)
4+
5+
6+
The HTML label tag implemented in ruby.
7+
8+
## Parameters
9+
10+
This component can take 3 optional configuration params and optional content.
11+
12+
#### # id (optional)
13+
Expects a string with all ids the div should have.
14+
15+
#### # class (optional)
16+
Expects a string with all classes the div should have.
17+
18+
#### # for (optional)
19+
Expects a string that binds the label to a given form element
20+
21+
## Example
22+
23+
```ruby
24+
label id: "foo", class: "bar", for: 'input_id' do
25+
plain 'Label For Element' # optional content
26+
end
27+
```
28+
29+
returns
30+
31+
```html
32+
<label for="input_id" id="foo" class="bar">
33+
Label For Element
34+
</label>
35+
```
36+

spec/usage/components/label_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def response
1313
label text: 'I am simple'
1414

1515
# enhanced label
16-
label id: 'my-id', class: 'my-class' do
16+
label id: 'my-id', for: 'label for something', class: 'my-class' do
1717
plain 'I am enhanced'
1818
end
1919
}
@@ -27,7 +27,7 @@ def response
2727

2828
expected_static_output = <<~HTML
2929
<label>I am simple</label>
30-
<label id="my-id" class="my-class">I am enhanced</label>
30+
<label for="label for something" id="my-id" class="my-class">I am enhanced</label>
3131
HTML
3232

3333
expect(stripped(static_output)).to include(stripped(expected_static_output))

0 commit comments

Comments
 (0)