@nr1e/qwik-ui 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -59,6 +59,7 @@ const DropUpButtonSelector = qwik.component$((props) => {
|
|
|
59
59
|
});
|
|
60
60
|
const DropUp = qwik.component$((props) => {
|
|
61
61
|
const open = qwik.useSignal(props?.open?.value ?? false);
|
|
62
|
+
const dropdownRef = qwik.useSignal();
|
|
62
63
|
qwik.useTask$(({ track }) => {
|
|
63
64
|
track(() => props?.open?.value);
|
|
64
65
|
if (props?.open?.value && props.open.value !== open.value) {
|
|
@@ -71,7 +72,24 @@ const DropUp = qwik.component$((props) => {
|
|
|
71
72
|
props.open.value = open.value;
|
|
72
73
|
}
|
|
73
74
|
});
|
|
75
|
+
qwik.useOnDocument("click", qwik.$((event) => {
|
|
76
|
+
if (open.value && dropdownRef.value && !dropdownRef.value.contains(event.target)) {
|
|
77
|
+
console.log("close");
|
|
78
|
+
open.value = false;
|
|
79
|
+
}
|
|
80
|
+
}));
|
|
81
|
+
qwik.useOnDocument("keydown", qwik.$((event) => {
|
|
82
|
+
if (open.value && event.key === "Escape") {
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
event.stopImmediatePropagation();
|
|
85
|
+
if (document.activeElement instanceof HTMLElement) {
|
|
86
|
+
document.activeElement.blur();
|
|
87
|
+
}
|
|
88
|
+
open.value = false;
|
|
89
|
+
}
|
|
90
|
+
}));
|
|
74
91
|
return /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
92
|
+
ref: dropdownRef,
|
|
75
93
|
class: `dropdown dropdown-top ${open.value ? "dropdown-open" : "dropdown-close"} ${props?.class ?? ""}`,
|
|
76
94
|
onClick$: () => {
|
|
77
95
|
open.value = !open.value;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from "@builder.io/qwik/jsx-runtime";
|
|
2
|
-
import { component$, Slot, useSignal, useTask$ } from "@builder.io/qwik";
|
|
2
|
+
import { component$, Slot, useSignal, useTask$, useOnDocument, $ } from "@builder.io/qwik";
|
|
3
3
|
import { Link } from "@builder.io/qwik-city";
|
|
4
4
|
const DropUpButton = component$((props) => {
|
|
5
5
|
return /* @__PURE__ */ jsx("li", {
|
|
@@ -57,6 +57,7 @@ const DropUpButtonSelector = component$((props) => {
|
|
|
57
57
|
});
|
|
58
58
|
const DropUp = component$((props) => {
|
|
59
59
|
const open = useSignal(props?.open?.value ?? false);
|
|
60
|
+
const dropdownRef = useSignal();
|
|
60
61
|
useTask$(({ track }) => {
|
|
61
62
|
track(() => props?.open?.value);
|
|
62
63
|
if (props?.open?.value && props.open.value !== open.value) {
|
|
@@ -69,7 +70,24 @@ const DropUp = component$((props) => {
|
|
|
69
70
|
props.open.value = open.value;
|
|
70
71
|
}
|
|
71
72
|
});
|
|
73
|
+
useOnDocument("click", $((event) => {
|
|
74
|
+
if (open.value && dropdownRef.value && !dropdownRef.value.contains(event.target)) {
|
|
75
|
+
console.log("close");
|
|
76
|
+
open.value = false;
|
|
77
|
+
}
|
|
78
|
+
}));
|
|
79
|
+
useOnDocument("keydown", $((event) => {
|
|
80
|
+
if (open.value && event.key === "Escape") {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
event.stopImmediatePropagation();
|
|
83
|
+
if (document.activeElement instanceof HTMLElement) {
|
|
84
|
+
document.activeElement.blur();
|
|
85
|
+
}
|
|
86
|
+
open.value = false;
|
|
87
|
+
}
|
|
88
|
+
}));
|
|
72
89
|
return /* @__PURE__ */ jsx("div", {
|
|
90
|
+
ref: dropdownRef,
|
|
73
91
|
class: `dropdown dropdown-top ${open.value ? "dropdown-open" : "dropdown-close"} ${props?.class ?? ""}`,
|
|
74
92
|
onClick$: () => {
|
|
75
93
|
open.value = !open.value;
|