-
Notifications
You must be signed in to change notification settings - Fork 64
Support readonly for all fields #1677
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ defmodule Backpex.HTML.CoreComponents do | |
| </.dropdown> | ||
| """ | ||
| 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,21 +65,38 @@ 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 | ||
|
Comment on lines
+68
to
+80
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks complicated. Can't we just add additional classes in the markup in case the dropdown is readonly?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is why. This is how the dropdown is rendered with the code above:
Whereas this code: trigger_class =
if assigns.readonly do
["cursor-not-allowed bg-base-200"] ++ trigger_class
else
trigger_class
endresults in this, and the field can be even highlighted on mouse click (although the dropdown does not open):
|
||
|
|
||
| assigns = assign(assigns, trigger_class: trigger_class) | ||
|
|
||
| ~H""" | ||
| <div id={@id} class={["dropdown", @class]} {@rest}> | ||
| <div id={@id} class={[not @readonly && "dropdown", @class]} {@rest}> | ||
| <div | ||
| id={"#{@id}-trigger"} | ||
| role="button" | ||
| tabindex="0" | ||
| aria-haspopup="true" | ||
| aria-label={@trigger && @trigger[:aria_label]} | ||
| aria-labelledby={@trigger && Map.get(@trigger, :aria_labelledby)} | ||
| class={@trigger && @trigger[:class]} | ||
| class={@trigger_class} | ||
| > | ||
| {render_slot(@trigger)} | ||
| </div> | ||
|
|
||
| <div | ||
| :if={not @readonly} | ||
| id={"#{@id}-menu"} | ||
| tabindex="-1" | ||
| aria-labelledby={"#{@id}-trigger"} | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.