Skip to content

feat(follow): read Get alerts and keep the button's width steady - #348

Merged
thomasguillot merged 8 commits into
trunkfrom
feat/follow-alerts-button
Nov 27, 2026
Merged

thomasguillot merged 8 commits into
trunkfrom
feat/follow-alerts-button

Conversation

@thomasguillot

@thomasguillot thomasguillot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

The Follow Coverage button changed width when a reader followed, gave no sign it was working, hid how to stop alerts, and said "Follow", which on a news site can read as following on social media or needing an account. This makes it say what it does, keeps it the same width, and confirms what the reader signed up for.

What changes

The button now reads Get alerts, then Alerts on with a check. Pointing at Alerts on, or tabbing to it, shows Stop alerts. "Stop alerts" replaces the issue's "Turn off" after newsroom feedback: a reader who comes back later still knows what it stops. The block keeps its name, Follow Coverage.

With this change:

  • The button keeps the width of its longest label, so a heading or text beside it doesn't move.
  • A small spinner shows while the browser and push service respond, for at least a second so it never flickers.
  • A short notice confirms the change: "Alerts on" or "Alerts off". Screen readers hear which liveblog: "You’ll get alerts for “Kettle River flood”." On a page with buttons for more than one liveblog, the notice shows that full sentence too. Without the Newspack plugin, screen readers announce it and nothing shows.
  • Right after alerts go on, the button keeps reading Alerts on under the pointer; Stop alerts shows once the reader moves away and comes back.
  • Closing the browser's permission prompt without answering returns the button to Get alerts with no message.
  • Publishers can still change the first label in the editor. Alerts on and Stop alerts can't be changed.
  • The button no longer appears in RSS feeds, where it can't work.
Before After
Before: Follow turns into a wider Following and pushes the text After: Get alerts, spinner, Alerts on with a short notice, Stop alerts on hover, then off
Before: Follow After: Get alerts
Before: Following, wider, text reflowed After: Alerts on with a check and the Alerts on. notice
Waiting Hover or focus
After: spinner while the browser responds After: Stop alerts on hover

The block README, DEVELOPMENT notes and the docs site pages are updated, and the three docs screenshots that show the button are retaken.

Closes #345.

How to test

  1. On a site with OneSignal set up, add a Follow Coverage block to a liveblog page, in a row with some text beside it. The inserted button reads "Get alerts".
  2. View the page and select Get alerts. A spinner shows for about a second, then the button reads "Alerts on" with a check. The text beside it doesn't move.
  3. Check the notice. It reads "Alerts on". With a screen reader on, it announces "You’ll get alerts for" followed by the liveblog's name in quotes.
  4. Move the pointer away, then back over the button. It reads "Stop alerts", at the same width.
  5. Select it. After the spinner it reads "Get alerts", and the notice reads "Alerts off".
  6. Add a second Follow Coverage block for a different liveblog to the page and select Get alerts on one. The notice shows the full sentence with that liveblog's name.
  7. Tab to the button while alerts are on. It reads "Stop alerts".
  8. In a browser that hasn't answered the site's notification prompt yet, select Get alerts and close the prompt without choosing. The button returns to "Get alerts" with no message.
  9. Block notifications for the site and select Get alerts. The blocked-notifications notice appears and the button stays on "Get alerts".
Technical details
  • Entry_Bindings::show_follow_labels() wraps the button's text in three labels stacked in one grid cell: the publisher's text, "Alerts on" with core's core/check icon, and "Stop alerts" (aria-hidden), plus a spinner. The new style.scss (the block's style) shows the right one from aria-pressed and aria-busy, so the button takes the width of the longest. "Alerts on" stays in the accessibility tree at zero opacity under hover and focus, so the name stays "Alerts on" with the pressed state.
  • The second and third labels and the spinner carry hidden, so a page without the stylesheet reads only the publisher's label. The stylesheet overrides hidden with a scoped !important, which also beats theme resets like [hidden] { display: none !important }.
  • data-on-notice / data-off-notice ("Alerts on" / "Alerts off") and data-on-message / data-off-message (the sentence with the liveblog's name in quotes) are built server-side; data-label-following is gone.
  • view.ts uses aria-busy and aria-disabled instead of disabled, so keyboard focus stays on the button while it waits. The outcome waits for MIN_PENDING_MS (1 second) and reaches every button for the same liveblog, including ones that arrived mid-toggle.
  • A closed or dismissed prompt never fires OneSignal's permissionChange, so the permission is also read shortly after requestPermission() resolves, from OneSignal or the browser's own Notification.permission.
  • Success uses Newspack UI's snackbar through the shared getSnackbar() helper, which the Share block now uses too. Newspack UI announces a notice as it opens it, so the notice opens with the full sentence; on a page with one liveblog it then shows the short text, keeping the sentence as screen-reader-text. Errors go to its error snackbar. Without Newspack UI, success goes to a visually hidden live region added when the toggle starts, and errors to the existing message after the button.
  • Coverage_Follow_Block::should_render() returns false in feeds, and the block's stylesheet joins the list preloaded for polled entries.
  • Tests: tests/js/follow-button.test.ts (spinner timing, buttons sharing a liveblog, confirmations, the prompt outcomes, failures) and test_button_holds_its_labels_and_names_the_liveblog / test_renders_nothing_in_a_feed in PHPUnit. Jest 234 passed, PHPUnit 1560 passed, PHPCS, Stylelint and the typecheck clean, docs site checks pass.
  • Checked in a browser on a local site: the width stays at 131px across all states, and the names read "Get alerts" and "Alerts on" (pressed).

Self-review: three rounds (Opus 5.5), no blockers.

thomasguillot and others added 6 commits November 27, 2026 15:08
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rant

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thomasguillot

thomasguillot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Self-review summary: four rounds on this branch before handoff.

Accepted:

  • 9104e8f: a browser prompt the reader closes no longer leaves the spinner on for good, and closing it shows no error. The button no longer renders in syndication feeds. Polled entries now load the button's stylesheet. The check uses core's core/check icon instead of a plugin copy. Long publisher labels can wrap again. The fallback live region exists before the first announcement. The state that keeps "Alerts on" under the pointer is only set while the pointer or focus is still on the button. A button that arrives mid-toggle gets the outcome too.
  • 179cadf: the labels stay hidden in the markup, and the stylesheet overrides that with a scoped !important instead of a script step, so an asynchronously loaded stylesheet can't flash all three labels at once. The permission check also accepts the browser's own grant. The check icon's fill follows the button text colour. The feed test gained a positive control, and a test covers a grant arriving through permissionChange.
  • Round 3: no changes; confirmed the above holds.
  • Round 4: reviewed eae4749 (the short "Alerts on." / "Alerts off." notice, with the liveblog named for screen readers); no changes needed.

Declined:

  • "Stop alerts" on keyboard focus isn't part of the accessible name. The issue asks for the swap on hover and focus, the resting label matches the name, and screen readers hear "Alerts on, pressed".
Deferred (not blocking)
  • Dropped: when a long liveblog name wraps the full sentence, swapping to the short text cancels the notice's fade-in. It only shows with long names or narrow screens, and a clean fix needs a createNotice option for separate spoken text in Newspack UI.

thomasguillot and others added 2 commits November 27, 2026 16:10
…creen readers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thomasguillot
thomasguillot marked this pull request as ready for review November 27, 2026 16:27
@thomasguillot
thomasguillot merged commit 19530f4 into trunk Nov 27, 2026
6 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Hey @thomasguillot, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

@thomasguillot
thomasguillot deleted the feat/follow-alerts-button branch November 27, 2026 16:27
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.

Make the Follow button clearer and keep its width steady

1 participant