Form and Checkbox: label markers stay with the last word - #1212
Draft
JeanMarcMilletScality wants to merge 1 commit into
Draft
JeanMarcMilletScality wants to merge 1 commit into
JeanMarcMilletScality wants to merge 1 commit into
Conversation
A required field's `*`, an optional field's `(optional)` and a label's help icon are all annotations on the label's last word, and all three could wrap onto a line of their own. The two text markers were joined to the label with an ordinary space, which is a soft-wrap opportunity: use a non-breaking one. The help icon has no space of its own -- `helpIconReserve` pads the end of the label's inline box and the icon sits back in that room -- but a label that ends in a space puts a break opportunity in front of the reserve, so the icon orphans anyway. Trim the label before applying the reserve. A label built from a template literal picks up a trailing space easily, which is how this shows up in practice rather than in theory. The required marker's separator now reaches the accessible name as a non-breaking space rather than a plain one; the two existing marker tests are updated to expect it.
Contributor
Hello jeanmarcmilletscality,My role is to assist you with the merge of this Available options
Available commands
Status report is not available. |
Contributor
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
Peer approvals must include at least 1 approval from the following list: |
This branch has not been deployed
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.
TL;DR — Form and Checkbox: a required field's
*, an(optional)suffix and a label's help icon could each end up alone on a second line; all three now stay with the label's last word.Context / Why
All three are annotations on the label's last word, and each is separated from it by something the line breaker is free to break at. Narrow the label column enough — a side panel, a container query — and the marker goes over on its own, reading as though it belongs to nothing.
🧩 Approach
Two different separators, so two fixes.
The text markers were joined with an ordinary space, which is a soft-wrap opportunity:
The help icon has no space of its own —
helpIconReservepads the end of the label's inline box and the icon sits back in that room, so it costs the last line nothing. What defeats it is a label that ends in a space: that leaves a break opportunity in front of the reserve, and the icon orphans anyway. So the label is trimmed before the reserve is applied, in both components that use it:A label built from a template literal picks up a trailing space easily —
`${name} ${suffix}`with an empty suffix — which is how this shows up in practice rather than in theory.trimLabelEndlives besidehelpIconReserve, since it is part of that mechanism's contract rather than a general utility.One consequence worth knowing about:
toHaveAccessibleNamedoes not normalise U+00A0 to a plain space, so the marker now reaches the accessible name as a non-breaking space. Screen readers announce it the same way, but an assertion written against'User name *'will fail. The two existing marker tests in this repo are updated to expect it.🔧 Usage
No API change. The only thing a consumer may need to touch is a test:
🔍 Review focus
form/Form.component.tsx › FormGroup— the non-breaking space is now part of the field's accessible name. Loud failure rather than silent (a consumer's assertion breaks at test time), but it is a contract change and the alternative — keeping a breakable space and accepting the orphan — is a real option to weigh.iconhelper/IconHelper.tsx › trimLabelEnd— a new export, deliberately not added to the package barrel: it exists to be paired withhelpIconReserveby the two components that use it.🧪 How to test
npx jest src/lib/components/form src/lib/components/checkbox*should stay on the same line as the last word, at every width.Checkboxwhoselabelends in a space and which has alabelHelpTooltip. The?icon should sit at the end of the label's last line, not below it.Follow-up
🔗 References
helpIconReservefor the form label's help icon; this closes the trailing-space hole in it.labelHelpTooltiponCheckbox, which is the surface this was reported on.🤖 Generated with Claude Code