Skip to content

Commit

Permalink
prevent invalid markup in generators
Browse files Browse the repository at this point in the history
It is not allowed to render a button inside an <a> tag:

https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-a-element

Therefore, we invert the order of the elements and nest a link inside a
button and forward any button clicks to the link.

Fixes #5770.
References #5814.
  • Loading branch information
SteffenDE committed Nov 26, 2024
1 parent 57b352b commit 20a2638
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
8 changes: 5 additions & 3 deletions priv/templates/phx.gen.html/index.html.heex
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<.header>
Listing <%= schema.human_plural %>
<:actions>
<.link href={~p"<%= schema.route_prefix %>/new"}>
<.button>New <%= schema.human_singular %></.button>
</.link>
<.button phx-click={JS.dispatch("click", to: {:inner, "a"})}>
<.link href={~p"<%= schema.route_prefix %>/new"}>
New <%= schema.human_singular %>
</.link>
</.button>
</:actions>
</.header>

Expand Down
8 changes: 5 additions & 3 deletions priv/templates/phx.gen.html/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
<%= 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>
<.button phx-click={JS.dispatch("click", to: {:inner, "a"})}>
<.link href={~p"<%= schema.route_prefix %>/#{@<%= schema.singular %>}/edit"}>
Edit <%= schema.singular %>
</.link>
</.button>
</:actions>
</.header>

Expand Down
8 changes: 5 additions & 3 deletions priv/templates/phx.gen.live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
<.header>
Listing <%= schema.human_plural %>
<:actions>
<.link navigate={~p"<%= schema.route_prefix %>/new"}>
<.button>New <%= schema.human_singular %></.button>
</.link>
<.button phx-click={JS.dispatch("click", to: {:inner, "a"})}>
<.link navigate={~p"<%= schema.route_prefix %>/new"}>
New <%= schema.human_singular %>
</.link>
</.button>
</:actions>
</.header>
Expand Down
8 changes: 5 additions & 3 deletions priv/templates/phx.gen.live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
<%= schema.human_singular %> <%%= @<%= schema.singular %>.id %>
<:subtitle>This is a <%= schema.singular %> record from your database.</:subtitle>
<:actions>
<.link navigate={~p"<%= schema.route_prefix %>/#{@<%= schema.singular %>}/edit?return_to=show"}>
<.button>Edit <%= schema.singular %></.button>
</.link>
<.button phx-click={JS.dispatch("click", to: {:inner, "a"})}>
<.link navigate={~p"<%= schema.route_prefix %>/#{@<%= schema.singular %>}/edit?return_to=show"}>
Edit <%= schema.singular %>
</.link>
</.button>
</:actions>
</.header>
Expand Down

0 comments on commit 20a2638

Please sign in to comment.