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

Add rel attribute to component wrapper #4551

Merged
merged 2 commits into from
Jan 15, 2025
Merged

Add rel attribute to component wrapper #4551

merged 2 commits into from
Jan 15, 2025

Conversation

andysellick
Copy link
Contributor

What

Adds the rel attribute to the component wrapper helper.

Why

Needed for the migration of the button component onto the component wrapper.

Visual Changes

None.

Trello card: https://trello.com/c/hUDC8lzz/418-add-component-wrapper-helper-to-button-component

@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4551 January 14, 2025 16:09 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4551 January 14, 2025 16:10 Inactive
@andysellick andysellick requested a review from AshGDS January 14, 2025 16:11
Copy link
Contributor

@AshGDS AshGDS left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for adding a set function as well. Approved with a non-blocking comment 👍

helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(rel: "nofollow")
helper.set_rel("noreferrer")
expect(helper.all_attributes[:rel]).to eql("noreferrer")
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocking comment - Just wondering about the semantics of set_rel/add_rel. I assume best practice would be to ensure set_rel is only used when paired with a boolean flag (e.g. helper.set_rel() if something == true? Otherwise, if we freely used set_rel on a component it would always override what the developer has passed through as rel in a render statement. And do you think there would ever be a situation where the developer needs to distinguish whether they want a rel value they've passed through to be an add_rel or a set_rel? How would we handle that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can see two use cases for the set_(thing) method (and you're right, I'll look at expanding that for the other attributes where appropriate) - one is the one you said, when paired with a boolean flag, but the other is for a component where we don't want something to be overridden, so it should always be set to what is in the template no matter what is passed.

I'll have a think about the best way of documenting this, might be something to add to this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AshGDS have expanded the documentation in an extra commit, can you take a look?

Copy link
Contributor

@AshGDS AshGDS left a comment

Choose a reason for hiding this comment

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

LGTM 👍

- explain difference between a set and add method for component options
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4551 January 15, 2025 10:18 Inactive
@andysellick andysellick merged commit ac48418 into main Jan 15, 2025
12 checks passed
@andysellick andysellick deleted the cw-add-rel branch January 15, 2025 10:21
@AshGDS AshGDS mentioned this pull request Jan 16, 2025
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.

3 participants