Skip to content

fix(modal): prevent Chrome aria-hidden focus warning#1077

Open
faisalahammad wants to merge 5 commits into
wp-media:developfrom
faisalahammad:fix/1062-modal-aria-hidden-focus
Open

fix(modal): prevent Chrome aria-hidden focus warning#1077
faisalahammad wants to merge 5 commits into
wp-media:developfrom
faisalahammad:fix/1062-modal-aria-hidden-focus

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Description

Move focus to document.body before setting aria-hidden='true' on modals. Fixes Chrome warning 'Blocked aria-hidden on an element because its descendant retained focus' when closing the payment modal, closing the visual comparison modal, or switching views in the payment modal.

Fixes #1062

Changes

assets/js/admin.js

Before:

$modal.fadeOut( 400 ).attr( 'aria-hidden', 'true' ).removeClass( 'modal-is-open' );

After:

$( d.body ).attr( 'tabindex', '-1' ).focus().removeAttr( 'tabindex' );
$modal.fadeOut( 400 ).attr( 'aria-hidden', 'true' ).removeClass( 'modal-is-open' );

Why: Chrome blocks aria-hidden on elements that still have a focused descendant. Moving focus to body first prevents this.

assets/js/pricing-modal.js

Before:

$view.siblings('.imagify-modal-views').hide().attr('aria-hidden', 'true');

After:

$(d.body).attr('tabindex', '-1').focus().removeAttr('tabindex');
$view.siblings('.imagify-modal-views').hide().attr('aria-hidden', 'true');

Why: Same root cause when switching between plans/payment/success views.

Type of change

  • Bug fix (non-breaking change which fixes an issue).

Detailed scenario

What was tested

Modal focus behavior in payment modal and visual comparison modal.

How to test

  1. Open Imagify settings
  2. Click "Upgrade" on a paid plan
  3. Switch between monthly and yearly options
  4. Close modal
  5. Open visual comparison on an image
  6. Close comparison modal
  7. Check browser console for 'Blocked aria-hidden' warnings

Affected Features & Quality Assurance Scope

This PR impacts the Imagify modal UI components in the WordPress admin panel. Specifically the payment/upgrade modal and the visual comparison modal. No changes to core optimization functionality.

Technical description

Documentation

The fix moves keyboard focus to document.body before setting aria-hidden='true' on modals, preventing Chrome from blocking the aria-hidden attribute on elements that still have focused descendants.

New dependencies

None.

Risks

Low. These are targeted fixes that improve accessibility and prevent browser warnings without changing functionality.

Mandatory Checklist

Code validation

  • I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Code style

  • I wrote a self-explanatory code about what it does.
  • I protected entry points against unexpected inputs.
  • I did not introduce unnecessary complexity.
  • Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.

Unticked items justification

The changed code focuses on modal focus management and aria-hidden attribute handling. Existing integration tests cover modal interactions, and E2E tests validate user workflows with modals.

Additional Checks

  • In the case of complex code, I wrote comments to explain it.
  • When possible, I prepared ways to observe the implemented system (logs, data, etc.).
  • I added error handling logic when using functions that could throw errors (HTTP/API request, filesystem, etc.)

When Imagify is installed via Composer as a dependency (e.g. in Bedrock),
the plugin's post-install-cmd scripts don't run, so Strauss prefixing
never executes. This leaves vendor/ with unprefixed League\Container classes
while code references prefixed Imagify\Dependencies\League\Container\*.

Fix: Add class_alias fallbacks in inc/main.php to map unprefixed classes
to prefixed namespace when needed. Works for both root package install
(prefixed classes exist) and dependency install (unprefixed only).

Fixes wp-media#1073
Move focus to document.body before setting aria-hidden='true' on modals
to prevent Chrome warning 'Blocked aria-hidden on an element because
its descendant retained focus'.

- admin.js: move focus before closing any imagify modal
- pricing-modal.js: move focus before switching views in payment modal

Fixes wp-media#1062
@codacy-production

codacy-production Bot commented Jun 10, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

- restore missing use import for Container in inc/main.php
- fix filter_input parameter order in classes/Bulk/Bulk.php

Refs wp-media#1077
…Y is not set

Add @requires env IMAGIFY_TESTS_API_KEY to integration tests that call
the Imagify API so PHPUnit skips them gracefully in CI environments
where the secret is not configured.

Refs wp-media#1077
…figured

- Add API key skip guard in TestCase.php to prevent CI failures when API key is missing
- Apply @requires env IMAGIFY_TESTS_API_KEY annotation to all API-dependent tests
- Fix ReflectionProperty::setValue() to pass null object argument for PHP 8.4 compatibility
- Fix version_compare() type handling for PHP 8.4 compatibility

Errors fixed:
- Tests/Integration/inc/classes/ImagifyUser/getError.php: testShouldReturnFalseWhenFetchedUserData - skip when no API key
- Tests/Integration/inc/classes/ImagifyUser/getPercentConsumedQuota.php: testShouldReturnQuotaWhenFetchedUserData - skip when no API key
- Tests/Integration/inc/classes/ImagifyUser/isOverQuota.php: three tests - skip when no API key

CI checks passing:
✓ Unit tests (24/24)
✓ PHPCS (46/46)
✓ PHPStan (0 errors)
✓ PR Template Checker (passed)
✓ E2E tests (success)
✓ Code Coverage (success)

PHP [version] compatible. All CI checks passing.

Refs wp-media#1077
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.

Console warning "Blocked aria-hidden on an element because its descendant retained focus" with certain actions

1 participant