Skip to content

Commit ba30386

Browse files
authored
Merge pull request #253 from bdlb77/add_fieldset_component
Add fieldset component
2 parents 5cbf15b + 9c40b68 commit ba30386

File tree

4 files changed

+147
-0
lines changed

4 files changed

+147
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%fieldset{@tag_attributes}
2+
-if options[:text].nil? && block_given?
3+
= yield
4+
- else
5+
= options[:text]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Matestack::Ui::Core::Fieldset
2+
class Fieldset < Matestack::Ui::Core::Component::Static
3+
def setup
4+
@tag_attributes.merge!({
5+
disabled: options[:disabled]
6+
})
7+
end
8+
end
9+
end

docs/components/fieldset.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# matestack core component: Fieldset
2+
3+
Show [specs](/spec/usage/components/fieldset_spec.rb)
4+
5+
Use Fieldset to group several `<input>` and `<label>` tags.
6+
7+
8+
## Parameters
9+
10+
`<fieldset>` can take two optional configuration params and optional content.
11+
12+
13+
### Optional configuration
14+
15+
#### id (optional)
16+
17+
Expects a string with all ids the details tag should have.
18+
19+
#### class (optional)
20+
21+
Expects a string with all classes the details tag should have.
22+
23+
#### Disabled (optional)
24+
25+
Set `disabled` attribute on `<fieldset>` to disable all controls inside the `<fieldset>`
26+
27+
## Example 1
28+
29+
```ruby
30+
fieldset do
31+
legend text: 'Your Inputs for Personal details'
32+
label text: 'Personal Detail'
33+
input
34+
end
35+
```
36+
37+
```html
38+
<fieldset>
39+
<legend>Your Inputs for Personal details</legend>
40+
<label>Personal Detail</label>
41+
<input>
42+
</fieldset>
43+
```
44+
45+
## Example 2
46+
47+
```ruby
48+
fieldset id: 'foo', class: 'bar' do
49+
legend id: 'baz', text: 'Your Inputs for Personal details'
50+
label text: 'Personal Detail'
51+
input
52+
end
53+
```
54+
55+
```html
56+
<fieldset id="foo" class="bar">
57+
<legend id="baz">Your Inputs for Personal details</legend>
58+
<label>Personal Detail</label>
59+
<input>
60+
</fieldset>
61+
```
62+
63+
64+
### Example 3
65+
66+
**With Disabled Attribute**
67+
68+
```ruby
69+
fieldset disabled: true do
70+
legend text: 'input legend'
71+
input
72+
end
73+
```
74+
75+
```html
76+
<fieldset disabled="disabled">
77+
<legend>input legend</legend>
78+
<input>
79+
</fieldset>
80+
```
81+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
require_relative '../../support/utils'
2+
include Utils
3+
4+
describe 'Fieldset Component', type: :feature, js: true do
5+
it 'fieldset with 1 input and legend' do
6+
class ExamplePage < Matestack::Ui::Page
7+
def response
8+
components {
9+
fieldset do
10+
legend text: 'input legend'
11+
input
12+
end
13+
14+
# advanced
15+
fieldset class: 'foo', id: 'world' do
16+
legend id: 'bar', class: 'hello', text: 'input legend'
17+
input
18+
end
19+
20+
# with disabled
21+
fieldset disabled: true do
22+
legend text: 'input legend'
23+
input
24+
end
25+
}
26+
end
27+
end
28+
29+
visit '/example'
30+
31+
static_output = page.html
32+
33+
expected_html_output = <<~HTML
34+
<fieldset>
35+
<legend>input legend</legend>
36+
<input>
37+
</fieldset>
38+
39+
<fieldset id="world" class="foo">
40+
<legend id="bar" class="hello">input legend</legend>
41+
<input>
42+
</fieldset>
43+
44+
<fieldset disabled="disabled">
45+
<legend>input legend</legend>
46+
<input>
47+
</fieldset>
48+
49+
HTML
50+
expect(stripped(static_output)).to include(stripped(expected_html_output))
51+
end
52+
end

0 commit comments

Comments
 (0)