Skip to content

Commit 79b7b46

Browse files
jpmckinneyclaude
andcommitted
a11y(Select): forward describedBy to the native select element
SelectProps exposed only `helpText`, which renders visible help. A consumer had no way to associate the control with an existing description element (e.g. a cross-field dependency hint such as "select a district first to enable this field") via aria-describedby without rendering visible text. Add an optional `describedBy` prop and merge it, space-separated, with the ids already generated for `helpText` and `error` rather than overwriting them. No visual change when the prop is unset. Adds a Storybook story. Unblocks IDS-DRR-Frontend ACC-003. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent bbf6541 commit 79b7b46

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

packages/opub-ui/src/components/Select/Select.stories.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,26 @@ export function Disabled({ ...props }) {
115115
// );
116116
// }
117117

118+
export function WithDescribedBy({ ...props }) {
119+
const options = [
120+
{ label: 'Block A', value: 'a' },
121+
{ label: 'Block B', value: 'b' },
122+
];
123+
124+
return (
125+
<>
126+
<p id="block-dependency-hint">Select a district first to enable this field.</p>
127+
<Select
128+
label="Block"
129+
name="select-1"
130+
describedBy="block-dependency-hint"
131+
options={options}
132+
{...props}
133+
/>
134+
</>
135+
);
136+
}
137+
118138
export function Error({ ...props }) {
119139
const [selected, setSelected] = useState('Bangaluru');
120140

packages/opub-ui/src/components/Select/Select.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const Select = forwardRef(
2727
labelInline,
2828
disabled,
2929
helpText,
30+
describedBy: describedByProp,
3031
placeholder,
3132
id: idProp,
3233
name,
@@ -76,6 +77,10 @@ export const Select = forwardRef(
7677
describedBy.push(`${id}Error`);
7778
}
7879

80+
if (describedByProp) {
81+
describedBy.push(describedByProp);
82+
}
83+
7984
const options = optionsProp || [];
8085
let normalizedOptions = options.map(normalizeOption);
8186

packages/opub-ui/src/types/select.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export interface SelectProps {
4545
disabled?: boolean;
4646
/** Additional text to aide in use */
4747
helpText?: React.ReactNode;
48+
/** ID(s) forwarded to the native select as `aria-describedby`, merged with the `helpText`/`error` ids */
49+
describedBy?: string;
4850
/** Example text to display as placeholder */
4951
placeholder?: string;
5052
/** ID for form input */

0 commit comments

Comments
 (0)