Skip to content

Commit

Permalink
♿ [open-formulieren/open-forms#4622] Error message is linked to respo…
Browse files Browse the repository at this point in the history
…nsible input

Using aria-describedby to explain which input is responsible for the error
  • Loading branch information
robinmolen committed Sep 26, 2024
1 parent 5a5c199 commit afde9cb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/forms/TextField/TextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const TextField = ({
/>
</Paragraph>
<HelpText>{description}</HelpText>
{touched && <ValidationErrors error={error} />}
{touched && <ValidationErrors error={error} ariaDescribedby={id} />}
</UtrechtFormField>
);
};
Expand Down
9 changes: 7 additions & 2 deletions src/components/forms/ValidationErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ import {FormFieldDescription} from '@utrecht/component-library-react';
import PropTypes from 'prop-types';
import React from 'react';

const ValidationErrors = ({error = ''}) => {
const ValidationErrors = ({error = '', ariaDescribedby = ''}) => {
if (!error) return null;
return (
<FormFieldDescription invalid className="utrecht-form-field-description--openforms-errors">
<FormFieldDescription
invalid
className="utrecht-form-field-description--openforms-errors"
aria-describedby={ariaDescribedby}
>
{error}
</FormFieldDescription>
);
};

ValidationErrors.propTypes = {
error: PropTypes.string,
ariaDescribedby: PropTypes.string,
};

export default ValidationErrors;
2 changes: 1 addition & 1 deletion src/formio/templates/addressNL.ejs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div ref="addressNLContainer"></div>
<div ref="addressNLContainer" id="{{ctx.instance.id}}-{{ctx.component.key}}"></div>
5 changes: 3 additions & 2 deletions src/formio/templates/field.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<div class="utrecht-form-fieldset utrecht-form-fieldset--openforms">
<fieldset
class="utrecht-form-fieldset__fieldset utrecht-form-fieldset--html-fieldset"
id="{{ctx.instance.id}}-{{ctx.component.key}}"
{% if (ctx.component.type === 'radio') { %}role="radiogroup"{% } %}
{% if (ctx.component.description) { %}aria-describedby="{{ctx.id}}-description"{% } %}
>
Expand Down Expand Up @@ -34,7 +35,7 @@
ref="messageContainer"
class="utrecht-form-field-description utrecht-form-field-description--invalid utrecht-form-field-description--openforms-errors"
role="alert"
aria-describedby="{{ctx.id}}"></div>
aria-describedby="{{ctx.instance.id}}-{{ctx.component.key}}"></div>

</fieldset>
</div>
Expand Down Expand Up @@ -73,6 +74,6 @@
ref="messageContainer"
class="utrecht-form-field-description utrecht-form-field-description--invalid utrecht-form-field-description--openforms-errors"
role="alert"
aria-describedby="{{ctx.id}}"></div>
aria-describedby="{{ctx.instance.id}}-{{ctx.component.key}}"></div>
</div>
{% } %}

0 comments on commit afde9cb

Please sign in to comment.