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

Update on this page and disclosure components to use SVG icons #3261

Merged
merged 5 commits into from
Feb 10, 2025

Conversation

davidrapson
Copy link
Contributor

@davidrapson davidrapson commented Mar 25, 2024

Background

We currently ship two different sets of icons within the design system. A new SVG icon set and the previous icon font. We've long wanted to remove the icon font completely but to do that we need to ensure that no internal components are using icon fonts.

This pull request makes steps to remove them from two related components: On this page and disclosure.

Changes

Inline toggle code

This is the biggest surface change. The on this page and disclosure components previously shared code via a utility method. In retrospect this makes it quite hard to change each component independently and in practice the disclosure component had subtly different behaviour which had to be patched in separately.

Practically these are both an implementation of https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/, much like targeted content is so it's reasonable to duplicate the pattern here to keep things flexible.

To account for this an additional cypress test has been added to cover the on this page toggle behaviour. This is preferable to the previous test anyway as it checks against a real component example rather than the lower level fixture used by the utility code.

Use SVG icons in place of icon fonts

For both components the same pattern has been used to make use of the PlusMinus icon component. Like with previous versions of this move the SVG icons are slightly thinner than the icon versions so there is a small visual change.

@davidrapson davidrapson mentioned this pull request Mar 25, 2024
4 tasks
@davidrapson davidrapson force-pushed the toggle-svg-icons branch 5 times, most recently from 0a30cef to 24e0efe Compare March 26, 2024 10:00
it { is_expected.to have_css "[data-toggle-target-id='my-id']" }
it { is_expected.to have_css "[aria-controls='my-id']" }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been switched out as the component no longer needs data-toggle-target-id to work. Testing against aria attributes is preferable too.

@davidrapson davidrapson marked this pull request as ready for review March 26, 2024 10:53
@davidrapson davidrapson requested a review from a team as a code owner March 26, 2024 10:53
@davidrapson davidrapson requested review from leeky, akamike, cnorthwood, marianayovcheva and davidsauntson and removed request for leeky and akamike March 26, 2024 10:53
@marianayovcheva marianayovcheva added the docs preview If this is added a preview version of the docs site will be deployed label Mar 27, 2024
@marianayovcheva
Copy link
Contributor

Yay for moving away from the icon font! 🎉 Looks really good!
A wild opinion - I think we don't necessarily need to get rid of the show-hide util. When I was comparing the two files (disclosure.ts and on-this-page.ts) I noticed that the main difference was the disclosure has the setSummaryText function. We could update show-hide with the tidied up common functionality and add the differences in the files. That being said, I don't know if there will be more differences between the two in the future, and the separate approach is also good.
Leaving open for David and Chris to also have a look.

@davidrapson
Copy link
Contributor Author

A wild opinion - I think we don't necessarily need to get rid of the show-hide util

My (loosely held) but strong preference is to keep them separate, especially as we only have two examples of slightly similar code. Not against extracting it again in future though. I'm very much optimising for "make the components easy to change" vs "share the most code" here.

@citizensadvice citizensadvice deleted a comment from github-actions bot Apr 17, 2024
@citizensadvice citizensadvice deleted a comment from github-actions bot Apr 17, 2024
@citizensadvice citizensadvice deleted a comment from github-actions bot Apr 17, 2024
@davidrapson davidrapson removed the docs preview If this is added a preview version of the docs site will be deployed label Apr 17, 2024
Copy link
Contributor

@davidsauntson davidsauntson left a comment

Choose a reason for hiding this comment

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

Nice to be closer to ditching the icon font 🙌🏻

We use the abstracted show/hide quite a lot in content platform. I think will cause a lot of code duplication in that codebase, but we can abstract it out there instead if we need to.

I'm in favour of not abstracting stuff unless it's useful - I think this is useful but it's not a strongly held opinion. Was changing to an icon font difficult because of the shared show/hide code, or has it made something else harder to change somewhere?

@davidrapson davidrapson added the help wanted Extra attention is needed label Aug 28, 2024
@davidrapson davidrapson marked this pull request as draft January 22, 2025 11:36
@davidrapson
Copy link
Contributor Author

Moving this back to draft as it it needs updating and I'd like to resolve the outstanding question on the show/hide helper

(My stance is that we should ditch it in the long term as it still relies on the icon font and is too generic/internal for consumers to be relying on but we should reinstate the helper in this PR so it doesn't need to block this going in)

@davidrapson davidrapson removed the help wanted Extra attention is needed label Jan 27, 2025
@davidrapson
Copy link
Contributor Author

Update this to bring it up to date with main.

Refreshed my memory a bit on where we left things on the show-hide utility and checked a couple more things:

The existing utility ultimately works based on the old icon font which a) we want to remove and b) works very differently to inline SVG icons. I’m not entirely sure what a generic utility for this would look like for those 🤔

I’d wondered if public-website was relying on this but it turns out it has it’s own copy of show-hide and doesn’t load the one here anyway which makes things simpler (maybe that came first?) so I think we’re safe to remove it as nothing is using and it would need a significant re-think to be useful with the SVG icon setup.

We should see if a suitable alternative comes out of removing icon font uses from public website if it turns out there is a revised version of this utility that works.

Does that sound good to folks?

@davidrapson davidrapson marked this pull request as ready for review January 27, 2025 18:20
Copy link
Contributor

@davidsauntson davidsauntson left a comment

Choose a reason for hiding this comment

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

Neither of the energy apps use the show-hide either 👍🏻

This change removes the use of icon fonts from the disclosure component.
To enable this the component has been refactored to inline the toggle
logic rather than sharing it between two components to make
per-component changes simpler to manage.

This change also makes sure the component consistently uses cads
prefixed classes including for js-cads classes.
This change removes the use of icon fonts from the on this page
component. To enable this the component has been refactored to inline
the toggle logic rather than sharing it between two components to make
per-component changes simpler to manage.

Includes an additional cypress tests to make sure we have test coverage
as some is lost by inlining the shared code.
This behaviour is now included and tested on a per-component basis.
@davidrapson davidrapson merged commit 83f6202 into main Feb 10, 2025
18 checks passed
@davidrapson davidrapson deleted the toggle-svg-icons branch February 10, 2025 14:28
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.

4 participants