From 03c129d0b3272eca16c4c48133c2580a288feced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kry=C5=A1p=C3=ADn?= Date: Tue, 11 Jun 2024 17:56:00 +0200 Subject: [PATCH] Fix(web-twig): Make ValidationText and HelperText ID optional #DS-1336 Set aria-describedby to form elements when helperText or validationText set. --- .../components/Checkbox/Checkbox.twig | 20 ++++++++++------ .../checkboxDefault.twig.snap.html | 6 +++-- .../checkboxDefaultPure.twig.snap.html | 3 +-- .../__snapshots__/checkboxItem.twig.snap.html | 2 +- .../components/Field/HelperText.twig | 2 +- .../components/Field/ValidationText.twig | 2 +- .../__tests__/__fixtures__/helperText.twig | 3 +-- .../__fixtures__/validationText.twig | 5 +--- .../__snapshots__/helperText.twig.snap.html | 2 +- .../validationText.twig.snap.html | 4 ++-- .../components/FieldGroup/FieldGroup.twig | 6 ++--- .../__snapshots__/fieldGroup.twig.snap.html | 12 +++++----- .../FileUploader/FileUploaderInput.twig | 20 ++++++++++------ .../fileUploaderInput.twig.snap.html | 14 +++++------ .../src/Resources/components/Item/Item.twig | 10 ++++---- .../src/Resources/components/Radio/Radio.twig | 18 ++++++++------ .../Resources/components/Select/Select.twig | 14 +++++++---- .../selectHelperText.twig.snap.html | 4 ++-- .../selectValidationState.twig.snap.html | 12 +++++----- .../textAreaDefault.twig.snap.html | 4 ++-- .../textAreaWithAutoResize.twig.snap.html | 4 ++-- .../textAreaWithHelperText.twig.snap.html | 4 ++-- ...extAreaWithMultilineMessage.twig.snap.html | 4 ++-- .../passwordFieldDefault.twig.snap.html | 4 ++-- .../textFieldDefault.twig.snap.html | 4 ++-- .../textFieldDefaultPure.twig.snap.html | 4 ++-- .../textFieldWithHelperText.twig.snap.html | 4 ++-- ...xtFieldWithMultilineMessage.twig.snap.html | 4 ++-- .../textFieldWithUnsafe.twig.snap.html | 6 ++--- .../TextFieldBase/TextFieldBase.twig | 24 +++++++++++++------ .../textFieldBaseDefault.twig.snap.html | 4 ++-- .../textFieldBaseMultiline.twig.snap.html | 4 ++-- 32 files changed, 131 insertions(+), 102 deletions(-) diff --git a/packages/web-twig/src/Resources/components/Checkbox/Checkbox.twig b/packages/web-twig/src/Resources/components/Checkbox/Checkbox.twig index 15b7c12aaa..d4874283b9 100644 --- a/packages/web-twig/src/Resources/components/Checkbox/Checkbox.twig +++ b/packages/web-twig/src/Resources/components/Checkbox/Checkbox.twig @@ -30,19 +30,22 @@ {%- set _helperTextClassName = _spiritClassPrefix ~ 'Checkbox__helperText' -%} {%- set _validationTextClassName = _spiritClassPrefix ~ 'Checkbox__validationText' -%} -{# Attributes #} -{%- set _checkedAttr = _isChecked ? 'checked' : null -%} -{%- set _disabledAttr = _isDisabled ? 'disabled' : null -%} -{%- set _nameAttr = _name ? 'name="' ~ _name | escape('html_attr') ~ '"' : null -%} -{%- set _requiredAttr = _isRequired ? 'required' : null -%} -{%- set _valueAttr = _value ? 'value=' ~ _value : null -%} - {# Miscellaneous #} {%- set _styleProps = useStyleProps(props) -%} {%- set _classNames = [ _rootClassName, _rootDisabledClassName, _rootItemClassName, _rootValidationStateClassName, _styleProps.className ] -%} +{%- set _helperTextId = _helperText or _unsafeHelperText ? _id ~ '-helper-text' : null -%} {%- set _labelClassName = [ _labelClassName, _labelHiddenClassName, _labelRequiredClassName ] -%} {%- set _mainPropsWithoutId = props | filter((value, prop) => prop is not same as('id')) -%} {%- set _allowedInputAttributes = [ 'autocomplete' ] -%} +{%- set _validationTextId = _validationText or _unsafeValidationText ? _id ~ '-validation-text' : null -%} + +{# Attributes #} +{%- set _ariaDescribedByAttr = _helperTextId or _validationTextId ? 'aria-describedby="' ~ [ _helperTextId, _validationTextId ] | join (' ') | trim ~ '"' : null -%} +{%- set _checkedAttr = _isChecked ? 'checked' : null -%} +{%- set _disabledAttr = _isDisabled ? 'disabled' : null -%} +{%- set _nameAttr = _name ? 'name="' ~ _name | escape('html_attr') ~ '"' : null -%} +{%- set _requiredAttr = _isRequired ? 'required' : null -%} +{%- set _valueAttr = _value ? 'value=' ~ _value : null -%}