Skip to content

Commit

Permalink
Rework fieldset/legend markup to fix duplicate actions button issue, …
Browse files Browse the repository at this point in the history
…and to use ARIA
  • Loading branch information
Lupe Camacho authored and Lupe Camacho committed Jan 13, 2025
1 parent dcee869 commit 2d294e8
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/helpers/Cp.php
Original file line number Diff line number Diff line change
Expand Up @@ -1541,27 +1541,21 @@ public static function fieldHtml(string|callable $input, array $config = []): st
$labelHtml = '';
}

$containerTag = $fieldset ? 'fieldset' : 'div';

return
Html::beginTag($containerTag, ArrayHelper::merge(
Html::beginTag('div', ArrayHelper::merge(
[
'class' => $fieldClass,
'id' => $fieldId,
'aria' => [
'labelledby' => $fieldset ? $labelId : null,
],
'role' => $fieldset ? 'group' : null,
'data' => [
'attribute' => $attribute,
] + $data,
'attribute' => $attribute,
] + $data,
],
$config['fieldAttributes'] ?? []
)) .
(($label && $fieldset)
? Html::tag('legend', $labelHtml, [
'class' => ['visually-hidden'],
'data' => [
'label' => $label,
],
])
: '') .
($status
? Html::beginTag('div', [
'id' => $statusId,
Expand All @@ -1583,9 +1577,6 @@ public static function fieldHtml(string|callable $input, array $config = []): st
'id' => $labelId,
'class' => $config['labelClass'] ?? null,
'for' => !$fieldset ? $id : null,
'aria' => [
'hidden' => $fieldset ? 'true' : null,
],
], $config['labelAttributes'] ?? []))
: '') .
(isset($config['labelExtra'])
Expand Down Expand Up @@ -1616,7 +1607,7 @@ public static function fieldHtml(string|callable $input, array $config = []): st
'errors' => $errors,
])
: '') .
Html::endTag($containerTag);
Html::endTag('div');
}

/**
Expand Down

0 comments on commit 2d294e8

Please sign in to comment.