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 'draggable' attribute to component wrapper helper #4544

Merged
merged 2 commits into from
Jan 14, 2025
Merged

Conversation

andysellick
Copy link
Contributor

What

Adds the draggable attribute to the component wrapper helper.

Also includes a clean up/restructure of the tests, and adding some missing things to the documentation.

Why

Needed for the button component.

Visual Changes

None.

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

- some option were missing from the docs and the snippet of info shown on the component guide
- restructure the tests, some tests were incorrectly nested
- add a few extra tests to cover corner cases and expand initial test to include new attributes
- make order of tests more consistent (invalid value, valid value, override value)
@andysellick andysellick marked this pull request as ready for review January 14, 2025 09:43
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-4544 January 14, 2025 09:43 Inactive
@andysellick andysellick requested a review from AshGDS January 14, 2025 09:47
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 - needs a changelog entry, and I've added a non-blocking comment 👍

it "can add aria attributes to already passed aria attributes" do
helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(aria: { label: "original-label", describedby: "other" })
helper.add_aria_attribute({ label: "extra-label", controls: "something" })
expect(helper.all_attributes[:aria]).to eql({ label: "original-label extra-label", describedby: "other", controls: "something" })
Copy link
Contributor

Choose a reason for hiding this comment

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

Possibly a nitpick/complicating the wrapper, but should there be a set_aria_attribute function, or a boolean passed to add_aria_attribute that allows you to override the existing aria attributes instead of appending to the existing one? Currently this test appends more text to the label when overriding a label entirely seems like the more common use case. For example:

helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(aria: { label: "Expand menu", })
helper.add_aria_attribute({ label: "Collapse Menu" }) if the_menu_is_open_on_pageload

# In our current implementation, the label becomes "Expand menu Collapse Menu"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good question. If it's all right I think I'll look at it in a separate PR, as there might be more options where having both an add and a set method might be useful.

@andysellick andysellick merged commit fd2a2c9 into main Jan 14, 2025
12 checks passed
@andysellick andysellick deleted the cwh-draggable branch January 14, 2025 11:59
@andysellick
Copy link
Contributor Author

Forgot to add a changelog entry, sorry 🤦

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