Skip to content

Commit dc6a823

Browse files
committed
refactor: extract NativeSelectIcon into its own component
Move the chevron icon from an inline private method in NativeSelect into a dedicated NativeSelectIcon component, following the same pattern as AccordionIcon. Supports block override for custom icons.
1 parent 74c075e commit dc6a823

3 files changed

Lines changed: 41 additions & 17 deletions

File tree

lib/ruby_ui/native_select/native_select.rb

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,12 @@ def view_template(&block)
1212
class: "group/native-select relative w-fit has-[select:disabled]:opacity-50"
1313
) do
1414
select(**attrs, &block)
15-
chevron_icon
15+
render RubyUI::NativeSelectIcon.new
1616
end
1717
end
1818

1919
private
2020

21-
def chevron_icon
22-
svg(
23-
xmlns: "http://www.w3.org/2000/svg",
24-
viewbox: "0 0 24 24",
25-
fill: "none",
26-
stroke: "currentColor",
27-
stroke_width: "2",
28-
stroke_linecap: "round",
29-
stroke_linejoin: "round",
30-
class: "text-muted-foreground pointer-events-none absolute top-1/2 right-2.5 size-4 -translate-y-1/2 select-none",
31-
aria_hidden: "true"
32-
) do |s|
33-
s.path(d: "m6 9 6 6 6-6")
34-
end
35-
end
36-
3721
def default_attrs
3822
{
3923
data: {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
module RubyUI
4+
class NativeSelectIcon < Base
5+
def view_template(&block)
6+
span(**attrs) do
7+
if block
8+
block.call
9+
else
10+
icon
11+
end
12+
end
13+
end
14+
15+
private
16+
17+
def icon
18+
svg(
19+
xmlns: "http://www.w3.org/2000/svg",
20+
viewbox: "0 0 24 24",
21+
fill: "none",
22+
stroke: "currentColor",
23+
stroke_width: "2",
24+
stroke_linecap: "round",
25+
stroke_linejoin: "round",
26+
class: "size-4",
27+
aria_hidden: "true"
28+
) do |s|
29+
s.path(d: "m6 9 6 6 6-6")
30+
end
31+
end
32+
33+
def default_attrs
34+
{
35+
class: "text-muted-foreground pointer-events-none absolute top-1/2 right-2.5 -translate-y-1/2 select-none"
36+
}
37+
end
38+
end
39+
end

test/ruby_ui/native_select_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def test_render_with_options
1616
assert_match(/Apple/, output)
1717
assert_match(/Banana/, output)
1818
assert_match(/<select/, output)
19+
assert_match(/<svg/, output)
1920
end
2021

2122
def test_render_with_groups

0 commit comments

Comments
 (0)