Skip to content
This repository has been archived by the owner on Jul 19, 2019. It is now read-only.

Do not render menu if callback returns nothing #383

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ class Autocomplete extends React.Component {
minWidth: this.state.menuWidth,
}
const menu = this.props.renderMenu(items, this.props.value, style)
if (!menu) {
return menu
}

return React.cloneElement(menu, {
ref: e => this.refs.menu = e,
// Ignore blur to prevent menu from de-rendering before we can process click
Expand Down
9 changes: 9 additions & 0 deletions lib/__tests__/Autocomplete-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ describe('Autocomplete acceptance tests', () => {
expect(menuSpy.mock.calls[1][2]).toEqual({ left: 0, top: 0, minWidth: 0 })
})

it('should be empty if no menu provided', () => {
const tree = shallow(AutocompleteComponentJSX({
open: true,
renderMenu: () => null,
}))

expect(tree.children()).toHaveLength(1)
})

it('should set menu positions when the menu is forced open via props.open', () => {
const menuSpy = jest.fn(() => <div />)
const tree = mount(AutocompleteComponentJSX({
Expand Down