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(FORMS-6979): Coral-Icon receives alt attribute value from wrapping Button title or icon attributes #295

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions coral-base-button/src/scripts/BaseButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@

if (this.iconPosition === iconPosition.LEFT) {
this.appendChild(label);
} else {

Check warning on line 195 in coral-base-button/src/scripts/BaseButton.js

View workflow job for this annotation

GitHub Actions / build (12.x)

Closing curly brace appears on the same line as the subsequent block
this.insertBefore(label, this.firstChild);
}
}
Expand Down Expand Up @@ -407,7 +407,7 @@

if (value === variant._CUSTOM) {
this.classList.remove(CLASSNAME);
} else {

Check warning on line 410 in coral-base-button/src/scripts/BaseButton.js

View workflow job for this annotation

GitHub Actions / build (12.x)

Closing curly brace appears on the same line as the subsequent block
this.classList.add(...VARIANT_MAP[value]);

if (value === variant.ACTION || value === variant.QUIET_ACTION) {
Expand Down Expand Up @@ -457,6 +457,11 @@
// Update autoAriaLabel as well
iconElement.autoAriaLabel = iconAutoAriaLabelValue;

// Accessibility fix
// If the wrapping <button> has either a "title=" or an "icon=" attribute
// passes the value down to the <coral-icon> as "alt="
(this.title || this.icon) && (iconElement.alt = this.title || this.icon);
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 this case is only valid when button itself does not have any text content in it, secondly this code can be avoided by setting iconAutoAriaLabel to Icon.autoAriaLabel.ON

Copy link
Member

Choose a reason for hiding this comment

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

the icon attribute doesn't seem like it would ever be satisfactory alt text. Looking at the list of icons these are not suitable as alt text. Perhaps as a fallback you could space separate instead of camel case - but even then these wouldn't be localized so it would still seem like a bad idea.


// removes the icon element from the DOM.
if (this.icon === '') {
iconElement.remove();
Expand Down Expand Up @@ -505,7 +510,7 @@
if (this._variant !== variant._CUSTOM) {
if (this._variant === variant.ACTION || this._variant === variant.QUIET_ACTION) {
label.classList.add(`${ACTION_CLASSNAME}-label`);
} else {

Check warning on line 513 in coral-base-button/src/scripts/BaseButton.js

View workflow job for this annotation

GitHub Actions / build (12.x)

Closing curly brace appears on the same line as the subsequent block
label.classList.add(`${CLASSNAME}-label`);
}
}
Expand Down Expand Up @@ -612,7 +617,7 @@
// Don't add duplicated icons
if (iconAdded) {
this.removeChild(child);
} else {

Check warning on line 620 in coral-base-button/src/scripts/BaseButton.js

View workflow job for this annotation

GitHub Actions / build (12.x)

Closing curly brace appears on the same line as the subsequent block
// Conserve existing icon element to content
this._elements.icon = child;
fragment.appendChild(child);
Expand All @@ -622,7 +627,7 @@
// Avoid content zone to be voracious
else if (contentZoneProvided) {
fragment.appendChild(child);
} else {

Check warning on line 630 in coral-base-button/src/scripts/BaseButton.js

View workflow job for this annotation

GitHub Actions / build (12.x)

Closing curly brace appears on the same line as the subsequent block
// Move anything else into the label
label.appendChild(child);
}
Expand Down