Autocomplete works with array and objects
All checks were successful
Deploy Docs to Synology / deploy (push) Successful in 4s
All checks were successful
Deploy Docs to Synology / deploy (push) Successful in 4s
This commit is contained in:
@@ -11,7 +11,11 @@ export { $, $$, watch, batch, h, Fragment, mount, when, each, router, onUnmount,
|
||||
const val = val => typeof val === "function" ? val() : val;
|
||||
const getBy = (item, field = 'label') => (item && typeof item === 'object') ? item[field] : item;
|
||||
const cls = (...classes) => classes.filter(Boolean).join(' ').trim();
|
||||
const filterBy = (items, query, field = 'label', q = String(query).toLowerCase()) => !query ? val(items) : val(items).filter(item => String(item && typeof item === 'object' ? item[field] : item).toLowerCase().includes(q));
|
||||
const filterBy = (items, query, field = 'label') => {
|
||||
const q = String(val(query) || '').toLowerCase();
|
||||
const list = (val(items) || []).map(i => typeof i === 'object' ? i : { label: i, value: i });
|
||||
return !q ? list : list.filter(item => String(item[field] || '').toLowerCase().includes(q));
|
||||
};
|
||||
const rand = (r) => `${r}-${Math.random().toString(36).slice(2, 9)}`
|
||||
export const hide = () => document.activeElement?.blur()
|
||||
|
||||
@@ -78,7 +82,7 @@ export const Autocomplete = ({ items, value, onselect, placeholder = '...', ...p
|
||||
onclick: () => pick(item)
|
||||
}, getBy(item))
|
||||
]),
|
||||
(item) => getBy(item)
|
||||
'value'
|
||||
),
|
||||
() => filtered().length === 0
|
||||
? h('li', { class: 'p-4 opacity-50 text-center' }, 'Sin resultados')
|
||||
|
||||
Reference in New Issue
Block a user