Add option for wrapping trimmed text in an accessible screen reader only

Created on 7 March 2018, over 6 years ago
Updated 10 June 2023, about 1 year ago

So the idea of this feature is to add a trim option, to the format settings under "Additional options" for wrapping the trimmed text in an accessible screen reader tag,ie <span class="sr-only">[ trimmed text ]</span>.

See screenshot attached for idea of option.

This would be useful for allowing screen readers to read full title in a view for example even if it is trimmed down.

I have this working in a custom module where I used smart trim as the basis of the code, essentially using `substr`:

$remainingText = substr($text, $this->limit - $this->charCount - strlen($text));

with the output looking like this:

$output .= '<span class="' . $this->getSetting('wrap_class') . '">' . $remainingText . '</span>';

I only have it working for truncate by characters and had to force strip html due to any code in the trimmed text breaking out of the span for some reason...

✨ Feature request
Status

Closed: duplicate

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom georgebrook

Live updates comments and jobs are added and updated live.
  • Accessibility

    It affects the ability of people with disabilities or special needs (such as blindness or color-blindness) to use Drupal.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇪Ireland lostcarpark

    Is this something that could be incorporated into twig template? If it could be achieved with Twig variables, that would seem cleaner and more flexible.

  • Status changed to Closed: duplicate about 1 year ago
  • 🇺🇸United States markie Albuquerque, NM

    This can be resolved by extending the twig template. Closing.

  • 🇮🇪Ireland lostcarpark

    I wonder is there enough to close this yet? I was thinking a "remainder" variable containing the trimmed text would be needed?

  • 🇺🇸United States ultimike Florida, USA

    Markie and I discussed this at DrupalCon Pittsburgh and we really want to limit the formatter configuration options - we want to reduce them, if possible.

    But, if there is a variable we can make available to the new smart-trim.html.twig template, that would be worth considering.

    @georgebrook or @lostcarpark - I'm not clear on else we would need to make available in the template file for this request to be achievable. Perhaps an example would help. Am I thinking about this correct in the following example?

    Full body text:

    But we’ve met before. That was a long time ago, I was a kid at St. Swithin’s, It used to be funded by the Wayne Foundation. It’s an orphanage. My mum died when I was small, it was a car accident. I don’t remember it. My dad got shot a couple of years later for a gambling debt. Oh I remember that one just fine. Not a lot of people know what it feels like to be angry in your bones.

    Trimmed text:

    But we’ve met before. That was a long time ago, I was a kid at St. Swithin’s, It used to be funded by the Wayne Foundation.

    Remainder text:

    It’s an orphanage. My mum died when I was small, it was a car accident. I don’t remember it. My dad got shot a couple of years later for a gambling debt. Oh I remember that one just fine. Not a lot of people know what it feels like to be angry in your bones.

    Do I have this correct?

    If so, can this use case be achieved by just adding a "remainder" variable to the twig template, as @lostcarpark suggests?

    -mike

  • 🇺🇸United States markie Albuquerque, NM

    I like the idea of the remainder variable but that is outside the scope of this request (in my opinion). A good use case for the remainder capture would be trimming, and then expanding on the same page. This would lead to the SDC example I was talking about as well. Of course that means we would probably bump this feature to a 3.x version for >10.1....

Production build 0.69.0 2024