File tree Expand file tree Collapse file tree 4 files changed +49
-14
lines changed
spec/helpers/solidus_admin Expand file tree Collapse file tree 4 files changed +49
-14
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ module SolidusAdmin
7
7
# BaseComponent is the base class for all components in Solidus Admin.
8
8
class BaseComponent < ViewComponent ::Base
9
9
include SolidusAdmin ::ComponentsHelper
10
+ include SolidusAdmin ::VoidElementsHelper
10
11
include Turbo ::FramesHelper
11
12
12
13
def icon_tag ( name , **attrs )
Original file line number Diff line number Diff line change @@ -93,24 +93,24 @@ def call
93
93
with_content options_for_select ( @attributes . delete ( :choices ) , @attributes . delete ( :value ) )
94
94
end
95
95
96
- options = {
96
+ build_tag
97
+ end
98
+
99
+ private
100
+
101
+ def build_tag
102
+ args = [ @tag ]
103
+ args << content unless void_element? ( @tag )
104
+
105
+ tag . public_send ( *args , **tag_options )
106
+ end
107
+
108
+ def tag_options
109
+ @tag_options ||= {
97
110
"data-controller" : stimulus_id ,
98
111
"data-#{ stimulus_id } -custom-validity-value" : @error . presence ,
99
112
"data-action" : "#{ stimulus_id } #clearCustomValidity" ,
100
113
**@attributes
101
114
}
102
-
103
- if tag . method ( @tag ) . parameters . any? { |_type , name | name == :content }
104
- tag . public_send (
105
- @tag ,
106
- content ,
107
- **options
108
- )
109
- else
110
- tag . public_send (
111
- @tag ,
112
- **options
113
- )
114
- end
115
115
end
116
116
end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusAdmin
4
+ module VoidElementsHelper
5
+ # https://github.com/rails/rails/blob/194d697036c61af0caa66de5659721ded2478ce9/actionview/lib/action_view/helpers/tag_helper.rb#L84
6
+ HTML_VOID_ELEMENTS = %i( area base br col embed hr img input keygen link meta source track wbr )
7
+
8
+ # @param element [Symbol]
9
+ def void_element? ( element )
10
+ HTML_VOID_ELEMENTS . include? ( element )
11
+ end
12
+ end
13
+ end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec . describe SolidusAdmin ::VoidElementsHelper , type : :helper do
6
+ describe '#void_element?' do
7
+ subject { helper . void_element? ( element ) }
8
+
9
+ context 'when element is void' do
10
+ let ( :element ) { :input }
11
+
12
+ it { is_expected . to be true }
13
+ end
14
+
15
+ context 'when element is not void' do
16
+ let ( :element ) { :div }
17
+
18
+ it { is_expected . to be false }
19
+ end
20
+ end
21
+ end
You can’t perform that action at this time.
0 commit comments