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 alt text support to decorateIcon #280

Closed
wants to merge 7 commits into from

Conversation

bstopp
Copy link

@bstopp bstopp commented Nov 1, 2023

Default the Alt Text to the iconName as referenced in markdown.

Also support i18n lookup based on icon-<icon-name> key.

Fix #279

Test URLs:

Copy link

aem-code-sync bot commented Nov 1, 2023

Hello, I'm the AEM Code Sync Bot and I will run some test suites that validate the page speed.
In case there are problems, just click the checkbox below to rerun the respective action.

  • Re-run PSI Checks

@bstopp bstopp changed the title Add alt text to icon. Add alt text support to decorateIcon Nov 1, 2023
@bstopp
Copy link
Author

bstopp commented Nov 1, 2023

I don't know how to provide a valid PSI after URL. I can push a branch to the upstream repo, however I do not have rights to the Content source to make the change there to reflect tests.

Here's the PSI check of my demo page

@davidnuescheler
Copy link
Contributor

i don't think that the decorate method (as it is called very early) should have a dependency on placeholders as that may add (variable and possibly considerable) weight to before LCP.

i think icons and alt texts and title / description inside the SVGs are an interesting quandary where i am not totally sure what's the correct solution, but i think that they don't need to be added before the icons are loaded (via lazy or intersection observer).

i think @ramboz has a PR (i forgot where) to enable spriting (and title / alt handling).

@bstopp
Copy link
Author

bstopp commented Nov 2, 2023

i think @ramboz has a PR (i forgot where) to enable spriting (and title / alt handling).

All sprites were removed during the renaming process. to aem.js Unless there's a new proposal out there to re-add sprite logic? (I haven't seen any new ones).

Even if the SVG has title/alt text inside the file itself, i'm not sure that solves this issue - Since the img tag itself doesn't have this information. I added titles to the LinkedIn svg on my test page, and it didn't resolve the issue for that case (PSI Report for non-fix branch) It seems as though if the SVG is inlined it meets the Accessibility requirements, but not if it is a img src.

@amol-anand indicated this might be a conern. I will remove the placeholders, but there should always be a default - it can just be the iconName as provided by the Author. I'll provide an example in the Block Party on how to post-process icons to provide a more meaningful alt description using placeholders.

@bstopp
Copy link
Author

bstopp commented Nov 2, 2023

Updated PSI Report

@ramboz
Copy link
Collaborator

ramboz commented Nov 6, 2023

Right, I submitted the old spriting to the block party, but haven't heard back from the team yet.

You can find the PR here: ramboz#12

scripts/aem.js Outdated
@@ -395,16 +395,18 @@ function decorateButtons(element) {

/**
* Add <img> for icon, prefixed with codeBasePath and optional prefix.
* @param {span} [element] span element with icon classes
* @param {Element} [span] span element with icon classes
* @param {string} [prefix] prefix to be added to icon the src
*/
function decorateIcon(span, prefix = '') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need to make this configurable. It only makes sense to add the alt attribute if we have an actual valuable description to expose via screen readers. If the icons are only used for decoration purposes, then it's usually better to just annotate them with role="presentation" alt=" ".

I'd rather propose something like:

Suggested change
function decorateIcon(span, prefix = '') {
function decorateIcon(span, prefix = '', alt = '') {

Copy link
Author

Choose a reason for hiding this comment

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

I did commit this, but my only concern with this is - there's no value coming from the decorateIcons wrapping iteration. This function is not exported, so where should the caller source this value?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You'd have to export the single decorateIcon as well and then explicitly instrument in the blocks that require proper alt text

scripts/aem.js Outdated Show resolved Hide resolved
bstopp and others added 4 commits November 6, 2023 12:21
Co-authored-by: Julien Ramboz <ramboz@users.noreply.github.com>
Co-authored-by: Julien Ramboz <ramboz@users.noreply.github.com>
@rofe
Copy link
Contributor

rofe commented Dec 7, 2023

@bstopp i think this PR needs to be moved to aem-lib since aem.js is released to this repo from there.

@bstopp
Copy link
Author

bstopp commented Dec 8, 2023

Didn't realize that. i'll move it this weekend.

@fkakatie
Copy link
Member

Didn't realize that. i'll move it this weekend.

@bstopp, please take a look here when you get a chance: adobe/aem-lib#26

@bstopp
Copy link
Author

bstopp commented Dec 11, 2023

Closing as moved to aem-lib

@bstopp bstopp closed this Dec 11, 2023
@bstopp bstopp deleted the bug/icon-alt-text branch December 11, 2023 17:34
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.

Update to Icon SVG Handling created Accessibility regression
5 participants