Skip to content

Commit 1bec783

Browse files
authored
Merge pull request #127 from mcass19/fix-nil-value-in-selection-list
fix: reject nil values in selection list
2 parents b58b8a4 + c0eea95 commit 1bec783

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/live_select/component.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ defmodule LiveSelect.Component do
486486
else
487487
[selected]
488488
end
489+
|> Enum.reject(&is_nil/1)
489490

490491
socket =
491492
socket

test/live_select_test.exs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,4 +1106,23 @@ defmodule LiveSelectTest do
11061106
assert_selected(live, "A")
11071107
end
11081108
end
1109+
1110+
test "handles nil in options list when navigating and clearing input", %{conn: conn} do
1111+
stub_options([{"A", 1}, {"B", 2}, {"C", 3}])
1112+
1113+
{:ok, live, _html} = live(conn, "/")
1114+
1115+
type(live, "ABC")
1116+
1117+
assert_options(live, ["A", "B", "C"])
1118+
1119+
keydown(live, "ArrowDown")
1120+
keydown(live, "Backspace")
1121+
1122+
type(live, "")
1123+
1124+
keydown(live, "Enter")
1125+
1126+
refute_selected(live)
1127+
end
11091128
end

0 commit comments

Comments
 (0)