[proposal] enable input-label association without explicit ids #154
Closed
samrichardsontylertech
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Proposal
It's currently necessary for consumers to supply each
<input>
element slotted into a Forge component with anid
and the associated<label>
element with afor
attribute pointing to thatid
. This is usually a reasonable ask, but with larger forms that may be dynamically generated or split across different files it can be hard to ensure thatids
are all present and unique. It's become a common gotcha and a source of occasionally hard to track down bugs.We should be able to implement a solution to allow creating accessible form fields without requiring explicit
id
andfor
attributes. There are a few initial options to consider:label
property like the one exposed by theforge-select
componentid
andfor
attributes if missing<label><input /></label>
patternNone of these solutions would replace the current pattern, but provide a simpler syntax for basic use cases.
Affected components
All components that accept slotted
<input>
and<label>
elements, like the text field and radio button.Benefits
Simpler, cleaner, and less bug-prone code.
Caveats
Allowing multiple ways to label inputs might result in conflicts or confusion.
Beta Was this translation helpful? Give feedback.
All reactions