Skip to content

Commit

Permalink
add value to drop down (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
NaveCohenMonday authored Dec 22, 2020
1 parent cdefacb commit 42210fa
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/components/Dropdown/Dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Dropdown = ({
searchable,
options,
defaultValue,
value,
noOptionsMessage,
openMenuOnFocus,
openMenuOnClick,
Expand All @@ -36,20 +37,20 @@ const Dropdown = ({
asyncOptions,
cacheOptions,
defaultOptions,
isVirtualized
isVirtualized,
}) => {
const [isOpen, setOpen] = useState(false);

const handleMenuOpen = useCallback(
data => {
(data) => {
onMenuOpen(data);
setOpen(true);
},
[onMenuOpen, setOpen]
);

const handleMenuClose = useCallback(
data => {
(data) => {
onMenuClose(data);
setOpen(false);
},
Expand All @@ -59,32 +60,34 @@ const Dropdown = ({
const customStyles = useMemo(() => styles({ size, rtl }), [size, rtl]);

const Menu = useCallback(
props => <MenuComponent {...props} isOpen={isOpen} />,
(props) => <MenuComponent {...props} isOpen={isOpen} />,
[isOpen]
);

const DropdownIndicator = useCallback(
props => <DropdownIndicatorComponent {...props} size={size} />,
(props) => <DropdownIndicatorComponent {...props} size={size} />,
[size]
);

const Option = useCallback(
props => <OptionComponent {...props} OptionRenderer={OptionRenderer} />,
(props) => <OptionComponent {...props} OptionRenderer={OptionRenderer} />,
[OptionRenderer]
);

const Input = useCallback(
props => <components.Input {...props} aria-label="Dropdown input" />,
(props) => <components.Input {...props} aria-label="Dropdown input" />,
[]
);

const SingleValue = useCallback(
props => <SingleValueComponent {...props} ValueRenderer={ValueRenderer} />,
(props) => (
<SingleValueComponent {...props} ValueRenderer={ValueRenderer} />
),
[ValueRenderer]
);

const ClearIndicator = useCallback(
props => <ClearIndicatorComponent {...props} size={size} />,
(props) => <ClearIndicatorComponent {...props} size={size} />,
[size]
);

Expand All @@ -94,12 +97,12 @@ const Dropdown = ({
...(asyncOptions && {
loadOptions: asyncOptions,
cacheOptions: cacheOptions,
...(defaultOptions && { defaultOptions })
})
...(defaultOptions && { defaultOptions }),
}),
};

const additions = {
...(!asyncOptions && { options })
...(!asyncOptions && { options }),
};

return (
Expand All @@ -112,7 +115,7 @@ const Dropdown = ({
Input,
...(OptionRenderer && { Option }),
...(ValueRenderer && { SingleValue }),
...(isVirtualized && { MenuList: WindowedMenuList })
...(isVirtualized && { MenuList: WindowedMenuList }),
}}
size={size}
noOptionsMessage={noOptionsMessage}
Expand All @@ -121,6 +124,7 @@ const Dropdown = ({
isClearable={clearable}
isSearchable={searchable}
defaultValue={defaultValue}
value={value}
onMenuOpen={handleMenuOpen}
onMenuClose={handleMenuClose}
onFocus={onFocus}
Expand Down Expand Up @@ -150,7 +154,7 @@ Dropdown.defaultProps = {
options: [],
noOptionsMessage: NOOP,
clearable: true,
size: SIZE.MEDIUM
size: SIZE.MEDIUM,
};

Dropdown.propTypes = {
Expand Down Expand Up @@ -237,8 +241,8 @@ Dropdown.propTypes = {
PropTypes.func, // callback
PropTypes.shape({
then: PropTypes.func.isRequired,
catch: PropTypes.func.isRequired
}) // Promise
catch: PropTypes.func.isRequired,
}), // Promise
]),
/**
* If set to true, fetched async options will be cached
Expand All @@ -249,12 +253,12 @@ Dropdown.propTypes = {
*/
defaultOptions: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.arrayOf(PropTypes.object)
PropTypes.arrayOf(PropTypes.object),
]),
/**
* If set to true, the menu will use virtualization. Virtualized async works only with
*/
isVirtualized: PropTypes.bool
isVirtualized: PropTypes.bool,
};

export default Dropdown;

0 comments on commit 42210fa

Please sign in to comment.