Skip to content

Commit 0f58c37

Browse files
authored
Adds description to Option (#1258)
1 parent 991ae72 commit 0f58c37

File tree

3 files changed

+75
-6
lines changed

3 files changed

+75
-6
lines changed

src/Select/Option.jsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { forwardRef } from 'react';
2+
import classNames from 'classnames';
23
import { components } from 'react-select';
34

45
import CheckboxButton from 'src/CheckboxButton';
@@ -24,10 +25,21 @@ const Option = forwardRef(({ indeterminate, ...props }, ref) => (
2425
ref={ref}
2526
onChange={() => null}
2627
/>
27-
<label>{props.label}</label>
28+
<div className="TitleDescriptionContainer">
29+
<label
30+
className={classNames({
31+
'Label--bold': props.description,
32+
})}
33+
>
34+
{props.label}
35+
</label>
36+
{ props.description && (
37+
<span className="Description">{ props.description }</span>
38+
)}
39+
</div>
2840
</div>
2941
</components.Option>
30-
));
42+
));
3143
/* eslint-enable react/prop-types */
3244

3345
export default Option;

src/Select/Option.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,19 @@
55
.Checkbox {
66
margin-right: var(--synth-spacing-3);
77
}
8+
9+
.TitleDescriptionContainer {
10+
display: flex;
11+
flex-direction: column;
12+
13+
.Label {
14+
&--bold {
15+
font-weight: var(--synth-font-weight-bold);
16+
}
17+
}
18+
19+
.Description {
20+
color: var(--ux-gray-800);
21+
}
22+
}
823
}

src/Select/SingleSelect.stories.jsx

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,26 @@ export default {
2020
};
2121

2222
const options = [
23-
{ label: '1-on-1 interview', value: 1 },
24-
{ label: 'Focus group', value: 2 },
25-
{ label: 'Multi-day study', value: 3 },
26-
{ label: 'Unmoderated task', value: 4 },
23+
{
24+
label: '1-on-1 interview',
25+
value: 1,
26+
description: 'Interviews are typically a conversation between you and a researcher.',
27+
},
28+
{
29+
label: 'Focus group',
30+
value: 2,
31+
description: 'Focus groups involve interacting with a small group of your peers.',
32+
},
33+
{
34+
label: 'Multi-day study',
35+
value: 3,
36+
description: 'Diary and multiday studies are days or weeks long commitments.',
37+
},
38+
{
39+
label: 'Unmoderated task',
40+
value: 4,
41+
description: 'An unmoderated task is just that—an opportunity for a user to try out a product, app, website, etc and share feedback.',
42+
},
2743
];
2844

2945
const peopleOptions = [
@@ -168,6 +184,32 @@ export const GroupedOptions = () => {
168184
);
169185
};
170186

187+
export const CustomOptionWithDescriptionAndCheckbox = () => (
188+
<FormGroup
189+
label="Custom Option with Description And Checkbox"
190+
labelHtmlFor="custom-option-with-description-and-checkbox-select"
191+
>
192+
<SingleSelect
193+
components={{
194+
Option: ({ ...props }) => (
195+
<Option
196+
{...props}
197+
// eslint-disable-next-line react/prop-types
198+
description={props.data.description}
199+
/>
200+
),
201+
}}
202+
inputId="custom-option-with-description-select"
203+
options={options}
204+
onChange={onChange}
205+
/>
206+
</FormGroup>
207+
);
208+
209+
/**
210+
If you're adding a new code, prefer the use of `Option` with a `description` prop.
211+
`OptionWithDescription` is effectively deprecated and will be merged into `Option`.
212+
*/
171213
export const CustomOptionWithDescription = () => {
172214
const optionsWithDescriptions = [
173215
{

0 commit comments

Comments
 (0)