Skip to content

Commit f3f6581

Browse files
Merge pull request #263 from bdlb77/label_component_bug
Label component bug
2 parents 7ba28c1 + 7073585 commit f3f6581

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
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+
form: options[:form]
7+
})
8+
end
49
end
510
end

docs/components/label.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
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 (To match `id` of form element)
20+
21+
#### # form (optional)
22+
Expects a string that specifies which form or forms the label belongs to.
23+
24+
## Example
25+
26+
```ruby
27+
label id: "foo", class: "bar", for: 'input_id', form: 'form1' do
28+
plain 'Label For Element' # optional content
29+
end
30+
31+
label id: 'foo', form: 'form1', text: "Label for form with id='form1'"
32+
33+
```
34+
35+
returns
36+
37+
```html
38+
<label for="input_id" id="foo" class="bar">
39+
Label For Element
40+
</label>
41+
42+
<label form="form1" id="foo">Label for form with id='form1'</label>
43+
44+
```
45+

spec/usage/components/label_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ 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
19+
20+
# with form attribute
21+
label id: 'form_label', for: "form", form: 'form1', text: 'Label for Form1'
1922
}
2023
end
2124

@@ -27,7 +30,9 @@ def response
2730

2831
expected_static_output = <<~HTML
2932
<label>I am simple</label>
30-
<label id="my-id" class="my-class">I am enhanced</label>
33+
<label for="label for something" id="my-id" class="my-class">I am enhanced</label>
34+
35+
<label for="form" form="form1" id="form_label" >Label for Form 1</label>
3136
HTML
3237

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

0 commit comments

Comments
 (0)