changed to new functions
All checks were successful
Deploy Docs to Synology / deploy (push) Successful in 3s
All checks were successful
Deploy Docs to Synology / deploy (push) Successful in 3s
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// components/Autocomplete.js
|
||||
import { $, Tag, For } from "sigpro";
|
||||
import { $, h, each } from "sigpro";
|
||||
import { val } from "../utils.js";
|
||||
import { Input } from "./Input.js";
|
||||
|
||||
@@ -22,10 +22,10 @@ export const Autocomplete = (props) => {
|
||||
const cursor = $(-1);
|
||||
|
||||
// FIX CRÍTICO: En lugar de una computed automática, usamos una señal manual
|
||||
// y un Watch para garantizar que la lista se actualice SÍNCRONAMENTE.
|
||||
// y un watch para garantizar que la lista se actualice SÍNCRONAMENTE.
|
||||
const list = $([]);
|
||||
|
||||
Watch(() => {
|
||||
watch(() => {
|
||||
const q = String(query()).toLowerCase();
|
||||
const data = val(items) || [];
|
||||
const filtered = q
|
||||
@@ -64,7 +64,7 @@ export const Autocomplete = (props) => {
|
||||
}
|
||||
};
|
||||
|
||||
return Tag("div", { class: 'relative w-full' }, [
|
||||
return h("div", { class: 'relative w-full' }, [
|
||||
Input({
|
||||
label,
|
||||
class: className,
|
||||
@@ -75,14 +75,14 @@ export const Autocomplete = (props) => {
|
||||
onkeydown: nav,
|
||||
oninput: (e) => {
|
||||
const v = e.target.value;
|
||||
query(v); // Esto dispara el Watch de arriba y actualiza 'list'
|
||||
query(v); // Esto dispara el watch de arriba y actualiza 'list'
|
||||
if (typeof value === "function") value(v);
|
||||
isOpen(true);
|
||||
cursor(-1);
|
||||
},
|
||||
...rest,
|
||||
}),
|
||||
Tag(
|
||||
h(
|
||||
"ul",
|
||||
{
|
||||
class: "absolute dropdown-menu left-0 w-full menu bg-base-100 rounded-box mt-1 p-2 shadow-xl max-h-60 overflow-y-auto border border-base-300 z-50",
|
||||
@@ -90,11 +90,11 @@ export const Autocomplete = (props) => {
|
||||
style: () => (isOpen() && list().length ? "display:block" : "display:none"),
|
||||
},
|
||||
[
|
||||
For(
|
||||
each(
|
||||
list,
|
||||
(opt, i) =>
|
||||
Tag("li", {}, [
|
||||
Tag(
|
||||
h("li", {}, [
|
||||
h(
|
||||
"a",
|
||||
{
|
||||
class: () => `block w-full ${cursor() === i ? "active bg-primary text-primary-content" : ""}`,
|
||||
@@ -107,7 +107,7 @@ export const Autocomplete = (props) => {
|
||||
(opt, i) => (typeof opt === "string" ? opt : opt.value) + i,
|
||||
),
|
||||
// Mensaje de "no hay datos" reactivo
|
||||
() => (list().length ? null : Tag("li", { class: "p-2 text-center opacity-50" }, "nodata")),
|
||||
() => (list().length ? null : h("li", { class: "p-2 text-center opacity-50" }, "nodata")),
|
||||
],
|
||||
),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user