Add Nunjucks logic to insert <span> element around HTML in start buttons#7188
Open
querkmachine wants to merge 1 commit into
Open
Add Nunjucks logic to insert <span> element around HTML in start buttons#7188querkmachine wants to merge 1 commit into
<span> element around HTML in start buttons#7188querkmachine wants to merge 1 commit into
Conversation
Start buttons use flexbox for layout and alignment. Part of how flexbox works includes it ignoring whitespace between adjacent flex children (elements and text nodes), causing them to render 'squashed' together. For example, HTML in a start button like this: Apply for <abbr>PIP</abbr> now Would render like this: Apply forPIPnow By wrapping the entire HTML string in an element, we remove the elements and text nodes from being flex children, and whitespace renders as expected.
f6e1cc2 to
5f0c6c5
Compare
Other changes to npm packagediff --git a/packages/govuk-frontend/dist/govuk/components/button/fixtures.json b/packages/govuk-frontend/dist/govuk/components/button/fixtures.json
index 3cde8da8f..4a800bcf5 100644
--- a/packages/govuk-frontend/dist/govuk/components/button/fixtures.json
+++ b/packages/govuk-frontend/dist/govuk/components/button/fixtures.json
@@ -467,6 +467,19 @@
"screenshot": false,
"html": "<a href=\"/\" role=\"button\" draggable=\"false\" class=\"govuk-button govuk-button--start\" data-module=\"govuk-button\">\n Start now link button\n <svg class=\"govuk-button__start-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"17.5\" height=\"19\" viewBox=\"0 0 33 40\" aria-hidden=\"true\" focusable=\"false\">\n <path fill=\"currentColor\" d=\"M0 0h13l20 20-20 20H0l20-20z\"/>\n </svg>\n</a>"
},
+ {
+ "name": "start link with html",
+ "options": {
+ "href": "/",
+ "html": "Start <em>now</em>",
+ "isStartButton": true
+ },
+ "hidden": true,
+ "description": "",
+ "pageTemplateOptions": {},
+ "screenshot": false,
+ "html": "<a href=\"/\" role=\"button\" draggable=\"false\" class=\"govuk-button govuk-button--start\" data-module=\"govuk-button\">\n <span>Start <em>now</em></span>\n <svg class=\"govuk-button__start-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"17.5\" height=\"19\" viewBox=\"0 0 33 40\" aria-hidden=\"true\" focusable=\"false\">\n <path fill=\"currentColor\" d=\"M0 0h13l20 20-20 20H0l20-20z\"/>\n </svg>\n</a>"
+ },
{
"name": "prevent double click",
"options": {
Action run for 5f0c6c5 |
📋 StatsNo changes to any distributed file sizes! Action run for 5f0c6c5 |
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.
Start buttons use flexbox for layout and alignment. Part of how flexbox works involves it ignoring whitespace between adjacent flex children (elements and text nodes), causing them to render 'squashed' together.
For example, HTML in a start button like this:
Would render like this:
By wrapping the entire HTML string in an element, we remove the elements and text nodes from being flex children, and whitespace renders as expected.
Fixes #3406.
Changes
isStartButtonis true and the content is being provided byhtmlparameter.<span>element surrounding it.<button>variants of the component, this has been abstracted into abuttonTextvariable set in the Nunjucks template.Thoughts
Making the insertion of the
<span>element highly conditional is in aid of reducing the footprint of additional code generated by the macro. There's no point including it for text-only inner content or on non-start buttons, as the issue is not present there. A few extra bytes is still a lot of data at scale!I have, controversially, listed this as a fix. I don't think we need to list it as a recommended change because:
<span>only needs to be added in this one, specific situation.<span>, the component looked visually broken. Presumably, any developer user that encountered this issue before either inserted a wrapping element themselves or altered the button content to not exhibit the issue.