Update CoreComponents, add explicit label association#6586
Merged
SteffenDE merged 1 commit intophoenixframework:mainfrom Jan 24, 2026
Merged
Update CoreComponents, add explicit label association#6586SteffenDE merged 1 commit intophoenixframework:mainfrom
SteffenDE merged 1 commit intophoenixframework:mainfrom
Conversation
Contributor
|
Thank you again! 🙌🏻 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Currently, the
inputs generated inCoreComponentsuses nesting to implicitly associate thelabelwith theinput.This works fine in most cases but there are a couple drawbacks
inputto be a sibling of thelabel, breaking the implicit association and unintentionally cause accessibility problems. If they are using PhoenixTest, this would also break any tests that fill in these inputs, since the majority of the functions rely on a working label.For more info, see
Changes
Update
CoreComponentstemplates forinputs. Addfor={@id}to explicitly associate alabelelement with itsinputelement.Diff of the generated
CoreComponentswith these changes:~H""" <div class="fieldset mb-2"> - <label> + <label for={@id}> <input type="hidden" name={@name} @@ -234,7 +234,7 @@ defmodule SomeTestProjectWeb.CoreComponents do def input(%{type: "select"} = assigns) do ~H""" <div class="fieldset mb-2"> - <label> + <label for={@id}> <span :if={@label} class="label mb-1">{@label}</span> <select id={@id} @@ -255,7 +255,7 @@ defmodule SomeTestProjectWeb.CoreComponents do def input(%{type: "textarea"} = assigns) do ~H""" <div class="fieldset mb-2"> - <label> + <label for={@id}> <span :if={@label} class="label mb-1">{@label}</span> <textarea id={@id} @@ -276,7 +276,7 @@ defmodule SomeTestProjectWeb.CoreComponents do def input(assigns) do ~H""" <div class="fieldset mb-2"> - <label> + <label for={@id}> <span :if={@label} class="label mb-1">{@label}</span> <input type={@type}