Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Added aria-describedby atttribute to avfield to link error messages #260

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/AvField.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ export default class AvField extends Component {
size={size}
disabled={disabled}
readOnly={readOnly}
{...attributes}
{...{...attributes, ...{'aria-describedby':'errorMsg'}}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should change this to

aria-describedby="errorMsg"
{ ...attributes }

This way the user can override it if needed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

>
{children}
</AvInput>);

const validation = this.context.FormCtrl.getInputState(this.props.name);

const feedback = validation.errorMessage ? (<AvFeedback>{validation.errorMessage}</AvFeedback>) : null;
const feedback = validation.errorMessage ? (<AvFeedback id="errorMsg">{validation.errorMessage}</AvFeedback>) : null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make the id dynamic. If multiple fields have an error, then there will be more than one element with id="errorMsg".

We can generate it off the id for the field

<AvFeedback id={`${id}-error`} ...`

we should use this value with the aria-describedby prop as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

const help = helpMessage ? (<FormText>{helpMessage}</FormText>) : null;
const inputRow = row ? <Col {...col}>{input}{feedback}{help}</Col> : input;
const check = attributes.type === 'checkbox';
Expand Down