Skip to content

Commit 30c5e1c

Browse files
authored
Merge pull request #1114 from rvsia/addDescriptionToPFSelect
Add description to pf select
2 parents d91863b + 37c66ae commit 30c5e1c

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

packages/pf4-component-mapper/src/select/select/option.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const Option = ({ item, isActive, isSelected, ...props }) => (
1919
<CheckIcon />
2020
</span>
2121
)}
22+
{item.description && <div className="pf-c-select__menu-item-description">{item.description}</div>}
2223
</button>
2324
</li>
2425
);
@@ -27,7 +28,8 @@ Option.propTypes = {
2728
item: PropTypes.shape({
2829
label: PropTypes.node,
2930
isDisabled: PropTypes.bool,
30-
disabled: PropTypes.bool
31+
disabled: PropTypes.bool,
32+
description: PropTypes.node
3133
}).isRequired,
3234
isActive: PropTypes.bool,
3335
isSelected: PropTypes.bool,

packages/pf4-component-mapper/src/tests/select/select.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { act } from 'react-dom/test-utils';
88
import ValueContainer from '../../select/select/value-container';
99
import FormTemplate from '../../form-template';
1010
import componentMapper from '../../component-mapper';
11+
import Option from '../../select/select/option';
1112

1213
describe('<Select />', () => {
1314
let initialProps;
@@ -75,6 +76,42 @@ describe('<Select />', () => {
7576
).toEqual('Translated');
7677
});
7778

79+
it('should render description', async () => {
80+
const wrapper = mount(
81+
<FormRenderer
82+
onSubmit={jest.fn}
83+
FormTemplate={FormTemplate}
84+
componentMapper={componentMapper}
85+
schema={{
86+
fields: [
87+
{
88+
component: componentTypes.SELECT,
89+
name: 'select',
90+
options: [
91+
{
92+
label: <h1>Translated</h1>,
93+
value: 'translated',
94+
description: 'some description'
95+
}
96+
]
97+
}
98+
]
99+
}}
100+
/>
101+
);
102+
103+
expect(wrapper.find(ValueContainer).find('h1')).toHaveLength(0);
104+
105+
wrapper.find('.pf-c-select__toggle').simulate('click');
106+
107+
expect(
108+
wrapper
109+
.find(Option)
110+
.find('.pf-c-select__menu-item-description')
111+
.text()
112+
).toEqual('some description');
113+
});
114+
78115
it('should return single simple value', async () => {
79116
const wrapper = mount(<Select {...initialProps} />);
80117
wrapper.find('.pf-c-select__toggle').simulate('click');

packages/react-renderer-demo/src/doc-components/examples-texts/pf4/select.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ const asyncLoadOptions = (searchValue) => new Promise(resolve => setTimeout(() =
3131
}, 2000));
3232
```
3333

34+
## Description
35+
36+
PF4 select can render a description for each option. Just add a `description` attribute to its object (can be `React.node`):
37+
38+
```jsx
39+
options: [
40+
{ value: 'value', label: 'Some label', description: 'Some description' }
41+
]
42+
```
43+
3444
import SelectCommon from '../select.md';
3545

3646
<SelectCommon/>

0 commit comments

Comments
 (0)