diff --git a/lib/backpex/html/core_components.ex b/lib/backpex/html/core_components.ex
index 8d31e6858..b9c70dbba 100644
--- a/lib/backpex/html/core_components.ex
+++ b/lib/backpex/html/core_components.ex
@@ -38,6 +38,7 @@ defmodule Backpex.HTML.CoreComponents do
"""
attr :id, :string, required: true, doc: "unique identifier for the dropdown"
+ attr :readonly, :boolean, default: false, doc: "whether the dropdown is readonly"
attr :class, :any, default: nil, doc: "additional classes for the outer container element"
slot :trigger, doc: "the trigger element to be used to toggle the dropdown menu" do
@@ -64,8 +65,24 @@ defmodule Backpex.HTML.CoreComponents do
_trigger -> nil
end)
+ trigger_class = (assigns.trigger && assigns.trigger[:class]) || ""
+
+ trigger_class =
+ if assigns.readonly do
+ ["cursor-not-allowed bg-base-200"] ++
+ (trigger_class
+ |> Enum.join(" ")
+ |> String.split()
+ |> List.delete("bg-transparent")
+ |> List.delete("input"))
+ else
+ trigger_class
+ end
+
+ assigns = assign(assigns, trigger_class: trigger_class)
+
~H"""
-