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

Refactor the accordion component code #2797

Merged
merged 3 commits into from
Jul 14, 2022
Merged

Refactor the accordion component code #2797

merged 3 commits into from
Jul 14, 2022

Conversation

andysellick
Copy link
Contributor

@andysellick andysellick commented May 25, 2022

What

Refactor some things in the accordion code. Specifically:

  • remove some variables that weren't used
  • stop having class name variables that don't start with . except it's needed every time the variable is used
  • rename the class name and element selector variables to clearly distinguish them
  • remove the class that was added on JS initialisation as it doesn't do anything except allow a test to pass - we should have a better way of testing our code than that

Why

I made some unrelated changes in the accordion recently and this was bothering me.

I'm 99.9% certain the variables I've removed aren't used but worth double checking. I think we used to have the ability to pass translated text to the component for the 'show/hide' and 'show/hide all' links (since they're created by JS, which can't access translations from Rails) but don't have that since now most of the accordion component JS is managed by code from govuk-frontend. At some point it might be good to think about how to bring that functionality back.

Visual Changes

None.

- I think these were previously used when the accordion had options to pass text from Rails to the JS, in order to do translations
- but they don't appear to be used anywhere
- separate class names from element selectors
- rename class name variables to distinguish them
- include '.' in selector variables instead of doing it multiple times throughout the code
- class was being added on component JS initialisation
- appears to only be needed for a test to pass
- removing as this is not how we should be testing this code, the JS is currently not fully tested but this is on our backlog to address
@andysellick andysellick marked this pull request as ready for review May 26, 2022 08:44
@querkmachine
Copy link
Member

I think we used to have the ability to pass translated text to the component […] At some point it might be good to think about how to bring that functionality back.

We're working on that at the moment! alphagov/govuk-frontend#1714

Signed,
Your friendly neighbourhood Design System team.

@andysellick
Copy link
Contributor Author

Brilliant, thanks @querkmachine!

@andysellick andysellick requested a review from injms June 29, 2022 16:32
@AshGDS AshGDS self-requested a review July 14, 2022 13:22
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.

Looks good to me @andysellick 👍

@andysellick andysellick merged commit ab864a5 into main Jul 14, 2022
@andysellick andysellick deleted the accordion-code branch July 14, 2022 15:07
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