Skip to content

Commit d006871

Browse files
Merge pull request #1572 from ASU/UDS-2042
UDS-2042: feat(app-rfi): add legend to fieldset for accessible form group labeling
2 parents 883c434 + 59cd66c commit d006871

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

packages/app-rfi/src/components/controls/RfiRadioGroup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Field } from "formik";
55
import PropTypes from "prop-types";
66
import React from "react";
77

8-
import { RfiError, RfiLabel } from "./controls-helpers";
8+
import { RfiError, RfiLegend } from "./controls-helpers";
99

1010
const RfiRadioGroup = ({ name, id, options, label, onBlur }) => {
1111
return (
@@ -19,7 +19,7 @@ const RfiRadioGroup = ({ name, id, options, label, onBlur }) => {
1919
const isError = meta.error;
2020
return (
2121
<fieldset>
22-
<RfiLabel label={label} name={name} id={id} />
22+
<RfiLegend label={label} />
2323
<RfiError isError={isError} metaError={meta.error} />
2424
{options.map(option => (
2525
<div

packages/app-rfi/src/components/controls/controls-helpers.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,41 @@ const GaEventPropTypes = {
1717

1818
const RfiLabel = ({ label, name, id, requiredIcon }) => (
1919
<label htmlFor={id || name}>
20-
{requiredIcon ? (
21-
<span title="Required">
22-
<i className="fas fa-circle uds-field-required" aria-hidden="true" />
23-
</span>
24-
) : null}
25-
&nbsp;
20+
{requiredIcon && (
21+
<>
22+
<span title="Required">
23+
<i className="fas fa-circle uds-field-required" aria-hidden="true" />
24+
</span>
25+
&nbsp;
26+
</>
27+
)}
2628
{label}
2729
</label>
2830
);
2931

32+
const RfiLegend = ({ label, requiredIcon }) => (
33+
<legend className="fw-bold">
34+
{requiredIcon && (
35+
<>
36+
<span title="Required">
37+
<i className="fas fa-circle uds-field-required" aria-hidden="true" />
38+
</span>
39+
&nbsp;
40+
</>
41+
)}
42+
{label}
43+
</legend>
44+
);
45+
3046
const RfiError = ({ isError, metaError }) => (
3147
<div role="alert">
32-
{isError ? (
48+
{isError && (
3349
<small className="form-text invalid-feedback">
3450
<i className="fas fa-exclamation-triangle" aria-hidden="true" />
3551
&nbsp;
3652
{metaError}
3753
</small>
38-
) : null}
54+
)}
3955
</div>
4056
);
4157

@@ -55,6 +71,16 @@ RfiLabel.propTypes = {
5571
requiredIcon: PropTypes.bool,
5672
};
5773

74+
RfiLegend.defaultProps = {
75+
label: undefined,
76+
requiredIcon: undefined,
77+
};
78+
79+
RfiLegend.propTypes = {
80+
label: PropTypes.string.isRequired,
81+
requiredIcon: PropTypes.bool,
82+
};
83+
5884
RfiError.defaultProps = {
5985
isError: undefined,
6086
metaError: undefined,
@@ -64,4 +90,4 @@ RfiError.propTypes = {
6490
isError: PropTypes.bool,
6591
metaError: PropTypes.string,
6692
};
67-
export { RfiLabel, RfiError, GaEventPropTypes };
93+
export { RfiLabel, RfiLegend, RfiError, GaEventPropTypes };

0 commit comments

Comments
 (0)