Skip to content

Commit ad4f5be

Browse files
authored
Merge pull request solidusio#6120 from chaimann/fix-select-component-missing-content
Fix missing options in select tags
2 parents 1b4e1f4 + e2b4c05 commit ad4f5be

File tree

4 files changed

+49
-14
lines changed

4 files changed

+49
-14
lines changed

admin/app/components/solidus_admin/base_component.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module SolidusAdmin
77
# BaseComponent is the base class for all components in Solidus Admin.
88
class BaseComponent < ViewComponent::Base
99
include SolidusAdmin::ComponentsHelper
10+
include SolidusAdmin::VoidElementsHelper
1011
include Turbo::FramesHelper
1112

1213
def icon_tag(name, **attrs)

admin/app/components/solidus_admin/ui/forms/input/component.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,24 @@ def call
9393
with_content options_for_select(@attributes.delete(:choices), @attributes.delete(:value))
9494
end
9595

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 ||= {
97110
"data-controller": stimulus_id,
98111
"data-#{stimulus_id}-custom-validity-value": @error.presence,
99112
"data-action": "#{stimulus_id}#clearCustomValidity",
100113
**@attributes
101114
}
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
115115
end
116116
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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

0 commit comments

Comments
 (0)