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 @@ -27,8 +27,10 @@
class GlyphRendererFactory extends Render\DefaultRendererFactory
{
/**
* components which render glyphs inside an HTML <button> element, where only
* palpable content is allowed.
* components which render glyphs inside an HTML <button> element (or equivalent),
* where only palpable content is allowed (no <a>).
* Any glyph rendered anywhere within these components' subtree will use the
* ButtonContextRenderer.
* @see https://html.spec.whatwg.org/#palpable-content
*/
protected const array USE_BUTTON_CONTEXT_RENDERER_FOR = [
Expand All @@ -45,9 +47,24 @@ class GlyphRendererFactory extends Render\DefaultRendererFactory
'RadioFieldInput',
];

/**
* Components that render glyphs inside an HTML <button> element themselves
* but also contain child components whose glyphs should NOT use the
* ButtonContextRenderer. Only glyphs that are direct children of these
* components (i.e. these components are the immediate parent context) will
* use the ButtonContextRenderer. This prevents false-positives for glyphs
* in nested child components.
*/
protected const array USE_BUTTON_CONTEXT_RENDERER_FOR_DIRECT_CONTEXT = [
'StandardFilterContainerInput',
];

public function getRendererInContext(Component\Component $component, array $contexts): ComponentRenderer
{
if (count(array_intersect(self::USE_BUTTON_CONTEXT_RENDERER_FOR, $contexts)) > 0) {
if (
$this->isDirectContextMatch($contexts) ||
count(array_intersect(self::USE_BUTTON_CONTEXT_RENDERER_FOR, $contexts)) > 0
) {
return new ButtonContextRenderer(
$this->ui_factory,
$this->tpl_factory,
Expand All @@ -70,4 +87,22 @@ public function getRendererInContext(Component\Component $component, array $cont
$this->upload_limit_resolver
);
}

/**
* Checks whether the immediate parent context (the component that directly
* renders this glyph) matches one of the DIRECT_CONTEXT components.
* The context array has the current component (glyph) as the last element,
* so the immediate parent is the second-to-last element.
*
* @param string[] $contexts
*/
private function isDirectContextMatch(array $contexts): bool
{
$count = count($contexts);
if ($count < 2) {
return false;
}
$immediate_parent = $contexts[$count - 2];
return in_array($immediate_parent, self::USE_BUTTON_CONTEXT_RENDERER_FOR_DIRECT_CONTEXT, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ public function testRenderActivatedCollapsed(): void
<button type="button" aria-expanded="false" aria-controls="active_inputs_id_1 section_inputs_id_1" id="opener_id_1">
<span>
<span data-collapse-glyph-visibility="0">
<a class="glyph" aria-label="collapse_content">
<span class="glyph" aria-label="collapse_content" role="img">
<span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
</a>
</span>
</span>
<span data-expand-glyph-visibility="1">
<a class="glyph" aria-label="expand_content">
<span class="glyph" aria-label="expand_content" role="img">
<span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span>
</a>
</span>
</span> filter
</span>
</button>
Expand Down Expand Up @@ -322,14 +322,14 @@ public function testRenderDeactivatedCollapsed(): void
<button type="button" aria-expanded="false" aria-controls="active_inputs_id_1 section_inputs_id_1" id="opener_id_1">
<span>
<span data-collapse-glyph-visibility="0">
<a class="glyph" aria-label="collapse_content">
<span class="glyph" aria-label="collapse_content" role="img">
<span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
</a>
</span>
</span>
<span data-expand-glyph-visibility="1">
<a class="glyph" aria-label="expand_content">
<span class="glyph" aria-label="expand_content" role="img">
<span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span>
</a>
</span>
</span> filter
</span>
</button>
Expand Down Expand Up @@ -460,14 +460,14 @@ public function testRenderActivatedExpanded(): void
<button type="button" aria-expanded="true" aria-controls="active_inputs_id_1 section_inputs_id_1" id="opener_id_1">
<span>
<span data-collapse-glyph-visibility="1">
<a class="glyph" aria-label="collapse_content">
<span class="glyph" aria-label="collapse_content" role="img">
<span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
</a>
</span>
</span>
<span data-expand-glyph-visibility="0">
<a class="glyph" aria-label="expand_content">
<span class="glyph" aria-label="expand_content" role="img">
<span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span>
</a>
</span>
</span> filter
</span>
</button>
Expand Down Expand Up @@ -598,14 +598,14 @@ public function testRenderDeactivatedExpanded(): void
<button type="button" aria-expanded="true" aria-controls="active_inputs_id_1 section_inputs_id_1" id="opener_id_1">
<span>
<span data-collapse-glyph-visibility="1">
<a class="glyph" aria-label="collapse_content">
<span class="glyph" aria-label="collapse_content" role="img">
<span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
</a>
</span>
</span>
<span data-expand-glyph-visibility="0">
<a class="glyph" aria-label="expand_content">
<span class="glyph" aria-label="expand_content" role="img">
<span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span>
</a>
</span>
</span> filter
</span>
</button>
Expand Down