-
Notifications
You must be signed in to change notification settings - Fork 21
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
Support links opening in new tab #363
Conversation
✅ Deploy Preview for govuk-components ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
065eae3
to
dfc0893
Compare
dfc0893
to
de317d3
Compare
Looks good! Might be worth checking if this plays nicely if you were to also specify those eg: govuk_link_to "Blah", "https://www.example.com", {rel: "help", target: "new"}, new_tab: "true" Behaviour here is a bit unpredictable, but possibly the ideal would be to:
|
This should be quite straightfowrard since this change to html-attributes-utils. Unfortunately as we can see from the builds, Ruby 3.0.0 changed the way keyword arguments meaning that the approach here needs to be adjusted. I'm not sure it's possible to change without breaking Rails compatibility or nesting the params inside the options hash. |
Going to hold off on this until Ruby |
de317d3
to
de8dcaf
Compare
This PR can follow on from #381 and will be in the upcoming release 🥳 |
The new tab argument injects some extra HTML attributes that are suggested by the GOV.UK Design System.
When new tab is: * false - nothing happens * true - the default text appended to the link * a string - the supplied text is appended to the link
Now we've added a keyword argument to the link helper we need to tell Ruby that the third arg is a hash and not a keyword argument. This is likely to be a breaking change.
de8dcaf
to
b7563f9
Compare
We're going to use deep merge on the options passed to govuk_link_helper and version 1.0.0 adds 'rel' to the list of mergeable items
This will allow us to merge the default and provided params in a way that overwrites the target attribute but combines the rel Add a test that covers the behaviour based on @frankieroberto's suggestion in the thread. #363
This behaviour is now included and covered by these specs: |
This PR adds new keyword argument
new_tab
to#govuk_link_to
and#govuk_button_link_to
that makes it easier (and safer) for developers to create links that open in a new tab/window.The design system specifies that the attributes
rel="noreferrer noopener" target="_blank"
should be present to prevent reverse tabnabbing. This is often forgotten by developers.The default value for
new_tab
is false. The new behaviours are as follows:new_tab: false
- no change, the helper works in the normal fashionnew_tab: true
- the default suffix is added after the link textnew_tab: "a string"
- the supplied suffix is added after the link textThe default suffix is "(opens in new tab)".
Fixes #360