Expandable text
ProText cut to a few lines with "See more", shown only when it is cut, that expands it in place: posts, comments, reviews and bios. Not an M3 component (@windmorph/react-pro).
import { ExpandableText } from '@windmorph/react-pro';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Keyboard
| Key | Action |
|---|---|
| Tab | Moves focus to "See more" (or "See less"), and on to the next element. |
| Enter or Space | On "See more", expands the text and moves focus to its start. On "See less", collapses it and returns focus to "See more". |
Screen reader
- Role
- The text in a
div(orpwithas="p"); "See more" and "See less" arebuttons. - Accessible name
- The buttons are named by their words, from
labels(more,less). - States announced
- The buttons carry
aria-expanded(false on "See more", true on "See less") andaria-controlspointing at the text.
- Screen readers read the whole text even while it is cut: the clamp is visual only, so nothing is hidden from them.
- Without JavaScript the full text shows, with no button.
Focus
- "See more" shows only when the text is actually cut, and is in the Tab order after the text's own links. "See less" (with
collapsible) follows the text. - Pressing "See more" removes it and moves focus to the start of the text (focusable by script only,
tabIndex={-1}) without scrolling, so the reader carries on from there. Pressing "See less" returns focus to "See more" (also on the first collapse of a text that started expanded), also without scrolling; only if the text's start is then above the window is it brought back into view. - Keyboard focus shows M3's focus indicator: a 3px
secondaryoutline 2px outside the button or the text. Pointer presses show no ring. - A link or button in the cut part that takes focus by Tab expands the text, focus staying on it, so it is never hidden under the fade or scrolled out of the clamped box.
Touch target
The buttons are one line of text tall, and each gets an invisible touch target 48px tall and at least 48px wide, growing down and sideways from its line, so it never covers the line above.
Motion
Expanding and collapsing are instant, with no height animation. When "See less" brings the text's start back into view, the page scrolls smoothly, and at once under reduced motion.
What you need to do
- Pass the button words through
labels(more,less) so they come from your translations. - Set
langwhen the text is in a different language from the page. - In forced-colours mode the buttons use the system button colour (
ButtonText), underlined; keep anyclassNames.buttonoverride from removing that.