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

Fix icons/logos with static SVG IDs to use generated IDs #5204

Merged
merged 12 commits into from
Sep 23, 2021

Conversation

cee-chen
Copy link
Member

@cee-chen cee-chen commented Sep 21, 2021

Summary

⚠️ This PR is primarily whitespace/indenting changes - I recommend viewing diffs with whitespace changes disabled.

Closes #4454

This PR fixes all icons/logos with static SVG ids (used for masks/fills/defs, etc.) to use our HTML ID generator utility, making every icon have its own unique set of IDs.

The issue with static IDs on our logo/icon SVGs is that they create semantic/accessibility errors when you use multiples of those icons on the same page, when only 1 unique ID should exist per-page.

Before

After:

(NB: all other issues on the page are pre-existing, we're only looking at the minor count for ID issues)

QA

Checklist

  • Check against all themes for compatibility in both light and dark modes

- [ ] Checked in mobile

  • Checked in Chrome, Safari, Edge, and Firefox

- [ ] Props have proper autodocs and playground toggles
- [ ] Added documentation
- [ ] Checked Code Sandbox works for any docs examples

- [ ] Checked for breaking changes and labeled appropriately

  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately
  • Revert 49b228e

@cee-chen cee-chen changed the title Logo generated ids Fix icons/logos with static SVG IDs to use generated IDs Sep 21, 2021
Comment on lines 3 to 7
import { htmlIdGenerator } from '../../../services';

const EuiIconLogoApache = ({ title, titleId, ...props }) => {
const generateId = htmlIdGenerator('logo_apache');
Copy link
Member Author

@cee-chen cee-chen Sep 21, 2021

Choose a reason for hiding this comment

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

You might ask: "Constance, you just created a useGeneratedHtmlId hook for functional components, why not use that here?"

To which I would say: Great question! The answer is because useGeneratedHtmlId() generates a completely random UUID each time, and I actually didn't want that for these logo IDs - I wanted their UUIDS to be the shared between each SVG/icon instance, and simply use different suffixes, like so:

This is also a good illustration/use-case of when to use the use hook (simple/singleton IDs) vs the original generator utility.

I'll also add I'm not concerned about the IDs regenerating for these icons: they have no internal state and won't rerender from that, so they'll only update when they receive new props dynamically, which I anticipate being fairly rare (and usage of these specific logos are rare/possibly will be deprecated, and and seem to be limited to Kibana currently in any case).

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5204/

@cee-chen cee-chen marked this pull request as ready for review September 21, 2021 16:09
Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

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

Hey we'll need to find a more general approach to solving this problem: these files are generated and the changes here will be undone the next time yarn compile-icons run 🤖. Output below:

Screen Shot 2021-09-22 at 8 35 50 AM

I think all changes need to be scoped to https://github.com/elastic/eui/blob/b23c9d7020526df7b5f971e2cae32e9a9246f9c5/scripts/compile-icons.js or to the original .svg files.

@thompsongl
Copy link
Contributor

Relatedly, we should add a THIS IS A GENERATED FILE. DO NOT MODIFY MANUALLY. comment to the template in compile-icons.js so this is more clear.

@cee-chen
Copy link
Member Author

Oh snap! I hadn't realized that, sorry. Will take a look at that generated comment as well!

@cee-chen
Copy link
Member Author

Going to do the generated comment in a separate PR since it touches a whole lot more icon files than I want to have in the diff for this specific PR/issue: #5210

- DRY out toString() to one var
- switch from indexOf to the slightly more readable `.includes()` API
- Use different template with htmlIdGenerator import/setup + non-implicit return
- tweak template literal indenting
- DRY out fileName for use as generator prefix
NOTE: I'm avoiding doing this in the `ast` process for two main reasons:

1. I'm a monster who think regexes are neat

2. the ${jsx} in the ast template is an actual tree of components and it seems much more tedious to iterate through each one & examine its attributes (of which the url() attr can have multiple - e.g. fill or mask), rather than use a basic regex capture group
- in their current state, all icons (except for dropwizard) will automatically truncate their ID names to 'a', 'b', etc. when cleanupIDs is set to true
moment of truth!
@cee-chen
Copy link
Member Author

@thompsongl Alrighty, compile-icons.js has been updated to automatically output the same changes I made manually! 🎉

Let me know what you think (and also if you think I'm a monster for using regexes)!

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5204/

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

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

This is great! Just a couple things before merging:

  • Revert 49b228e
  • Merge/rebase master and update the changelog entry location

(Also, you're not a regex monster 👹)

@cee-chen
Copy link
Member Author

Master merged, changelog updated, revert made, and auto-merge enabled 🚀

@cee-chen cee-chen enabled auto-merge (squash) September 23, 2021 16:27
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5204/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logo icons should use random IDs
3 participants