Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add :caret slot with ability to customize its classes #87

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/live_select.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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`"
Expand Down
1 change: 1 addition & 0 deletions lib/live_select/component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ defmodule LiveSelect.Component do
:"phx-focus",
:option,
:tag,
:caret,
:clear_button,
:hide_dropdown,
:value_mapper,
Expand Down
3 changes: 3 additions & 0 deletions lib/live_select/component.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
<% end %>
</button>
<% end %>
<%= if @mode == :single && @caret != [] && @selection == [] do %>
<div :for={caret <- @caret} class={caret[:class]}><%= render_slot(caret) %></div>
<% end %>
</div>
<%= if @mode == :single do %>
<%= hidden_input(@field.form, @field.field,
Expand Down
Loading