Skip to content

Commit 7073585

Browse files
committed
form attribute for label
1 parent 5bfbee9 commit 7073585

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

app/concepts/matestack/ui/core/label/label.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module Matestack::Ui::Core::Label
22
class Label < Matestack::Ui::Core::Component::Static
33
def setup
44
@tag_attributes.merge!({
5-
for: options[:for]
5+
for: options[:for],
6+
form: options[:form]
67
})
78
end
89
end

docs/components/label.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ Expects a string with all ids the div should have.
1616
Expects a string with all classes the div should have.
1717

1818
#### # for (optional)
19-
Expects a string that binds the label to a given form element
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.
2023

2124
## Example
2225

2326
```ruby
24-
label id: "foo", class: "bar", for: 'input_id' do
27+
label id: "foo", class: "bar", for: 'input_id', form: 'form1' do
2528
plain 'Label For Element' # optional content
2629
end
30+
31+
label id: 'foo', form: 'form1', text: "Label for form with id='form1'"
32+
2733
```
2834

2935
returns
@@ -32,5 +38,8 @@ returns
3238
<label for="input_id" id="foo" class="bar">
3339
Label For Element
3440
</label>
41+
42+
<label form="form1" id="foo">Label for form with id='form1'</label>
43+
3544
```
3645

spec/usage/components/label_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ def response
1616
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

@@ -28,6 +31,8 @@ def response
2831
expected_static_output = <<~HTML
2932
<label>I am simple</label>
3033
<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)