Add hint to creatable ComboBoxes without suggestions available

props-settings-ui-keyboard-propagation
Adam Rutkowski 3 years ago
parent ae0019afe5
commit aeafeea6e6

@ -195,6 +195,12 @@ defmodule PlausibleWeb.Live.Components.ComboBox do
>
No matches found. Try searching for something different.
</div>
<div
:if={@suggestions == [] && @creatable && String.trim(@display_value) == ""}
class="relative cursor-default select-none py-2 px-4 text-gray-700 dark:text-gray-300"
>
Create an item by typing.
</div>
</ul>
"""
end

@ -123,6 +123,15 @@ defmodule PlausibleWeb.Live.Components.ComboBoxTest do
"No matches found. Try searching for something different."
end
test "when no options available, hints the user to create one by typing" do
doc =
render_sample_component([],
creatable: true
)
assert text_of_element(doc, "#dropdown-test-component div") == "Create an item by typing."
end
test "makes the html input required when required option is passed" do
input_query = "input[type=text][required]"
assert render_sample_component([], required: true) |> element_exists?(input_query)

Loading…
Cancel
Save