Skip to content

[Simple Analytics] Accessibility#214

Open
alaca wants to merge 1 commit into
feature/simple-analyticsfrom
feature/208-accessibility
Open

[Simple Analytics] Accessibility#214
alaca wants to merge 1 commit into
feature/simple-analyticsfrom
feature/208-accessibility

Conversation

@alaca
Copy link
Copy Markdown
Collaborator

@alaca alaca commented May 13, 2026

Description of the Change

Closes #208

How to test the Change

Run Lighthouse Accessibility audit in DevTools. Expect score 100.
Tab through the page. Every control shows a 2px teal ring.
Open date popover. Press Esc. Popover closes, focus returns to trigger.
DevTools Rendering panel, toggle prefers-reduced-motion: reduce. Charts snap, no animation, skeleton pulse frozen.
DevTools Elements, find #mailchimp-sf-fp-data-table and #mailchimp-sf-sa-data-table. Each contains a real table with chart data.

Changelog Entry

Switched all :focus to :focus-visible and bumped the ring from 1px to 2px.
Added a global focus ring rule for every button on the analytics page.
Darkened the chart Submissions color from #2DD4BF to #0E9384.
Darkened the Conversion Rate line color from #EAB308 to #A88008.
Updated the legend chip fill to match the new Submissions teal.
Added PREFERS_REDUCED_MOTION check that disables Chart.js animations.
Added a local screen-reader-text utility class.
Replaced the muted state opacity trick with #6b7280 so the text passes WCAG 4.5:1.
Added a screen reader data table for each chart.
Wired both canvases to their tables via aria-describedby.
Replaced the bare Date range with a span and gave the trigger button proper aria-labelledby.
Added aria-haspopup="dialog" on the trigger.
Made the popover a real role="dialog" with aria-labelledby.
Added an Escape key handler that closes the popover and returns focus to the trigger.

Credits

Props @alaca

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@github-actions github-actions Bot added this to the 2.1.0 milestone May 13, 2026
@github-actions github-actions Bot added the needs:feedback This requires reporter feedback to better understand the request. label May 13, 2026
@github-actions
Copy link
Copy Markdown

@alaca thanks for the PR! Could you please fill out the PR template with description, changelog, and credits information so that we can properly review and merge this?

@alaca alaca changed the base branch from develop to feature/simple-analytics May 13, 2026 14:17
@alaca alaca requested a review from iamdharmesh May 13, 2026 14:28
@iamdharmesh iamdharmesh requested a review from Copilot May 14, 2026 09:52
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds accessibility improvements to the Simple Analytics admin page, focusing on keyboard interaction, chart alternatives, reduced motion, and contrast.

Changes:

  • Updates date range controls with ARIA labeling, dialog semantics, and Escape handling.
  • Adds reduced-motion Chart.js configuration and screen-reader chart data tables.
  • Adjusts focus indicators, chart colors, and muted-state contrast.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
includes/admin/templates/analytics.php Adds ARIA attributes and hidden data-table containers for analytics charts.
assets/js/analytics.js Adds reduced-motion handling, Escape popover behavior, chart color updates, and dynamic data-table rendering.
assets/css/analytics.scss Adds screen-reader utility styles, updated focus-visible rings, contrast tweaks, and reduced-motion CSS.
Comments suppressed due to low confidence (4)

assets/js/analytics.js:1353

  • The screen-reader table is only populated on the ready path and is never cleared by the loading, empty, or error paths. After a successful load, changing filters to an empty range or failed request leaves stale rows in the element referenced by aria-describedby, so assistive technology can still receive the previous chart data.
			renderDataTable(rows, fromLabel, toLabel);

assets/js/analytics.js:531

  • The new screen-reader table rendering is not covered by the existing analytics Cypress success-state tests. Those tests already stub chart payloads, so they should assert that the aria-describedby target contains a table with the expected row data after a successful response.
		function renderDataTable(rows, fromLabel, toLabel) {

assets/js/analytics.js:1044

  • The new screen-reader table rendering is not covered by the existing analytics Cypress success-state tests. Those tests already stub chart payloads, so they should assert that the aria-describedby target contains a table with the expected row data after a successful response.
		function renderDataTable(rows, fromLabel, toLabel) {

includes/admin/templates/analytics.php:380

  • The chart still exposes tooltip details only through Chart.js pointer interactions: the canvas is not focusable and there are no keyboard handlers for moving between data points. The hidden table helps screen-reader users, but sighted keyboard users still cannot access the per-bucket tooltip values required for keyboard-accessible chart tooltips.
									class="mailchimp-sf-sa__canvas"
									role="img"
									aria-label="<?php esc_attr_e( 'Subscriber change bar chart', 'mailchimp' ); ?>"
									aria-describedby="mailchimp-sf-sa-data-table"
								></canvas>

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread assets/js/analytics.js
setOverlay('');
setState('ready');
renderChart(rows);
renderDataTable(rows, fromLabel, toLabel);
Comment on lines +388 to +390
<div
id="mailchimp-sf-sa-data-table"
class="mailchimp-sf-sa__data-table screen-reader-text"
Comment thread assets/css/analytics.scss
Comment on lines +45 to +48
.mailchimp_page_mailchimp_sf_analytics .mailchimp-sf-button:focus-visible,
.mailchimp_page_mailchimp_sf_analytics button:focus-visible {
box-shadow: 0 0 0 2px var(--mailchimp-color-link, #017e89);
outline: none;
Comment on lines 279 to 283
class="mailchimp-sf-fp__canvas"
role="img"
aria-label="<?php esc_attr_e( 'Form views, submissions, and conversion rate chart', 'mailchimp' ); ?>"
aria-describedby="mailchimp-sf-fp-data-table"
></canvas>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@alaca Could you please check if this is feasible?

Comment thread assets/js/analytics.js
Comment on lines +445 to +448
closePopover();
if (trigger) {
trigger.focus();
}
Copy link
Copy Markdown
Collaborator

@iamdharmesh iamdharmesh left a comment

Choose a reason for hiding this comment

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

Thanks @alaca. Over all this looks good. Could you please check on the feedback from copilot, specifically for keyboard-navigable tooltips? Thank you.

Comment thread assets/css/analytics.scss
// while keeping it readable by assistive tech. Defined locally so the
// styles still apply if WP core's stylesheet load order changes.
// -----------------------------------------------------------------------------
.screen-reader-text {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we scope this to make sure it only apply to screen reader text added by us?

Something like .mailchimp_page_mailchimp_sf_analytics .screen-reader-text

Comment on lines 279 to 283
class="mailchimp-sf-fp__canvas"
role="img"
aria-label="<?php esc_attr_e( 'Form views, submissions, and conversion rate chart', 'mailchimp' ); ?>"
aria-describedby="mailchimp-sf-fp-data-table"
></canvas>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@alaca Could you please check if this is feasible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:feedback This requires reporter feedback to better understand the request.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Simple Analytics] Accessibility

3 participants