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

Remove invalid nested <button> inside <a> element in heex templates #5814

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: 2 additions & 2 deletions priv/templates/phx.gen.html/index.html.heex
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<.header>
Listing <%= schema.human_plural %>
<:actions>
<.link href={~p"<%= schema.route_prefix %>/new"}>
<.button>New <%= schema.human_singular %></.button>
<.link href={~p"<%= schema.route_prefix %>/new"} class="py-2 px-3 text-sm font-semibold rounded-lg bg-zinc-100 hover:bg-zinc-200/80">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest this style since a very similar style is already used for the button-alike link "Get Started" in app.html.heex

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid using tailwind styles in generators. The home page is fine, because we discard it. Could we use <.button> only instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my projects I have a <.button link={%{patch: ...}} that then has a properly styled <.link inside. Maybe that's the way to go?

Copy link
Contributor Author

@phoebe100 phoebe100 May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about plain old link by simply using <.link> without any fancy style?
Buttons would always require javascript and some users might create their projects with --no-live flag.

Or the generators could produce different elements:

  • mix phx.gen.live could use <.button> with phx-click only
  • while mix phx.gen.html could stick to simple <.link> (which could still be styled/replaced further if CoreComponents gets some button-alike link component in the future)

New <%= schema.human_singular %>
</.link>
</:actions>
</.header>
Expand Down
4 changes: 2 additions & 2 deletions priv/templates/phx.gen.html/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<%= schema.human_singular %> <%%= @<%= schema.singular %>.id %>
<:subtitle>This is a <%= schema.singular %> record from your database.</:subtitle>
<:actions>
<.link href={~p"<%= schema.route_prefix %>/#{@<%= schema.singular %>}/edit"}>
<.button>Edit <%= schema.singular %></.button>
<.link href={~p"<%= schema.route_prefix %>/#{@<%= schema.singular %>}/edit"} class="py-2 px-3 text-sm font-semibold rounded-lg bg-zinc-100 hover:bg-zinc-200/80">
Edit <%= schema.singular %>
</.link>
</:actions>
</.header>
Expand Down
4 changes: 2 additions & 2 deletions priv/templates/phx.gen.live/index.html.heex
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<.header>
Listing <%= schema.human_plural %>
<:actions>
<.link patch={~p"<%= schema.route_prefix %>/new"}>
<.button>New <%= schema.human_singular %></.button>
<.link patch={~p"<%= schema.route_prefix %>/new"} class="py-2 px-3 text-sm font-semibold rounded-lg bg-zinc-100 hover:bg-zinc-200/80">
New <%= schema.human_singular %>
</.link>
</:actions>
</.header>
Expand Down
4 changes: 2 additions & 2 deletions priv/templates/phx.gen.live/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<%= schema.human_singular %> <%%= @<%= schema.singular %>.id %>
<:subtitle>This is a <%= schema.singular %> record from your database.</:subtitle>
<:actions>
<.link patch={~p"<%= schema.route_prefix %>/#{@<%= schema.singular %>}/show/edit"} phx-click={JS.push_focus()}>
<.button>Edit <%= schema.singular %></.button>
<.link patch={~p"<%= schema.route_prefix %>/#{@<%= schema.singular %>}/show/edit"} phx-click={JS.push_focus()} class="py-2 px-3 text-sm font-semibold rounded-lg bg-zinc-100 hover:bg-zinc-200/80">
Edit <%= schema.singular %>
</.link>
</:actions>
</.header>
Expand Down
Loading