Skip to content

Commit 6c1b8d1

Browse files
committed
Allow actions to accept id and class attributes
1 parent 34ab700 commit 6c1b8d1

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

app/concepts/action/view/action.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
%a{"@click.prevent": "perform", "href": action_path}
1+
%a{@tag_attributes, "@click.prevent": "perform", "href": action_path}
22
- if block_given?
33
= yield

docs/components/action.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,34 @@ failure: {
8585
}
8686
```
8787

88+
### ID (optional)
89+
90+
This parameter accepts a string of ids that the action component should have:
91+
92+
```ruby
93+
id: 'my-action-id'
94+
```
95+
96+
which renders as an HTML `id` attribute, like so:
97+
98+
```html
99+
<a id="my-action-id">...</a>
100+
```
101+
102+
### Class (optional)
103+
104+
This parameter accepts a string of classes that the action component should have:
105+
106+
```ruby
107+
class: 'my-action-class'
108+
```
109+
110+
which renders as an HTML `class` attribute, like so:
111+
112+
```html
113+
<a class="my-action-class">...</a>
114+
```
115+
88116
### Notify
89117

90118
Not in use right now.

spec/usage/components/action_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,33 @@ def page2
386386

387387
end
388388

389+
it 'accepts class and id attributes and returns them as the corresponding HTML attributes' do
390+
391+
class ExamplePage < Page::Cell::Page
392+
393+
def response
394+
components {
395+
action action_config do
396+
button text: "Click me!"
397+
end
398+
}
399+
end
400+
401+
def action_config
402+
return {
403+
id: 'action-id',
404+
class: 'action-class'
405+
}
406+
end
407+
408+
end
409+
410+
visit "/example"
411+
412+
expect(page).to have_css('a#action-id.action-class')
413+
414+
end
415+
389416
it 'action_path: passing path as a string (not recommended)' do
390417

391418
Rails.application.routes.append do

0 commit comments

Comments
 (0)