{%
set summary_classes = [
@@ -33,7 +46,18 @@
{% endif %}
- {{ description }}
+ {% if description_display == 'before' and description.content %}
+
+ {{ description.content }}
+
+ {% endif %}
+
{{ children }}
{{ value }}
+
+ {% if description_display in ['after', 'invisible'] and description.content %}
+
+ {{ description.content }}
+
+ {% endif %}
diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestDescriptionForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestDescriptionForm.php
index 81120ad..bb8286b 100644
--- a/core/modules/system/tests/modules/form_test/src/Form/FormTestDescriptionForm.php
+++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestDescriptionForm.php
@@ -23,6 +23,12 @@ public function getFormId() {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
+ $form['form_textfield_test_description_default'] = [
+ '#type' => 'textfield',
+ '#title' => 'Textfield test for description default after element',
+ '#description' => 'Textfield test for description default after element',
+ ];
+
$form['form_textfield_test_description_before'] = [
'#type' => 'textfield',
'#title' => 'Textfield test for description before element',
diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestGroupDetailsForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestGroupDetailsForm.php
index 002b07d..304edf4 100644
--- a/core/modules/system/tests/modules/form_test/src/Form/FormTestGroupDetailsForm.php
+++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestGroupDetailsForm.php
@@ -30,6 +30,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $required
$form['meta'] = [
'#type' => 'details',
'#title' => 'Group element',
+ '#description' => 'Details test for default description position.',
'#open' => TRUE,
'#group' => 'details',
];
@@ -37,6 +38,55 @@ public function buildForm(array $form, FormStateInterface $form_state, $required
'#type' => 'textfield',
'#title' => 'Nest in details element',
];
+
+ $form['details_before'] = [
+ '#type' => 'details',
+ '#title' => 'Details test for description before element',
+ '#description' => 'Details test for description before element.',
+ '#description_display' => 'before',
+ ];
+ $form['meta_before'] = [
+ '#type' => 'container',
+ '#title' => 'Group element',
+ '#group' => 'details_before',
+ ];
+ $form['meta_before']['element'] = [
+ '#type' => 'textfield',
+ '#title' => 'Nest in container element',
+ ];
+
+ $form['details_after'] = [
+ '#type' => 'details',
+ '#title' => 'Details test for description after element',
+ '#description' => 'Details test for description after element.',
+ '#description_display' => 'after',
+ ];
+ $form['meta_after'] = [
+ '#type' => 'container',
+ '#title' => 'Group element',
+ '#group' => 'details_after',
+ ];
+ $form['meta_after']['element'] = [
+ '#type' => 'textfield',
+ '#title' => 'Nest in container element',
+ ];
+
+ $form['details_invisible'] = [
+ '#type' => 'details',
+ '#title' => 'Details test for visually-hidden description',
+ '#description' => 'Details test for visually-hidden description.',
+ '#description_display' => 'invisible',
+ ];
+ $form['meta_invisible'] = [
+ '#type' => 'container',
+ '#title' => 'Group element',
+ '#group' => 'details_invisible',
+ ];
+ $form['meta_invisible']['element'] = [
+ '#type' => 'textfield',
+ '#title' => 'Nest in container element',
+ ];
+
return $form;
}
diff --git a/core/themes/classy/templates/form/details.html.twig b/core/themes/classy/templates/form/details.html.twig
index 24366c3..2a9669b 100644
--- a/core/themes/classy/templates/form/details.html.twig
+++ b/core/themes/classy/templates/form/details.html.twig
@@ -8,12 +8,25 @@
* - errors: (optional) Any errors for this details element, may not be set.
* - title: (optional) The title of the element, may not be set.
* - description: (optional) The description of the element, may not be set.
+ * - description_display: (optional) Description display setting. It can have
+ * these values:
+ * - before: The description is output before the element. This is the default
+ * value.
+ * - after: The description is output after the element.
+ * - invisible: The description is output after the element, hidden visually
+ * but available to screen readers.
* - children: (optional) The children of the element, may not be set.
* - value: (optional) The value of the element, may not be set.
*
* @see template_preprocess_details()
*/
#}
+{%
+ set description_classes = [
+ 'description',
+ description_display == 'invisible' ? 'visually-hidden',
+ ]
+%}