@dbcdk/react-components 0.0.112 → 0.0.114
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.
|
@@ -72,7 +72,6 @@
|
|
|
72
72
|
|
|
73
73
|
.value {
|
|
74
74
|
font-size: var(--font-size-md);
|
|
75
|
-
font-weight: var(--font-weight-bold);
|
|
76
75
|
line-height: 1;
|
|
77
76
|
font-variant-numeric: tabular-nums;
|
|
78
77
|
max-width: 100%;
|
|
@@ -87,7 +86,7 @@
|
|
|
87
86
|
}
|
|
88
87
|
|
|
89
88
|
.tile[data-size='sm'] .value {
|
|
90
|
-
font-size: var(--font-size-
|
|
89
|
+
font-size: var(--font-size-xs);
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
.tile[data-size='lg'] .label {
|
|
@@ -87,14 +87,23 @@ const SearchBox = react.forwardRef(function SearchBoxInner({
|
|
|
87
87
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
88
88
|
}
|
|
89
89
|
}, [enableHotkey]);
|
|
90
|
+
const hasInitialTemplate = initialTemplate !== void 0 && initialTemplate !== null;
|
|
91
|
+
const hasQuery = draft.trim().length > 0;
|
|
92
|
+
const canShowPopover = hasQuery || hasInitialTemplate;
|
|
90
93
|
const handleChange = react.useCallback(
|
|
91
94
|
(e) => {
|
|
92
|
-
var _a2, _b;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
var _a2, _b, _c;
|
|
96
|
+
const nextDraft = e.target.value;
|
|
97
|
+
const nextHasQuery = nextDraft.trim().length > 0;
|
|
98
|
+
setDraft(nextDraft);
|
|
99
|
+
if (nextHasQuery || hasInitialTemplate) {
|
|
100
|
+
if (!((_a2 = popoverRef.current) == null ? void 0 : _a2.isOpen())) (_b = popoverRef.current) == null ? void 0 : _b.open();
|
|
101
|
+
} else {
|
|
102
|
+
(_c = popoverRef.current) == null ? void 0 : _c.close();
|
|
103
|
+
}
|
|
95
104
|
onChange == null ? void 0 : onChange(e);
|
|
96
105
|
},
|
|
97
|
-
[onChange]
|
|
106
|
+
[hasInitialTemplate, onChange]
|
|
98
107
|
);
|
|
99
108
|
const handleSelect = react.useCallback(
|
|
100
109
|
(item) => {
|
|
@@ -119,6 +128,11 @@ const SearchBox = react.forwardRef(function SearchBoxInner({
|
|
|
119
128
|
react.useEffect(() => {
|
|
120
129
|
setActiveIndex(null);
|
|
121
130
|
}, [result]);
|
|
131
|
+
react.useEffect(() => {
|
|
132
|
+
var _a2;
|
|
133
|
+
if (canShowPopover) return;
|
|
134
|
+
(_a2 = popoverRef.current) == null ? void 0 : _a2.close();
|
|
135
|
+
}, [canShowPopover]);
|
|
122
136
|
const showInputIcon = !onButtonClick || !!buttonLabel || !!buttonIcon;
|
|
123
137
|
const trailingButtonIcon = onButtonClick && !buttonLabel && !buttonIcon ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Search, {}) : buttonIcon;
|
|
124
138
|
const trailingButtonAriaLabel = buttonAriaLabel != null ? buttonAriaLabel : onButtonClick && !buttonLabel ? "S\xF8g" : void 0;
|
|
@@ -157,7 +171,7 @@ const SearchBox = react.forwardRef(function SearchBoxInner({
|
|
|
157
171
|
}
|
|
158
172
|
);
|
|
159
173
|
}
|
|
160
|
-
const dropdownContent = resultTemplate ? resultTemplate : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
174
|
+
const dropdownContent = !canShowPopover ? null : !hasQuery && hasInitialTemplate ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.resultContainer, children: initialTemplate }) : resultTemplate ? resultTemplate : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
161
175
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
162
176
|
"ul",
|
|
163
177
|
{
|
|
@@ -186,7 +200,7 @@ const SearchBox = react.forwardRef(function SearchBoxInner({
|
|
|
186
200
|
))
|
|
187
201
|
}
|
|
188
202
|
),
|
|
189
|
-
!loading && !(result == null ? void 0 : result.length) && /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.resultContainer, children:
|
|
203
|
+
!loading && !(result == null ? void 0 : result.length) && /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.resultContainer, children: noResultText })
|
|
190
204
|
] });
|
|
191
205
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
192
206
|
"div",
|
|
@@ -208,15 +222,19 @@ const SearchBox = react.forwardRef(function SearchBoxInner({
|
|
|
208
222
|
Input.Input,
|
|
209
223
|
{
|
|
210
224
|
ref: internalInputRef,
|
|
211
|
-
onFocusCapture:
|
|
225
|
+
onFocusCapture: (e) => {
|
|
226
|
+
if (!canShowPopover) return;
|
|
227
|
+
event(e);
|
|
228
|
+
},
|
|
212
229
|
onClick: () => {
|
|
213
230
|
var _a3, _b;
|
|
231
|
+
if (!canShowPopover) return;
|
|
214
232
|
if (!((_a3 = popoverRef.current) == null ? void 0 : _a3.isOpen())) (_b = popoverRef.current) == null ? void 0 : _b.open();
|
|
215
233
|
},
|
|
216
234
|
role: "combobox",
|
|
217
235
|
"aria-haspopup": "listbox",
|
|
218
236
|
"aria-expanded": popoverOpen,
|
|
219
|
-
"aria-controls": listboxId,
|
|
237
|
+
"aria-controls": canShowPopover ? listboxId : void 0,
|
|
220
238
|
"aria-autocomplete": "list",
|
|
221
239
|
"aria-activedescendant": activeOptionId,
|
|
222
240
|
clearAriaLabel: "Ryd s\xF8gning",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { InputVariant } from '../../components/forms/input/Input';
|
|
3
3
|
import { Size } from '../../types/sizes.types';
|
|
4
|
-
type SearchBoxProps<T extends Record<string, unknown>> = {
|
|
4
|
+
export type SearchBoxProps<T extends Record<string, unknown>> = {
|
|
5
5
|
inputWidth?: string | number;
|
|
6
6
|
maxWidth?: string | number;
|
|
7
7
|
inputSize?: Exclude<Size, 'xl'>;
|
|
@@ -81,14 +81,23 @@ const SearchBox = forwardRef(function SearchBoxInner({
|
|
|
81
81
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
82
82
|
}
|
|
83
83
|
}, [enableHotkey]);
|
|
84
|
+
const hasInitialTemplate = initialTemplate !== void 0 && initialTemplate !== null;
|
|
85
|
+
const hasQuery = draft.trim().length > 0;
|
|
86
|
+
const canShowPopover = hasQuery || hasInitialTemplate;
|
|
84
87
|
const handleChange = useCallback(
|
|
85
88
|
(e) => {
|
|
86
|
-
var _a2, _b;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
var _a2, _b, _c;
|
|
90
|
+
const nextDraft = e.target.value;
|
|
91
|
+
const nextHasQuery = nextDraft.trim().length > 0;
|
|
92
|
+
setDraft(nextDraft);
|
|
93
|
+
if (nextHasQuery || hasInitialTemplate) {
|
|
94
|
+
if (!((_a2 = popoverRef.current) == null ? void 0 : _a2.isOpen())) (_b = popoverRef.current) == null ? void 0 : _b.open();
|
|
95
|
+
} else {
|
|
96
|
+
(_c = popoverRef.current) == null ? void 0 : _c.close();
|
|
97
|
+
}
|
|
89
98
|
onChange == null ? void 0 : onChange(e);
|
|
90
99
|
},
|
|
91
|
-
[onChange]
|
|
100
|
+
[hasInitialTemplate, onChange]
|
|
92
101
|
);
|
|
93
102
|
const handleSelect = useCallback(
|
|
94
103
|
(item) => {
|
|
@@ -113,6 +122,11 @@ const SearchBox = forwardRef(function SearchBoxInner({
|
|
|
113
122
|
useEffect(() => {
|
|
114
123
|
setActiveIndex(null);
|
|
115
124
|
}, [result]);
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
var _a2;
|
|
127
|
+
if (canShowPopover) return;
|
|
128
|
+
(_a2 = popoverRef.current) == null ? void 0 : _a2.close();
|
|
129
|
+
}, [canShowPopover]);
|
|
116
130
|
const showInputIcon = !onButtonClick || !!buttonLabel || !!buttonIcon;
|
|
117
131
|
const trailingButtonIcon = onButtonClick && !buttonLabel && !buttonIcon ? /* @__PURE__ */ jsx(Search, {}) : buttonIcon;
|
|
118
132
|
const trailingButtonAriaLabel = buttonAriaLabel != null ? buttonAriaLabel : onButtonClick && !buttonLabel ? "S\xF8g" : void 0;
|
|
@@ -151,7 +165,7 @@ const SearchBox = forwardRef(function SearchBoxInner({
|
|
|
151
165
|
}
|
|
152
166
|
);
|
|
153
167
|
}
|
|
154
|
-
const dropdownContent = resultTemplate ? resultTemplate : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
168
|
+
const dropdownContent = !canShowPopover ? null : !hasQuery && hasInitialTemplate ? /* @__PURE__ */ jsx("div", { className: styles.resultContainer, children: initialTemplate }) : resultTemplate ? resultTemplate : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
155
169
|
/* @__PURE__ */ jsx(
|
|
156
170
|
"ul",
|
|
157
171
|
{
|
|
@@ -180,7 +194,7 @@ const SearchBox = forwardRef(function SearchBoxInner({
|
|
|
180
194
|
))
|
|
181
195
|
}
|
|
182
196
|
),
|
|
183
|
-
!loading && !(result == null ? void 0 : result.length) && /* @__PURE__ */ jsx("div", { className: styles.resultContainer, children:
|
|
197
|
+
!loading && !(result == null ? void 0 : result.length) && /* @__PURE__ */ jsx("div", { className: styles.resultContainer, children: noResultText })
|
|
184
198
|
] });
|
|
185
199
|
return /* @__PURE__ */ jsx(
|
|
186
200
|
"div",
|
|
@@ -202,15 +216,19 @@ const SearchBox = forwardRef(function SearchBoxInner({
|
|
|
202
216
|
Input,
|
|
203
217
|
{
|
|
204
218
|
ref: internalInputRef,
|
|
205
|
-
onFocusCapture:
|
|
219
|
+
onFocusCapture: (e) => {
|
|
220
|
+
if (!canShowPopover) return;
|
|
221
|
+
event(e);
|
|
222
|
+
},
|
|
206
223
|
onClick: () => {
|
|
207
224
|
var _a3, _b;
|
|
225
|
+
if (!canShowPopover) return;
|
|
208
226
|
if (!((_a3 = popoverRef.current) == null ? void 0 : _a3.isOpen())) (_b = popoverRef.current) == null ? void 0 : _b.open();
|
|
209
227
|
},
|
|
210
228
|
role: "combobox",
|
|
211
229
|
"aria-haspopup": "listbox",
|
|
212
230
|
"aria-expanded": popoverOpen,
|
|
213
|
-
"aria-controls": listboxId,
|
|
231
|
+
"aria-controls": canShowPopover ? listboxId : void 0,
|
|
214
232
|
"aria-autocomplete": "list",
|
|
215
233
|
"aria-activedescendant": activeOptionId,
|
|
216
234
|
clearAriaLabel: "Ryd s\xF8gning",
|