Skip to content

Commit 17999f7

Browse files
authored
[Bug Fix] Fix SelectValue placeholder fallback (#292) (#382)
1 parent c13b7e1 commit 17999f7

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

gem/lib/ruby_ui/select/select_value.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ def initialize(placeholder: nil, **attrs)
99

1010
def view_template(&block)
1111
span(**attrs) do
12-
block ? block.call : @placeholder
12+
value = block ? block.call : @placeholder
13+
value || @placeholder
1314
end
1415
end
1516

gem/test/ruby_ui/select_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,14 @@ def test_render_with_all_items
2929
assert_match(/John/, output)
3030
assert_match('name="NAME"', output)
3131
end
32+
33+
def test_select_value_renders_placeholder_when_block_returns_nil
34+
output = phlex do
35+
RubyUI.SelectValue(placeholder: "Placeholder") do
36+
nil
37+
end
38+
end
39+
40+
assert_match(/Placeholder/, output)
41+
end
3242
end

0 commit comments

Comments
 (0)