-
Notifications
You must be signed in to change notification settings - Fork 3k
Remove invalid nested <button> inside <a> element in heex templates #5814
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
Conversation
| <: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"> |
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.
I suggest this style since a very similar style is already used for the button-alike link "Get Started" in app.html.heex
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.
We should avoid using tailwind styles in generators. The home page is fine, because we discard it. Could we use <.button> only instead?
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.
In my projects I have a <.button link={%{patch: ...}} that then has a properly styled <.link inside. Maybe that's the way to go?
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.
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 to Elixir & Phoenix, but the way the industry has been solving the (I need button styles for my link) problem is by using a prop called |
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.
* prevent invalid markup in generators 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. * update LV in integration tests
|
Closed via 1f4be18. Thank you! |
|
@SteffenDE I've come up with an idea I think might be a good fit for phoenix defaults, in my own codebase I've created a |
|
@lifeiscontent This sounds similar to what I proposed initially in #5820 (I added a link attribute to the button 89c76df, but another idea was a |
|
@SteffenDE the current solution is still producing invalid HTML though, you can't nest |
|
@lifeiscontent you‘re absolutely right and now I feel stupid 😃 |
|
@SteffenDE should we revert this? Or this is an improvement anyway? |
|
No need to revert, it’s basically the same, but I plan to send a new PR |
|
@SteffenDE maybe a little far out of an idea, but what if we prefixed all of the core components with this has some interesting growth benefits. e.g. if its and if people want to completely overhaul their design systems, they can naturally graudate to something like |
Fixes #5770