Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Fix styles in `code-sandbox` package @lucivpav ([#1853](https://github.com/stardust-ui/react/pull/1853))
- Adding accessibility tab content @kolaps33 ([#1840](https://github.com/stardust-ui/react/pull/1840))
- Fix CodeSandbox examples versions mismatch @lucivpav ([#1849](https://github.com/stardust-ui/react/pull/1849))
- Update documentation regarding `renderSelectedItem` prop in `Dropdown` @lucivpav ([#1856](https://github.com/stardust-ui/react/pull/1856))

<!--------------------------------[ v0.37.0 ]------------------------------- -->
## [v0.37.0](https://github.com/stardust-ui/react/tree/v0.37.0) (2019-08-26)
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ export interface DropdownProps
items?: ShorthandCollection<DropdownItemProps>

/**
* Function that converts an item to string. Used when dropdown has the search boolean prop set to true.
* Function that converts an item to string. Used when dropdown has the `search` boolean prop set to true.
* By default, it:
* - returns the header property (if it exists on an item)
* - returns the `header` property (if it exists on an item)
* - converts an item to string (if the item is a primitive)
*/
itemToString?: (item: ShorthandValue<DropdownItemProps>) => string
Expand Down Expand Up @@ -185,7 +185,7 @@ export interface DropdownProps
renderItem?: ShorthandRenderFunction

/**
* A custom render function for the selected item.
* A custom render function for the selected item. Only applicable with the `multiple` prop.
*
* @param {React.ReactType} Component - The computed component for this slot.
* @param {object} props - The computed props for this slot.
Expand Down
19 changes: 19 additions & 0 deletions packages/react/test/specs/components/Dropdown/Dropdown-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1441,4 +1441,23 @@ describe('Dropdown', () => {
expect(stopPropagation).toBeCalledTimes(1)
})
})

describe('renderSelectedItem', () => {
it('calls renderSelectedItem in multiple selection', () => {
const renderSelectedItem = jest.fn((selectedItem, props) => null)
const wrapper = mountWithProvider(
<Dropdown multiple items={items} renderSelectedItem={renderSelectedItem} />,
)
const triggerButton = getTriggerButtonWrapper(wrapper)

triggerButton.simulate('click')
const firstItem = getItemAtIndexWrapper(wrapper)
firstItem.simulate('click', { nativeEvent: { stopImmediatePropagation: _.noop } })
triggerButton.simulate('click')
const secondItem = getItemAtIndexWrapper(wrapper, 1)
secondItem.simulate('click', { nativeEvent: { stopImmediatePropagation: _.noop } })

expect(renderSelectedItem).toBeCalled()
})
})
})