Skip to content
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

Simplify the choice of text for legends and labels #308

Merged
merged 1 commit into from
Aug 16, 2021

Conversation

peteryates
Copy link
Member

@peteryates peteryates commented Aug 15, 2021

Finding by presence is a more-descriptive approach than compacting the array and selecting the first remaining item.

It also gives us the opportunity to make the behaviour around label/legend rendering more intuitive when the key:

  • is nil
  • has nil text
  • has text but it's empty ("")

Now, empty strings will fail Rails' #presence check and be treated like nil. This means that if you pass #govuk_text_field(label: { text: "" }) the label will fall back to the localised or default value instead of rendering an empty <label> element.

@peteryates peteryates added the technical debt Something could be better label Aug 15, 2021
Finding by presence is a more-descriptive approach that compacting and
selecting the first remaining item. This refactoring also gives us the
opportunity to improve the test cases around whether or not captions are
rendered when the legend or label:

* is nil
* has nil text
* text is an empty string
@peteryates peteryates force-pushed the refactor-some-compact-first-chains branch from 0f063f7 to 1c27692 Compare August 15, 2021 12:29
@peteryates peteryates merged commit 92423d3 into master Aug 16, 2021
@peteryates peteryates deleted the refactor-some-compact-first-chains branch August 16, 2021 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical debt Something could be better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant