-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Remove view component data attribute helper (#4186)
Because: * We can simplify and use Rails 7's [`tag.attributes` helper](https://blog.saeloun.com/2021/05/05/rails-7-transform-hash-into-html-for-erb-interpolation/) instead This commit: * Removes `html_data_attributes_for` view component helper method. * Removes data attributes parameter from card components - it wasn't used anywhere. * Adds a couple of spec for testing cards with ids and custom classes
- Loading branch information
1 parent
f6f0ea4
commit 0bec432
Showing
5 changed files
with
15 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,4 @@ | ||
class ApplicationComponent < ViewComponent::Base | ||
include Classy::Yaml::ComponentHelpers | ||
include Turbo::FramesHelper | ||
|
||
private | ||
|
||
def html_data_attributes_for(data) | ||
data.map do |key, value| | ||
"data-#{key.to_s.dasherize}=#{value.to_s.dasherize}" | ||
end.join(' ') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe CardComponent, type: :component do | ||
let(:data_attributes) { { controller: 'navbar', navbar_target: 'menu_state' } } | ||
it 'renders the card with custom classes' do | ||
component = described_class.new(classes: 'a-class') | ||
|
||
it 'renders a div with the data attributes parsed to be html valid' do | ||
component = described_class.new(data_attributes:) | ||
render_inline(component) | ||
|
||
expect(page).to have_css('div.a-class') | ||
end | ||
|
||
it 'renders the card with an id' do | ||
component = described_class.new(id: 'an-id') | ||
|
||
render_inline(component) | ||
|
||
expect(page).to have_css("div[data-controller='navbar'][data-navbar-target='menu-state']") | ||
expect(page).to have_css('div#an-id') | ||
end | ||
end |