Page MenuHomePhabricator

Add alternative text to CSS generated content
Closed, ResolvedPublic2 Estimated Story Points

Description

Background

Vector uses msg-parentheses and msg-brackets in order to generate visual brackets and parenthesis via CSS content. This method was originally used to hide the visual content from screenreaders and assistive tech, but depending on the browser and screenreader the content can still be read out. Adding alternative text to the CSS content would be a quick fix, though it's support is limited to Chrome.

Related: https://phabricator.wikimedia.org/T268900#8256603

Requirement

Scope: Desktop web (Vector 2022).

  • CSS-generated content (e.g., msg-parentheses, msg-brackets) must include alternative text of an empty string ('') to prevent screen readers from reading visual brackets or parentheses.
  • Rendering must remain compatible with older browsers that do not support content alternative text.
  • The visual display of parentheses and brackets must remain unchanged.
  • Screen readers must only read the label text, not decorative characters.

BDD

Feature: Accessibility improvement for CSS-generated content

  Scenario: Screenreader behavior with CSS-generated parentheses
    Given I am using a modern browser and screenreader
    When viewing a Vector page that includes `msg-parentheses` or `msg-brackets`
    Then screenreader output does not announce the parentheses or brackets
    And only the label text is read aloud

Test Steps

Test Case 1: Screenreader validation

  1. Open a Vector 2022 page containing elements with msg-parentheses or msg-brackets.
  2. Enable VoiceOver (macOS) or NVDA (Windows).
  3. AC1: Screenreader reads only the label text.
  4. AC2: Parentheses/brackets are not read aloud.

QA Results - Beta

ACStatusDetails
1T320996#11248379
2T320996#11248379

QA Results - Prod

ACStatusDetails
1T320996#11248384
2T320996#11248384

Acceptance criteria for done

  • CSS generated content in Vector has alternative text of empty string (i.e. content: '@{msg-parentheses-end}' / '')
  • The rendering doesn't fail in older browsers that don't support content alternative text

Event Timeline

bwang triaged this task as Low priority.Oct 25 2022, 7:57 PM
LGoto set the point value for this task to 2.Jan 12 2023, 6:43 PM

Thank you for tagging this task with good first task for Wikimedia newcomers!

Newcomers often may not be aware of things that may seem obvious to seasoned contributors, so please take a moment to reflect on how this task might look to somebody who has never contributed to Wikimedia projects.

A good first task is a self-contained, non-controversial task with a clear approach. It should be well-described with pointers to help a completely new contributor, for example it should clearly point to the codebase URL and provide clear steps to help a contributor get set up for success. We've included some guidelines at https://phabricator.wikimedia.org/tag/good_first_task/ !

Thank you for helping us drive new contributions to our projects <3

It now works pretty widely, but this would probably need to be written as

.selector {
  content: '@{msg-parentheses-end}';
  content: '@{msg-parentheses-end}' / ''
}

Just to ensure you don't break Firefox and Safari older than about a year or so.

Shadabgdg subscribed.

I'm interested in working on this task. Plan: update the CSS to add alt='' to the msg-parentheses/msg-brackets generated content, following the linked Chrome implementation details. Note: This will only have an effect in Chrome as other browsers do not currently support alt text in CSS content.

Change #1184495 had a related patch set uploaded (by Shadabgdg; author: L10n-bot):

[mediawiki/skins/Vector@master] Vector: Replace CSS-generated parentheses with empty content for accessibility

https://gerrit.wikimedia.org/r/1184495

I have uploaded a patch for review:
https://gerrit.wikimedia.org/r/c/mediawiki/skins/Vector/+/1184495

This patch replaces CSS-generated parentheses with empty content to improve accessibility and ensure screen readers do not announce extra characters.

Jdlrobson-WMF subscribed.

Patch doesn't seem related? Did you push the correct patch?

Change #1185187 had a related patch set uploaded (by Shadabgdg; author: Shadabgdg):

[mediawiki/skins/Vector@master] Vector: Replace CSS-generated parentheses with empty content for accessibility

https://gerrit.wikimedia.org/r/1185187

Change #1184495 abandoned by Shadabgdg:

[mediawiki/skins/Vector@master] Vector: Replace CSS-generated parentheses with empty content for accessibility

Reason:

Abandoning this change in favor of https://gerrit.wikimedia.org/r/c/mediawiki/skins/Vector/+/1185187
, which contains the correct implementation.

https://gerrit.wikimedia.org/r/1184495

I’ve uploaded the corrected patch here: Gerrit: 1185187

Hi @Izno, are you sure about this?
From the MDN docs it's not entirely clear if content supporting browser, that have not yet implemented the alt fallback are ignoring the rule. The normal way were any invalid value the whole property is ignored, but there are some sequences where this is not true.

Also the alt text is normally aimed for image or emoji replacement and not for string replacements.

It now works pretty widely, but this would probably need to be written as

.selector {
  content: '@{msg-parentheses-end}';
  content: '@{msg-parentheses-end}' / ''
}

Just to ensure you don't break Firefox and Safari older than about a year or so.

OK, I've put this to test in Firefox 115/Win 8.1, and the content property with alt fallback is no exception. @Izno's recommendation is key for our basic support.

image.png (1,220×1,124 px, 331 KB)

Hi @Izno, are you sure about this?

My intuition is generally that browsers are going to be fairly conservative in what they accept as valid CSS so as to prevent it becoming a threat vector in general and to save them the work of supporting CSS that isn't standard. Expanding content with the / 'abc' felt like a place where that conservatism was going to be relevant. Good to see that borne out in that case. :^)

Change #1185187 merged by jenkins-bot:

[mediawiki/skins/Vector@master] styles: Add alt text fallback for CSS-generated parentheses in user menu

https://gerrit.wikimedia.org/r/1185187

I see several other places in core and elsewhere that could use this kind of change. search that has many false positives and maybe also some false negatives. mediawiki.hlist parentheses and middots, makeCollapsible brackets, skinStyles.less, and so on (and eyeballing, what look like a lot of clearfixes that given the number of less files appearing could potentially be a mixin).

@Volker_E I'm not clear if this is something I can/should be validating in prod.

@Edtadros With a screenreader and a modern browser (latest Safari & VoiceOver for example), you should be able to verify that the brackets are not read out/exposed, only the label itself.

Test Result - Beta

Status: ✅ PASS
Environment: beta
OS: macOS Sequoia 15.5
Browser: Safari
Device: MS
Emulated Device: NA

Test Case 1: Screenreader validation

  1. Open a Vector 2022 page containing elements with msg-parentheses or msg-brackets.
  2. Enable VoiceOver (macOS) or NVDA (Windows).
  3. AC1: Screenreader reads only the label text.
  4. AC2: Parentheses/brackets are not read aloud.

screenshot 235.png (1,632×651 px, 273 KB)

@Volker_E on beta it doesn't announce the brackets, but it does announce the pipe as a vertical line.

Test Result - Prod

Status: ✅ PASS
Environment: testwiki
OS: macOS Sequoia 15.5
Browser: Safari
Device: MS
Emulated Device: NA

Test Case 1: Screenreader validation

  1. Open a Vector 2022 page containing elements with msg-parentheses or msg-brackets.
  2. Enable VoiceOver (macOS) or NVDA (Windows).
  3. AC1: Screenreader reads only the label text.
  4. AC2: Parentheses/brackets are not read aloud.

screenshot 105.mov.gif (1,632×650 px, 1 MB)