Context
PR #337 added prefix/suffix support to text_field, wrapping inputs in usa-input-group with adjacent prefix/suffix divs. The implementation includes a scoped workaround: when a prefixed/suffixed input is in an error state, Rails' default field_with_errors wrapper is stripped via regex. Without the strip, the wrapper sits between .usa-input-prefix and <input> and breaks the .usa-input-prefix + input CSS adjacency selector that supplies the input's padding-left.
The fix addresses the immediate bug but only for prefix/suffix. Rails injects a <div class="field_with_errors"> wrapper that Strata never wants, and the same bug will reproduce with any future USWDS feature that uses adjacent-sibling selectors (character counters, date pickers, combo boxes).
Proposal
Set Rails' field_error_proc to a pass-through at the engine level, then remove the scoped strip from text_field.
ActionView::Base.field_error_proc = ->(html_tag, _instance) { html_tag }
Why this is safe
Strata already renders its own error markup for every form helper:
usa-input--error on the input element
usa-form-group--error on the surrounding form group
usa-error-message span with the validation message
Rails' field_with_errors wrapper adds nothing on top of that. It's redundant for any consumer of Strata's form builders.
Why this matters now
USWDS uses adjacent-sibling and child selectors in several components:
.usa-input-prefix + input (this PR)
.usa-input-suffix + .usa-character-count__message (character counters)
.usa-date-picker__wrapper > input (date pickers)
Each will hit the same wrapper-breaks-adjacency bug as it gets added. Fixing the wrapper at the engine level preempts the whole class.
Precedent
navapbc/archive-md-famli did this in config/application.rb:112.
Scope of the follow-up PR
- Add the
field_error_proc override in Strata's engine boot config
- Remove the scoped strip from
Strata::FormBuilder#text_field
- Keep the "blank prefix/suffix as absent" spec (independent of
field_error_proc)
- Adjust or drop the "keeps the input as the immediate sibling of the prefix in error states" spec; the adjacency will hold by default once the wrapper is gone, making that spec a tautology
Open question
Whether to fold an ADR into the follow-up PR. Blast radius (changes rendered HTML for every Strata consumer in error states) and rationale (Strata's error markup makes Rails' redundant) both suggest yes.
Context
PR #337 added prefix/suffix support to
text_field, wrapping inputs inusa-input-groupwith adjacent prefix/suffix divs. The implementation includes a scoped workaround: when a prefixed/suffixed input is in an error state, Rails' defaultfield_with_errorswrapper is stripped via regex. Without the strip, the wrapper sits between.usa-input-prefixand<input>and breaks the.usa-input-prefix + inputCSS adjacency selector that supplies the input'spadding-left.The fix addresses the immediate bug but only for prefix/suffix. Rails injects a
<div class="field_with_errors">wrapper that Strata never wants, and the same bug will reproduce with any future USWDS feature that uses adjacent-sibling selectors (character counters, date pickers, combo boxes).Proposal
Set Rails'
field_error_procto a pass-through at the engine level, then remove the scoped strip fromtext_field.Why this is safe
Strata already renders its own error markup for every form helper:
usa-input--erroron the input elementusa-form-group--erroron the surrounding form groupusa-error-messagespan with the validation messageRails'
field_with_errorswrapper adds nothing on top of that. It's redundant for any consumer of Strata's form builders.Why this matters now
USWDS uses adjacent-sibling and child selectors in several components:
.usa-input-prefix + input(this PR).usa-input-suffix + .usa-character-count__message(character counters).usa-date-picker__wrapper > input(date pickers)Each will hit the same wrapper-breaks-adjacency bug as it gets added. Fixing the wrapper at the engine level preempts the whole class.
Precedent
navapbc/archive-md-famlidid this in config/application.rb:112.Scope of the follow-up PR
field_error_procoverride in Strata's engine boot configStrata::FormBuilder#text_fieldfield_error_proc)Open question
Whether to fold an ADR into the follow-up PR. Blast radius (changes rendered HTML for every Strata consumer in error states) and rationale (Strata's error markup makes Rails' redundant) both suggest yes.