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

Commit

Permalink
Implement aria-required in child field
Browse files Browse the repository at this point in the history
  • Loading branch information
francocorreasosa committed Jan 28, 2020
1 parent 8ecc782 commit 89290bf
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions core/components/molecules/form/field/field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ const ariaDescribedBy = (helperTextId, errorTextId) => {
return {};
};

const applyAriaToFieldChild = (children, inputId, helperTextId, errorTextId) =>
const applyAriaToFieldChild = (children, inputId, helperTextId, errorTextId, isRequired) =>
React.Children.map(children, (child) => {
if (!child) {
return null;
}
return React.cloneElement(child, {
id: inputId,
...ariaDescribedBy(helperTextId, errorTextId)
...ariaDescribedBy(helperTextId, errorTextId),
"aria-required": isRequired
});
});

Expand Down Expand Up @@ -136,7 +137,7 @@ const Field = (props: IFieldProps) => {
{...ariaDescribedBy(helperTextId, errorTextId)}
/>
) : (
applyAriaToFieldChild(props.children, id, helperTextId, errorTextId)
applyAriaToFieldChild(props.children, id, helperTextId, errorTextId, props.required)
)}
{(props.error || props.helpText) && (
<Field.FeedbackContainer>
Expand Down

0 comments on commit 89290bf

Please sign in to comment.