Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hash handling to site health infos accordions #8184

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/js/_enqueues/admin/site-health.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ jQuery( function( $ ) {
$( '.health-check-accordion' ).on( 'click', '.health-check-accordion-trigger', function() {
var isExpanded = ( 'true' === $( this ).attr( 'aria-expanded' ) );

window.location.hash = $( this ).attr( 'id' );

if ( isExpanded ) {
$( this ).attr( 'aria-expanded', 'false' );
$( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', true );
Expand All @@ -53,8 +55,19 @@ jQuery( function( $ ) {
}
} );

// Site Health test handling.
// Get hash from query string and open the related accordion.
$( window ).on( 'load', function() {
var hash = window.location.hash;
if ( hash ) {
var requestedPanel = $( hash );
if ( requestedPanel.length ) {
$( requestedPanel ).attr( 'aria-expanded', 'true' );

Choose a reason for hiding this comment

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

requestedPanel is already a jQuery object, so wrapping it again with $() is unnecessary.

$( '#' + requestedPanel.attr( 'aria-controls' ) ).attr( 'hidden', false );
}
}
} );

// Site Health test handling.
$( '.site-health-view-passed' ).on( 'click', function() {
var goodIssuesWrapper = $( '#health-check-issues-good' );

Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/site-health-info.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

?>
<h3 class="health-check-accordion-heading">
<button aria-expanded="false" class="health-check-accordion-trigger" aria-controls="health-check-accordion-block-<?php echo esc_attr( $section ); ?>" type="button">
<button id="health-check-section-<?php echo esc_attr( $section ); ?>" aria-expanded="false" class="health-check-accordion-trigger" aria-controls="health-check-accordion-block-<?php echo esc_attr( $section ); ?>" type="button">
<span class="title">
<?php echo esc_html( $details['label'] ); ?>
<?php
Expand Down
Loading