simplify as possible

This commit is contained in:
Víctor Losada Hernández
2026-10-29 15:05:44 +01:00
parent 8ee317e8c4
commit f38d20540f
+5 -15
View File
@@ -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}