Skip to content

Commit

Permalink
Tiled Gallery: Accessibility - when images are not interactive, remov…
Browse files Browse the repository at this point in the history
…e button role and tabindex. (#40241)
  • Loading branch information
coder-karen authored Nov 26, 2024
1 parent 63a223a commit f55374c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: compat

Tiled Gallery: Increase accessibility by ensuring images are not classified as interactive when they shouldn't be.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Automattic\Jetpack\Blocks;
use Automattic\Jetpack\Current_Plan as Jetpack_Plan;
use Automattic\Jetpack\Status;
use Automattic\Jetpack\Status\Host;
use Jetpack;
use Jetpack_Gutenberg;

Expand Down Expand Up @@ -150,6 +151,9 @@ public static function render( $attr, $content ) {
}
}

// Apply non-interactive markup last to clean up interactivity attributes.
$content = self::non_interactive_markup( $attr, $content );

/**
* Filter the output of the Tiled Galleries content.
*
Expand All @@ -162,6 +166,31 @@ public static function render( $attr, $content ) {
return apply_filters( 'jetpack_tiled_galleries_block_content', $content );
}

/**
* Removes tabindex and role markup for images that should not be interactive.
*
* @param array $attr Attributes key/value array.
* @param string $content String containing the block content.
*/
private static function non_interactive_markup( $attr, $content ) {
$link_to = $attr['linkTo'] ?? 'none';

$host = new Host();
$is_module_active = $host->is_wpcom_simple()
? get_option( 'carousel_enable_it' )
: Jetpack::is_module_active( 'carousel' );

if ( $link_to === 'none' && ! $is_module_active ) {
// Remove tabIndex and role="button" by replacing the content
$content = preg_replace(
'/\s*(role="button"|tabindex="0")/',
'',
$content
);
}
return $content;
}

/**
* Determines whether a Tiled Gallery block uses square or circle images (1:1 ratio)
*
Expand Down

0 comments on commit f55374c

Please sign in to comment.