mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-15 12:28:45 +00:00
simplify as possible
This commit is contained in:
@@ -15,33 +15,24 @@ const Combobox = ({
|
|||||||
filterOn : [] // should allow as array to filter on multiple attributes, or even custom filter
|
filterOn : [] // should allow as array to filter on multiple attributes, or even custom filter
|
||||||
},
|
},
|
||||||
valuePatterns = /.+/,
|
valuePatterns = /.+/,
|
||||||
|
options,
|
||||||
...props
|
...props
|
||||||
})=>{
|
})=>{
|
||||||
|
|
||||||
const dropdownRef = useRef(null);
|
const dropdownRef = useRef(null);
|
||||||
const [showDropdown, setShowDropdown] = useState(false);
|
const [showDropdown, setShowDropdown] = useState(false);
|
||||||
const [value, setValue] = useState('');
|
|
||||||
const [options, setOptions] = useState([...props.options]);
|
|
||||||
const [inputFocused, setInputFocused] = useState(false);
|
const [inputFocused, setInputFocused] = useState(false);
|
||||||
|
const [value, setValue] = useState(defaultValue);
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
if(trigger == 'click') {
|
if(trigger === 'click') {
|
||||||
document.addEventListener('click', handleClickOutside);
|
document.addEventListener('click', handleClickOutside);
|
||||||
|
return ()=>document.removeEventListener('click', handleClickOutside);
|
||||||
}
|
}
|
||||||
setValue(defaultValue);
|
|
||||||
|
|
||||||
return ()=>{
|
|
||||||
if(trigger == 'click') {
|
|
||||||
document.removeEventListener('click', handleClickOutside);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleClickOutside = (e)=>{
|
const handleClickOutside = (e)=>{
|
||||||
// Close dropdown when clicked outside
|
// Close dropdown when clicked outside
|
||||||
if(dropdownRef.current && !dropdownRef.current.contains(e.target)) {
|
if(!dropdownRef.current?.contains(e.target)) handleDropdown(false);
|
||||||
handleDropdown(false);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDropdown = (show)=>{
|
const handleDropdown = (show)=>{
|
||||||
@@ -112,7 +103,6 @@ const Combobox = ({
|
|||||||
});
|
});
|
||||||
dropdownChildren = _.uniq(filteredArrays.flat(1));
|
dropdownChildren = _.uniq(filteredArrays.flat(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='dropdown-options'>
|
<div className='dropdown-options'>
|
||||||
{dropdownChildren}
|
{dropdownChildren}
|
||||||
|
|||||||
Reference in New Issue
Block a user