Skip to content

Commit

Permalink
fix: Associating FormField hint while not in error state (#2199)
Browse files Browse the repository at this point in the history
Fixes: #2149  

I observed that when using hintId and hintText props on `<FormField>`, the hint instructions were still not associated to the input field. Screen readers were not automatically reading the description on focus.

[category:Components]
  • Loading branch information
williamjstanton committed May 23, 2023
1 parent 6be5a03 commit 585e35a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions modules/react/form-field/lib/FormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ export class FormField extends React.Component<React.PropsWithChildren<FormField
if (typeof this.props.error !== 'undefined') {
props.error = this.props.error;

if (this.props.hintId) {
props['aria-describedby'] = this.props.hintId;
}

if (this.props.error === ErrorType.Error) {
props['aria-invalid'] = true;
}
}

if (this.props.hintId) {
props['aria-describedby'] = this.props.hintId;
}

if (this.props.required) {
props.required = true;
}
Expand Down
2 changes: 2 additions & 0 deletions modules/react/form-field/stories/examples/Hint.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import {FormField} from '@workday/canvas-kit-react/form-field';
import {TextInput} from '@workday/canvas-kit-react/text-input';
import {useUniqueId} from '@workday/canvas-kit-react/common';

export const Hint = () => {
const [value, setValue] = React.useState('');
Expand All @@ -11,6 +12,7 @@ export const Hint = () => {

return (
<FormField
hintId={useUniqueId()}
hintText="This address will be shown as a shipping address option for future orders."
label="Address Name"
>
Expand Down

0 comments on commit 585e35a

Please sign in to comment.