Announce settings save status to screen readers - #1851
Conversation
📝 WalkthroughWalkthroughThe settings page now renders saved-status notices, conditionally loads ChangesSettings save status
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant SettingsPage
participant AdminApp
participant AnnounceSettingsSaveStatus
participant WpA11y
SettingsPage->>AdminApp: Render settings notice and initialize
AdminApp->>AnnounceSettingsSaveStatus: Pass window.wp?.a11y
AnnounceSettingsSaveStatus->>WpA11y: Speak notice message with politeness
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
29edf88 to
81c93ac
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/phpunit/partials/SettingsPagePartialTest.php`:
- Line 41: Update tests/phpunit/partials/SettingsPagePartialTest.php at lines
41-41 by renaming the test method to test_partial_renders_settings_saved_notice
and adding a : void return type. Update tests/phpunit/Admin/EnqueueAdminTest.php
at lines 106-106 by renaming the test method to
test_enqueue_base_script_with_wp_a11y_on_settings_page and adding a : void
return type, preserving each test’s existing behavior.
- Line 13: Move SettingsPagePartialTest into the
EqualizeDigital\AccessibilityChecker\Tests\Partials namespace and add the
corresponding PSR-4 mapping for tests/phpunit/ in composer.json or the PHPUnit
bootstrap/autoload configuration, ensuring the test remains discoverable and
runnable.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 729ea44f-a921-401a-8e60-8bc88e122e04
📒 Files selected for processing (7)
admin/class-enqueue-admin.phppartials/settings-page.phpsrc/admin/index.jssrc/admin/settings/announce-settings-save-status.jstests/jest/admin/announce-settings-save-status.test.jstests/phpunit/Admin/EnqueueAdminTest.phptests/phpunit/partials/SettingsPagePartialTest.php
| $admin_script_dependencies = [ 'jquery' ]; | ||
| if ( 'accessibility_checker_settings' === $page ) { | ||
| $admin_script_dependencies[] = 'wp-a11y'; | ||
| } | ||
|
|
||
| wp_enqueue_script( 'edac', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/admin.bundle.js', $admin_script_dependencies, EDAC_VERSION, false ); |
There was a problem hiding this comment.
It's probably worth just putting this in the deps array everywhere rather than just conditionally on the one page.
| $admin_script_dependencies = [ 'jquery' ]; | |
| if ( 'accessibility_checker_settings' === $page ) { | |
| $admin_script_dependencies[] = 'wp-a11y'; | |
| } | |
| wp_enqueue_script( 'edac', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/admin.bundle.js', $admin_script_dependencies, EDAC_VERSION, false ); | |
| wp_enqueue_script( 'edac', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/admin.bundle.js', [ 'jquery', 'wp-a11y' ], EDAC_VERSION, false ); |
There was a problem hiding this comment.
Updated as suggested: edac now includes wp-a11y on every admin page, and the non-settings regression test was updated. PHPUnit passes with 27 tests and 56 assertions, along with PHPCS.
Summary
Fixes #1757.
wp.a11y.speak, using polite output for success and assertive output for errors.wp-a11yas a dependency of the admin bundle.Root cause
The settings form submits through WordPress's Settings API, which stores the standard result notice, but the custom settings page did not call
settings_errors(). The page therefore refreshed without showing or announcing the save result.The settings page now renders the standard visible notice immediately after its heading. On DOM ready, the admin bundle detects the notice and schedules the announcement for one second after the page finishes loading. This prevents the polite status from being lost among the screen reader's page-load announcements and does not move keyboard focus.
Validation
npm run buildgit diff --checkChecklist