josenanodev-react-components-library 0.2.0 → 0.2.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.
@@ -51,6 +51,35 @@ const InputBoxWithConfirmation = ({ onConfirmAction, inputType = "text", adition
51
51
  setCachedValue(event.target.value);
52
52
  setCurrentValue(event.target.value);
53
53
  setFocused(true);
54
+ }, onKeyDown: (event) => {
55
+ console.log(event.key);
56
+ if (event.key === "Enter") {
57
+ if (currentValue) {
58
+ onConfirmAction(currentValue);
59
+ setCachedValue(currentValue);
60
+ }
61
+ setFocused(false);
62
+ if (inputRef.current) {
63
+ inputRef.current.blur();
64
+ }
65
+ }
66
+ else if (event.key === "Tab") {
67
+ if (currentValue) {
68
+ onConfirmAction(currentValue);
69
+ setCachedValue(currentValue);
70
+ }
71
+ setFocused(false);
72
+ if (inputRef.current) {
73
+ inputRef.current.blur();
74
+ }
75
+ }
76
+ else if (event.key === "Escape") {
77
+ setCurrentValue(cachedValue);
78
+ setFocused(false);
79
+ if (inputRef.current) {
80
+ inputRef.current.blur();
81
+ }
82
+ }
54
83
  } }),
55
84
  focused ? (react_1.default.createElement("button", { className: "button-for-input-box-with-confirmation", onClick: () => {
56
85
  if (currentValue) {
@@ -23,6 +23,35 @@ const InputBoxWithConfirmation = ({ onConfirmAction, inputType = "text", adition
23
23
  setCachedValue(event.target.value);
24
24
  setCurrentValue(event.target.value);
25
25
  setFocused(true);
26
+ }, onKeyDown: (event) => {
27
+ console.log(event.key);
28
+ if (event.key === "Enter") {
29
+ if (currentValue) {
30
+ onConfirmAction(currentValue);
31
+ setCachedValue(currentValue);
32
+ }
33
+ setFocused(false);
34
+ if (inputRef.current) {
35
+ inputRef.current.blur();
36
+ }
37
+ }
38
+ else if (event.key === "Tab") {
39
+ if (currentValue) {
40
+ onConfirmAction(currentValue);
41
+ setCachedValue(currentValue);
42
+ }
43
+ setFocused(false);
44
+ if (inputRef.current) {
45
+ inputRef.current.blur();
46
+ }
47
+ }
48
+ else if (event.key === "Escape") {
49
+ setCurrentValue(cachedValue);
50
+ setFocused(false);
51
+ if (inputRef.current) {
52
+ inputRef.current.blur();
53
+ }
54
+ }
26
55
  } }),
27
56
  focused ? (React.createElement("button", { className: "button-for-input-box-with-confirmation", onClick: () => {
28
57
  if (currentValue) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "josenanodev-react-components-library",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "author": {
5
5
  "name": "Jose Carlos Cardenas Martinez"
6
6
  },