@gustavo-valsechi/client 1.4.93 → 1.4.95
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.
|
@@ -41,14 +41,16 @@ var import_contexts = require("../../../../../contexts");
|
|
|
41
41
|
var import_lodash = __toESM(require("lodash"));
|
|
42
42
|
var import_options = __toESM(require("./options"));
|
|
43
43
|
function InputSelect(props) {
|
|
44
|
-
const inputRef = (0, import_react.useRef)(
|
|
44
|
+
const inputRef = (0, import_react.useRef)(null);
|
|
45
45
|
const target = (0, import_contexts.useTarget)();
|
|
46
46
|
const [focus, setFocus] = (0, import_react.useState)(false);
|
|
47
47
|
const register = (props.register || ((name) => ({})))(props.name || "");
|
|
48
48
|
(0, import_react.useEffect)(() => {
|
|
49
|
+
if (!(inputRef == null ? void 0 : inputRef.current)) return;
|
|
50
|
+
console.log(inputRef == null ? void 0 : inputRef.current);
|
|
49
51
|
target.add({ ref: inputRef, component: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_options.default, { ...props, inputRef, register }) });
|
|
50
52
|
return () => target.remove(inputRef);
|
|
51
|
-
}, []);
|
|
53
|
+
}, [inputRef]);
|
|
52
54
|
const onBlur = (event) => {
|
|
53
55
|
setFocus(false);
|
|
54
56
|
if (register.onBlur) register.onBlur(event);
|
|
@@ -72,10 +74,10 @@ function InputSelect(props) {
|
|
|
72
74
|
"input",
|
|
73
75
|
{
|
|
74
76
|
...import_lodash.default.omit(props, ["className", "register", "mask", "setValue"]),
|
|
75
|
-
ref: inputRef,
|
|
76
77
|
type: "text",
|
|
77
78
|
maxLength: props.maxLength || 255,
|
|
78
79
|
...register,
|
|
80
|
+
ref: inputRef,
|
|
79
81
|
onChange,
|
|
80
82
|
onFocus,
|
|
81
83
|
onBlur
|
|
@@ -8,14 +8,16 @@ import { useTarget } from "../../../../../contexts";
|
|
|
8
8
|
import _ from "lodash";
|
|
9
9
|
import InputSelectOption from "./options";
|
|
10
10
|
function InputSelect(props) {
|
|
11
|
-
const inputRef = useRef(
|
|
11
|
+
const inputRef = useRef(null);
|
|
12
12
|
const target = useTarget();
|
|
13
13
|
const [focus, setFocus] = useState(false);
|
|
14
14
|
const register = (props.register || ((name) => ({})))(props.name || "");
|
|
15
15
|
useEffect(() => {
|
|
16
|
+
if (!(inputRef == null ? void 0 : inputRef.current)) return;
|
|
17
|
+
console.log(inputRef == null ? void 0 : inputRef.current);
|
|
16
18
|
target.add({ ref: inputRef, component: /* @__PURE__ */ jsx(InputSelectOption, { ...props, inputRef, register }) });
|
|
17
19
|
return () => target.remove(inputRef);
|
|
18
|
-
}, []);
|
|
20
|
+
}, [inputRef]);
|
|
19
21
|
const onBlur = (event) => {
|
|
20
22
|
setFocus(false);
|
|
21
23
|
if (register.onBlur) register.onBlur(event);
|
|
@@ -39,10 +41,10 @@ function InputSelect(props) {
|
|
|
39
41
|
"input",
|
|
40
42
|
{
|
|
41
43
|
..._.omit(props, ["className", "register", "mask", "setValue"]),
|
|
42
|
-
ref: inputRef,
|
|
43
44
|
type: "text",
|
|
44
45
|
maxLength: props.maxLength || 255,
|
|
45
46
|
...register,
|
|
47
|
+
ref: inputRef,
|
|
46
48
|
onChange,
|
|
47
49
|
onFocus,
|
|
48
50
|
onBlur
|
|
@@ -47,10 +47,6 @@ const TargetProviderContainer = ({ children }) => {
|
|
|
47
47
|
const elementFocusable = (target, index) => {
|
|
48
48
|
const focusableTags = ["input", "select", "textarea", "button"];
|
|
49
49
|
const isFocusable = import_lodash.default.some(focusableTags, (tag) => target.ref.current.tagName.toLowerCase() === tag);
|
|
50
|
-
console.log("tagName", target.ref.current.tagName.toLowerCase());
|
|
51
|
-
console.log("isFocusable", isFocusable);
|
|
52
|
-
console.log("target.ref.current", target.ref.current);
|
|
53
|
-
console.log("inputRef.current[index]", inputRef.current[index]);
|
|
54
50
|
if (isFocusable) return target.ref.current;
|
|
55
51
|
return inputRef.current[index];
|
|
56
52
|
};
|
|
@@ -104,8 +100,22 @@ const TargetProviderContainer = ({ children }) => {
|
|
|
104
100
|
import_lodash.default.forEach(targets, (target, index) => {
|
|
105
101
|
var _a;
|
|
106
102
|
const element = (_a = target.ref) == null ? void 0 : _a.current;
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
if (!(element == null ? void 0 : element.addEventListener)) return;
|
|
104
|
+
element.addEventListener("click", () => {
|
|
105
|
+
const targetElement = import_lodash.default.find(containerRef.current, (data, i) => i === index);
|
|
106
|
+
if (!targetElement) return;
|
|
107
|
+
const focusable = elementFocusable(target, index);
|
|
108
|
+
if (focusable === document.activeElement) {
|
|
109
|
+
close(targetElement);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const coords = getCoords(element);
|
|
113
|
+
open(targetElement, coords);
|
|
114
|
+
focusable.focus();
|
|
115
|
+
});
|
|
116
|
+
element.addEventListener("resize", () => {
|
|
117
|
+
import_lodash.default.forEach(containerRef.current, (elementRef) => close(elementRef));
|
|
118
|
+
});
|
|
109
119
|
});
|
|
110
120
|
}, [targets, inputRef, containerRef]);
|
|
111
121
|
const getCoords = (target) => {
|
|
@@ -13,10 +13,6 @@ const TargetProviderContainer = ({ children }) => {
|
|
|
13
13
|
const elementFocusable = (target, index) => {
|
|
14
14
|
const focusableTags = ["input", "select", "textarea", "button"];
|
|
15
15
|
const isFocusable = _.some(focusableTags, (tag) => target.ref.current.tagName.toLowerCase() === tag);
|
|
16
|
-
console.log("tagName", target.ref.current.tagName.toLowerCase());
|
|
17
|
-
console.log("isFocusable", isFocusable);
|
|
18
|
-
console.log("target.ref.current", target.ref.current);
|
|
19
|
-
console.log("inputRef.current[index]", inputRef.current[index]);
|
|
20
16
|
if (isFocusable) return target.ref.current;
|
|
21
17
|
return inputRef.current[index];
|
|
22
18
|
};
|
|
@@ -70,8 +66,22 @@ const TargetProviderContainer = ({ children }) => {
|
|
|
70
66
|
_.forEach(targets, (target, index) => {
|
|
71
67
|
var _a;
|
|
72
68
|
const element = (_a = target.ref) == null ? void 0 : _a.current;
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
if (!(element == null ? void 0 : element.addEventListener)) return;
|
|
70
|
+
element.addEventListener("click", () => {
|
|
71
|
+
const targetElement = _.find(containerRef.current, (data, i) => i === index);
|
|
72
|
+
if (!targetElement) return;
|
|
73
|
+
const focusable = elementFocusable(target, index);
|
|
74
|
+
if (focusable === document.activeElement) {
|
|
75
|
+
close(targetElement);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const coords = getCoords(element);
|
|
79
|
+
open(targetElement, coords);
|
|
80
|
+
focusable.focus();
|
|
81
|
+
});
|
|
82
|
+
element.addEventListener("resize", () => {
|
|
83
|
+
_.forEach(containerRef.current, (elementRef) => close(elementRef));
|
|
84
|
+
});
|
|
75
85
|
});
|
|
76
86
|
}, [targets, inputRef, containerRef]);
|
|
77
87
|
const getCoords = (target) => {
|