From 1cd29d8315fa41121a9956c66605c3a588ef09f9 Mon Sep 17 00:00:00 2001 From: Douglas Bouttell <155977861+douglasbouttell-camunda@users.noreply.github.com> Date: Thu, 15 Feb 2024 11:36:38 +0000 Subject: [PATCH] feat(a11y): fields announce their descriptions and labels properly (#1043) * Include all description blocks in `aria-describedby`. * Add `required` property to inputs that can be required. * Add `aria-invalid` property to input which have validation errors. * Do not announce the asterisk/star which denotes a required field. * Have components generate their own error ID. * Remove confusing use of `id` in Label. It now has an `id` and an `htmlFor` prop. * Update groups `aria-labelledby` to point to an actual label. --- .../src/render/components/Description.js | 4 ++-- .../src/render/components/FormField.js | 2 -- .../form-js-viewer/src/render/components/Label.js | 8 +++++--- .../src/render/components/form-fields/Checkbox.js | 14 +++++++++----- .../src/render/components/form-fields/Checklist.js | 14 +++++++++----- .../src/render/components/form-fields/Datetime.js | 7 ++++--- .../src/render/components/form-fields/IFrame.js | 2 +- .../src/render/components/form-fields/Number.js | 14 +++++++++----- .../src/render/components/form-fields/Radio.js | 14 +++++++++----- .../src/render/components/form-fields/Select.js | 14 +++++++++----- .../src/render/components/form-fields/Table.js | 2 +- .../src/render/components/form-fields/Taglist.js | 14 +++++++++----- .../src/render/components/form-fields/Textarea.js | 14 +++++++++----- .../src/render/components/form-fields/Textfield.js | 14 +++++++++----- .../components/form-fields/parts/Datepicker.js | 2 +- .../components/form-fields/parts/Timepicker.js | 2 +- 16 files changed, 87 insertions(+), 54 deletions(-) diff --git a/packages/form-js-viewer/src/render/components/Description.js b/packages/form-js-viewer/src/render/components/Description.js index 3a6d40d3c..7dc6d1ac1 100644 --- a/packages/form-js-viewer/src/render/components/Description.js +++ b/packages/form-js-viewer/src/render/components/Description.js @@ -2,7 +2,7 @@ import { useSingleLineTemplateEvaluation } from '../hooks'; export function Description(props) { - const { description } = props; + const { description, id } = props; const evaluatedDescription = useSingleLineTemplateEvaluation(description || '', { debug: true }); @@ -10,5 +10,5 @@ export function Description(props) { return null; } - return
{ evaluatedDescription }
; + return
{ evaluatedDescription }
; } \ No newline at end of file diff --git a/packages/form-js-viewer/src/render/components/FormField.js b/packages/form-js-viewer/src/render/components/FormField.js index c4d0741bd..27e38c47b 100644 --- a/packages/form-js-viewer/src/render/components/FormField.js +++ b/packages/form-js-viewer/src/render/components/FormField.js @@ -128,7 +128,6 @@ export function FormField(props) { const domId = `${prefixId(field.id, formId, indexes)}`; const fieldErrors = get(errors, [ field.id, ...Object.values(indexes || {}) ]) || []; - const errorMessageId = errors.length === 0 ? undefined : `${domId}-error-message`; return ( @@ -137,7 +136,6 @@ export function FormField(props) { { ...props } disabled={ disabled } errors={ fieldErrors } - errorMessageId={ errorMessageId } domId={ domId } onChange={ disabled || readonly ? noop : onChangeIndexed } onBlur={ disabled || readonly ? noop : onBlur } diff --git a/packages/form-js-viewer/src/render/components/Label.js b/packages/form-js-viewer/src/render/components/Label.js index 971195375..81292a879 100644 --- a/packages/form-js-viewer/src/render/components/Label.js +++ b/packages/form-js-viewer/src/render/components/Label.js @@ -5,7 +5,8 @@ import { useSingleLineTemplateEvaluation } from '../hooks'; /** * @typedef Props - * @property {string} [id] + * @property {string|undefined} [id] + * @property {string|undefined} [htmlFor] * @property {string|undefined} label * @property {string} [class] * @property {boolean} [collapseOnEmpty] @@ -18,6 +19,7 @@ import { useSingleLineTemplateEvaluation } from '../hooks'; export function Label(props) { const { id, + htmlFor, label, collapseOnEmpty = true, required = false @@ -26,11 +28,11 @@ export function Label(props) { const evaluatedLabel = useSingleLineTemplateEvaluation(label || '', { debug: true }); return ( -