Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public function project(
if ( 'core/group' === $name && $facts->isAuthorLayoutItem ) {
$attrs['className'] = SourceDom::mergeClassNames((string) ($attrs['className'] ?? ''), self::CSS_OWNED_LAYOUT_ITEM_CLASS);
}
if ( in_array($name, array( 'core/group', 'core/paragraph' ), true) && self::isHiddenAccessibilitySupportElement($sourceElement) ) {
$attrs['className'] = SourceDom::mergeClassNames((string) ($attrs['className'] ?? ''), self::HIDDEN_RICH_TEXT_MARKER_CLASS);
}
if ( 'core/group' === $name && $this->isAtomicInlineChildFlow($sourceElement, $innerBlocks) ) {
$attrs['className'] = SourceDom::mergeClassNames((string) ($attrs['className'] ?? ''), self::CSS_OWNED_INLINE_FLOW_CLASS);
}
Expand Down Expand Up @@ -90,6 +93,17 @@ public function project(
return $attrs;
}

private static function isHiddenAccessibilitySupportElement(DOMElement $element): bool
{
$identity = strtolower(SourceDom::attr($element, 'id') . ' ' . SourceDom::attr($element, 'class'));
if ( 1 !== preg_match('/(?:a11y|accessib|screen[-_]?reader|sr[-_]?only|visually[-_]?hidden)/', $identity) ) {
return false;
}

$style = strtolower(SourceDom::attr($element, 'style'));
return 1 === preg_match('/(?:^|;)\s*(?:display\s*:\s*none|visibility\s*:\s*hidden)\s*(?:!important)?\s*(?:;|$)/', $style);
}

public function sourceProjectionClassName(DOMElement $element, SourceBlockAttributeProjectionContext $context, string $className = ''): string
{
$sourceTagMarker = $context->selectorProjections->tagMarker(strtolower($element->tagName));
Expand Down
17 changes: 17 additions & 0 deletions php-transformer/tests/unit/inert-closed-state-interactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,23 @@
$boundaryMarkerAfterAuthor
);

$hiddenNavigationSupport = <<<'HTML'
<wix-dropdown-menu>
<nav><ul><li><a href="/">Home</a></li></ul><div id="menu-hiddenA11ySubMenuIndication" style="display:none">Use tab to navigate through the menu items.</div></nav>
</wix-dropdown-menu>
HTML;

$hiddenNavigationSupportResult = ( new HtmlTransformer() )->transform($hiddenNavigationSupport)->toArray();
$hiddenNavigationSupportMarkup = (string) ($hiddenNavigationSupportResult['serialized_blocks'] ?? '');
$hiddenNavigationSupportBeforeAuthor = $cssContent($hiddenNavigationSupportResult, 'before-author', 'both');
$assert(
str_contains($hiddenNavigationSupportMarkup, 'Use tab to navigate through the menu items.')
&& str_contains($hiddenNavigationSupportMarkup, 'blocks-engine-hidden-richtext-marker')
&& str_contains($hiddenNavigationSupportBeforeAuthor, ':where(.blocks-engine-hidden-richtext-marker){display:none}'),
'an explicitly hidden navigation accessibility support group retains its hidden state',
$hiddenNavigationSupportMarkup . "\n" . $hiddenNavigationSupportBeforeAuthor
);

if ( $failures > 0 ) {
fwrite(STDERR, "inert closed-state interactions: {$failures} failed, {$passes} passed\n");
exit(1);
Expand Down
Loading