-
Notifications
You must be signed in to change notification settings - Fork 829
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
Conversation
22a233e
to
72e2c68
Compare
import { htmlIdGenerator } from '../../../services'; | ||
|
||
const EuiIconLogoApache = ({ title, titleId, ...props }) => { | ||
const generateId = htmlIdGenerator('logo_apache'); |
There was a problem hiding this comment.
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).
Preview documentation changes for this PR: https://eui.elastic.co/pr_5204/ |
There was a problem hiding this 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:
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.
Relatedly, we should add a |
Oh snap! I hadn't realized that, sorry. Will take a look at that generated comment as well! |
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
72e2c68
to
f0488ac
Compare
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!
f0488ac
to
49b228e
Compare
@thompsongl Alrighty, Let me know what you think (and also if you think I'm a monster for using regexes)! |
Preview documentation changes for this PR: https://eui.elastic.co/pr_5204/ |
There was a problem hiding this 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 👹)
Master merged, changelog updated, revert made, and auto-merge enabled 🚀 |
Preview documentation changes for this PR: https://eui.elastic.co/pr_5204/ |
Summary
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
id attribute value must be unique
Checklist
- [ ] Checked in mobile- [ ] Props have proper autodocs and playground toggles- [ ] Added documentation- [ ] Checked Code Sandbox works for any docs examples- [ ] Checked for breaking changes and labeled appropriately