Skip to content

Commit 3e63b27

Browse files
committed
feat(pf4): add description to select
1 parent d91863b commit 3e63b27

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.ddorg__pf4-component-mapper__select-option-description {
2+
font-size: 12px;
3+
color: rgb(106, 110, 115);
4+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33

4+
import './option.css';
5+
46
import { CheckIcon } from '@patternfly/react-icons';
57

68
const Option = ({ item, isActive, isSelected, ...props }) => (
@@ -19,6 +21,7 @@ const Option = ({ item, isActive, isSelected, ...props }) => (
1921
<CheckIcon />
2022
</span>
2123
)}
24+
{item.description && <div className="ddorg__pf4-component-mapper__select-option-description">{item.description}</div>}
2225
</button>
2326
</li>
2427
);
@@ -27,7 +30,8 @@ Option.propTypes = {
2730
item: PropTypes.shape({
2831
label: PropTypes.node,
2932
isDisabled: PropTypes.bool,
30-
disabled: PropTypes.bool
33+
disabled: PropTypes.bool,
34+
description: PropTypes.node
3135
}).isRequired,
3236
isActive: PropTypes.bool,
3337
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('.ddorg__pf4-component-mapper__select-option-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');

0 commit comments

Comments
 (0)