Skip to content

Commit e7e4e71

Browse files
authored
Make single select a dropdown at >5 choices (#691)
1 parent aaf4723 commit e7e4e71

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

.changeset/early-planets-rule.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'wingman-fe': patch
3+
---
4+
5+
QuestionnaireForm: Render single-select questions with >5 choices as a dropdown
6+
7+
This matches existing behaviour of SEEK's native apply form.

fe/lib/components/QuestionnaireForm/components/SingleSelect.tsx

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { RadioGroup, RadioItem, Stack, Text } from 'braid-design-system';
1+
import {
2+
Dropdown,
3+
RadioGroup,
4+
RadioItem,
5+
Stack,
6+
Text,
7+
} from 'braid-design-system';
28
import React from 'react';
39

410
import { componentId } from './componentId';
@@ -18,7 +24,9 @@ const SingleSelect = ({
1824
id,
1925
title,
2026
}: SingleSelectProps) => {
21-
const onChange = (event: React.FormEvent<HTMLInputElement>) => {
27+
const onChange = (
28+
event: React.FormEvent<HTMLInputElement | HTMLSelectElement>,
29+
) => {
2230
setValue(event.currentTarget.value);
2331
};
2432

@@ -28,16 +36,29 @@ const SingleSelect = ({
2836
{title}
2937
</Text>
3038

31-
<RadioGroup
32-
aria-labelledby={componentId('single-select-label', id)}
33-
id={componentId('single-select', id)}
34-
onChange={onChange}
35-
value={value}
36-
>
37-
{choices.map((choice) => (
38-
<RadioItem key={choice} label={choice} value={choice} />
39-
))}
40-
</RadioGroup>
39+
{choices.length > 5 ? (
40+
<Dropdown
41+
aria-labelledby={componentId('single-select-label', id)}
42+
id={componentId('single-select', id)}
43+
onChange={onChange}
44+
value={value}
45+
>
46+
{choices.map((choice) => (
47+
<option key={choice}>{choice}</option>
48+
))}
49+
</Dropdown>
50+
) : (
51+
<RadioGroup
52+
aria-labelledby={componentId('single-select-label', id)}
53+
id={componentId('single-select', id)}
54+
onChange={onChange}
55+
value={value}
56+
>
57+
{choices.map((choice) => (
58+
<RadioItem key={choice} label={choice} value={choice} />
59+
))}
60+
</RadioGroup>
61+
)}
4162
</Stack>
4263
);
4364
};

0 commit comments

Comments
 (0)