-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept selectedOptionsDisplayFormatter prop #504
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,14 @@ const propTypes = { | |
children: PropTypes.node, | ||
className: PropTypes.string, | ||
selectedValues: PropTypes.arrayOf(PropTypes.string), | ||
selectedOptionsDisplayFormatter: PropTypes.func, | ||
...togglePropTypes('expanded'), | ||
} | ||
|
||
const defaultProps = { | ||
className: '', | ||
selectedValues: [], | ||
selectedOptionsDisplayFormatter: getLabel, | ||
} | ||
|
||
// Wraps the `DropdownCheckboxGroup` component | ||
|
@@ -22,12 +24,13 @@ function DropdownSelect ({ | |
className, | ||
expanded, | ||
selectedValues, | ||
toggleExpanded, | ||
toggleExpanded, | ||
selectedOptionsDisplayFormatter, | ||
}) { | ||
return ( | ||
<div className="dropdown-select"> | ||
<div className="select-input" onClick={ toggleExpanded }> | ||
<p>{ getLabel(selectedValues) }</p> | ||
<p>{selectedOptionsDisplayFormatter(selectedValues)}</p> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this has the possibility to return jsx, should we make it a component (a la LabeledField's labelComponent)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
</div> | ||
<div | ||
className={ classnames( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,27 @@ test('DropdownCheckboxGroup removes value to array when selected option clicked' | |
wrapper.find('input').simulate('change') | ||
const newValue = onChange.mock.calls[0][0] | ||
expect(newValue).toEqual([]) | ||
}) | ||
|
||
test('DropdownCheckboxGroup allows custom selected option formatting', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A test for jsx would be nice as well |
||
const selectedOptionsDisplayFormatter = (values) => { | ||
return values.length ? values.join('; ') : 'Empty' | ||
} | ||
const onChange = jest.fn() | ||
const TOGGLED_OPTION = 'TOGGLED_OPTION' | ||
const props = { | ||
input: { | ||
name: 'test', | ||
value: [], | ||
onChange, | ||
}, | ||
meta: {}, | ||
options: [TOGGLED_OPTION], | ||
selectedOptionsDisplayFormatter, | ||
} | ||
const wrapper = mount(<DropdownCheckboxGroup { ...props } />) | ||
wrapper.find('input').simulate('change') | ||
const newValues = onChange.mock.calls[0] | ||
const displayOptionsHtml = wrapper.find('.select-input').innerHTML | ||
expect(displayOptionsHtml).toEqual(`<p>${selectedOptionsDisplayFormatter(newValues)}</p>`) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it return HTML or JSX?