From 7c7af92bcece4ee3122bf47ad4dc9712dd84a404 Mon Sep 17 00:00:00 2001 From: Mike Fix Date: Fri, 17 May 2019 10:42:46 -0700 Subject: [PATCH] fix dropdown sort --- components/Dropdown.js | 138 ++++++++++++++++++++++++----------------- 1 file changed, 81 insertions(+), 57 deletions(-) diff --git a/components/Dropdown.js b/components/Dropdown.js index e92f059..122eb1a 100644 --- a/components/Dropdown.js +++ b/components/Dropdown.js @@ -57,62 +57,21 @@ class Dropdown extends React.PureComponent { userInputtedValue = '' - renderDropdown = ({ - isOpen, - highlightedIndex, - selectedItem, - getRootProps, - getToggleButtonProps, - getInputProps, - getItemProps - }) => { - const { list, color, itemWrapper, icon, disableInput, title } = this.props - const { itemsToShow } = this.state - - const minWidth = calcMinWidth(itemsToShow) - const labelId = title ? `${title.toLowerCase()}-dropdown` : undefined - - return ( - - {title && {title}} - {icon} - - {selectedItem.name} - - {isOpen ? ( - - {list.map((item, index) => ( - - {item.name} - - ))} - - ) : null} - - ) - } - render() { - const { innerRef, selected, onChange, title } = this.props + const { + innerRef, + color, + selected, + onChange, + itemWrapper, + icon, + disableInput, + title + } = this.props const { itemsToShow, inputValue } = this.state + const minWidth = calcMinWidth(itemsToShow) + const labelId = title ? `${title.toLowerCase()}-dropdown` : undefined return ( @@ -126,12 +85,77 @@ class Dropdown extends React.PureComponent { onUserAction={this.onUserAction} labelId={labelId} > - {this.renderDropdown} + {renderDropdown({ + color, + list: itemsToShow, + selected, + minWidth, + itemWrapper, + icon, + disableInput, + title, + labelId + })} ) } } +const renderDropdown = ({ + color, + list, + minWidth, + itemWrapper, + icon, + disableInput, + title, + labelId +}) => ({ + isOpen, + highlightedIndex, + selectedItem, + getRootProps, + getToggleButtonProps, + getInputProps, + getItemProps +}) => { + return ( + + {title && {title}} + {icon} + + {selectedItem.name} + + {isOpen ? ( + + {list.map((item, index) => ( + + {item.name} + + ))} + + ) : null} + + ) +} + const DropdownContainer = ({ children, innerRef, minWidth, ...rest }) => { return (
@@ -174,9 +198,9 @@ const DropdownIcon = ({ children, isOpen }) => {
) + } else { + return null } - - return null } const SelectedItem = ({ @@ -246,7 +270,7 @@ const SelectedItem = ({ ) } -const List = ({ children, color }) => { +const ListItems = ({ children, color }) => { return (