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

Hint component can render block-level elements as valid HTML #1855

Merged
merged 3 commits into from
Jul 8, 2020

Conversation

vanitabarrett
Copy link
Contributor

@vanitabarrett vanitabarrett commented Jul 8, 2020

What

  • Switch the hint component wrapping element from span to div

Why

We allow HTML to be passed to the component, and it seems reasonable that someone may want to pass (for example) 2 paragraphs in. At the moment this would render correctly but would be invalid HTML.

Preview: https://govuk-frontend-review-pr-1855.herokuapp.com/components/hint (no visual changes expected)

Fixes #1835

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1855 July 8, 2020 09:58 Inactive
@vanitabarrett vanitabarrett changed the title Make hint block element Hint component can render block-level elements as valid HTML Jul 8, 2020
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1855 July 8, 2020 10:01 Inactive
@vanitabarrett vanitabarrett force-pushed the make-hint-block-element branch from a98eb58 to 501e764 Compare July 8, 2020 10:04
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1855 July 8, 2020 10:05 Inactive
@vanitabarrett vanitabarrett marked this pull request as ready for review July 8, 2020 10:12
@vanitabarrett vanitabarrett force-pushed the make-hint-block-element branch from 501e764 to df9e46c Compare July 8, 2020 12:35
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1855 July 8, 2020 12:35 Inactive
Copy link
Member

@hannalaakso hannalaakso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vanitabarrett, this looks great 🚀

Vanita Barrett added 3 commits July 8, 2020 14:47
It's possible to pass HTML into the hint component, but this becomes invalid HTML if someone passes a block element in (for example: a <p> tag) as the hint wraps everything in a span.

This commit switches the hint from using a wrapping span to a div, so block elements can be passed in as valid HTML.
@vanitabarrett vanitabarrett force-pushed the make-hint-block-element branch from df9e46c to 266f091 Compare July 8, 2020 13:47
@vanitabarrett vanitabarrett merged commit 6e3a992 into master Jul 8, 2020
@vanitabarrett vanitabarrett deleted the make-hint-block-element branch July 8, 2020 14:36
@vanitabarrett vanitabarrett mentioned this pull request Jul 29, 2020
andymantell added a commit to surevine/govuk-react-jsx that referenced this pull request Jul 30, 2020
andymantell added a commit to andymantell/govuk-frontend-jinja that referenced this pull request Aug 10, 2020
peteryates added a commit to x-govuk/govuk-form-builder that referenced this pull request Aug 12, 2020
This makes hints behave more like labels, captions and legends.

However, there is a slight difference based on the kinds of arguments
passed. The following behaviour only applies to hints.

* When a single string of text is supplied, the hint is wrapped in a
  `span` tag.

* When a block of HTML is supplied, the hint is wrapped in a `div`. This
  is because rendering block level elements inside a span results in
  invalid HTML[0][1]

[0] alphagov/govuk-frontend#1855
[1] https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider changing govukHint to wrap its content in a DIV rather than a SPAN
4 participants