From 6b9b7cfa47bf4c7db4e3f5a2d7580f0654e64527 Mon Sep 17 00:00:00 2001 From: Eric Saxby Date: Tue, 29 Oct 2024 16:24:11 -0700 Subject: [PATCH] Add :caret slot with ability to customize its classes --- lib/live_select.ex | 4 ++++ lib/live_select/component.ex | 1 + lib/live_select/component.html.heex | 3 +++ 3 files changed, 8 insertions(+) diff --git a/lib/live_select.ex b/lib/live_select.ex index 3ab370e..bf1cc80 100644 --- a/lib/live_select.ex +++ b/lib/live_select.ex @@ -417,6 +417,10 @@ defmodule LiveSelect do doc: "one of `:tailwind`, `:daisyui` or `:none`. See the [Styling section](styling.html) for details" + slot(:caret, doc: "optional slot for rendering a caret when no option has been selected.") do + attr :class, :list + end + slot(:option, doc: "optional slot that renders an option in the dropdown. The option's data is available via `:let`" diff --git a/lib/live_select/component.ex b/lib/live_select/component.ex index 8ff2cc0..92286ad 100644 --- a/lib/live_select/component.ex +++ b/lib/live_select/component.ex @@ -363,6 +363,7 @@ defmodule LiveSelect.Component do :"phx-focus", :option, :tag, + :caret, :clear_button, :hide_dropdown, :value_mapper, diff --git a/lib/live_select/component.html.heex b/lib/live_select/component.html.heex index a4ecd3a..4e519ba 100644 --- a/lib/live_select/component.html.heex +++ b/lib/live_select/component.html.heex @@ -76,6 +76,9 @@ <% end %> <% end %> + <%= if @mode == :single && @caret != [] && @selection == [] do %> +
<%= render_slot(caret) %>
+ <% end %> <%= if @mode == :single do %> <%= hidden_input(@field.form, @field.field,