@etsoo/react 1.4.26 → 1.4.30
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.
package/lib/mu/SearchBar.js
CHANGED
|
@@ -52,6 +52,7 @@ const setChildState = (child, enabled) => {
|
|
|
52
52
|
* @returns Component
|
|
53
53
|
*/
|
|
54
54
|
export function SearchBar(props) {
|
|
55
|
+
var _a;
|
|
55
56
|
// Destruct
|
|
56
57
|
const { className, fields, innerHeight = 40, onSubmit } = props;
|
|
57
58
|
// Labels
|
|
@@ -64,11 +65,14 @@ export function SearchBar(props) {
|
|
|
64
65
|
// Drawer open / close
|
|
65
66
|
const [open, updateOpen] = React.useState(false);
|
|
66
67
|
// State
|
|
67
|
-
const state = React.useRef({}).current;
|
|
68
|
+
const state = React.useRef({ hasMore: true }).current;
|
|
69
|
+
const lastMaxWidth = (_a = state.lastMaxWidth) !== null && _a !== void 0 ? _a : 9999;
|
|
68
70
|
// Watch container
|
|
69
71
|
const { dimensions } = useDimensions(1, (target, rect) => {
|
|
70
72
|
// Same logic from resetButtonRef
|
|
71
|
-
|
|
73
|
+
console.log('useDimensions', state.hasMore, rect.width, lastMaxWidth);
|
|
74
|
+
if (rect.width === lastMaxWidth ||
|
|
75
|
+
(!state.hasMore && rect.width > lastMaxWidth))
|
|
72
76
|
return false;
|
|
73
77
|
// Len
|
|
74
78
|
const len = target.children.length;
|
|
@@ -95,8 +99,10 @@ export function SearchBar(props) {
|
|
|
95
99
|
containerRect.width < 10)
|
|
96
100
|
return;
|
|
97
101
|
// Container width
|
|
102
|
+
console.log('resetButtonRef', state.hasMore, containerRect.width, lastMaxWidth);
|
|
98
103
|
let maxWidth = containerRect.width;
|
|
99
|
-
if (maxWidth ===
|
|
104
|
+
if (maxWidth === lastMaxWidth ||
|
|
105
|
+
(!state.hasMore && maxWidth > lastMaxWidth)) {
|
|
100
106
|
return;
|
|
101
107
|
}
|
|
102
108
|
state.lastMaxWidth = maxWidth;
|
|
@@ -158,6 +164,7 @@ export function SearchBar(props) {
|
|
|
158
164
|
}
|
|
159
165
|
}
|
|
160
166
|
// Show or hide more button
|
|
167
|
+
state.hasMore = hasMore;
|
|
161
168
|
setElementVisible(buttonMore, hasMore);
|
|
162
169
|
setElementVisible(resetButton, true);
|
|
163
170
|
// Update menu start index
|
package/package.json
CHANGED
package/src/mu/SearchBar.tsx
CHANGED
|
@@ -105,12 +105,19 @@ export function SearchBar(props: SearchBarProps) {
|
|
|
105
105
|
moreForm?: HTMLFormElement;
|
|
106
106
|
submitSeed?: number;
|
|
107
107
|
lastMaxWidth?: number;
|
|
108
|
-
|
|
108
|
+
hasMore: boolean;
|
|
109
|
+
}>({ hasMore: true }).current;
|
|
110
|
+
const lastMaxWidth = state.lastMaxWidth ?? 9999;
|
|
109
111
|
|
|
110
112
|
// Watch container
|
|
111
113
|
const { dimensions } = useDimensions(1, (target, rect) => {
|
|
112
114
|
// Same logic from resetButtonRef
|
|
113
|
-
|
|
115
|
+
console.log('useDimensions', state.hasMore, rect.width, lastMaxWidth);
|
|
116
|
+
if (
|
|
117
|
+
rect.width === lastMaxWidth ||
|
|
118
|
+
(!state.hasMore && rect.width > lastMaxWidth)
|
|
119
|
+
)
|
|
120
|
+
return false;
|
|
114
121
|
|
|
115
122
|
// Len
|
|
116
123
|
const len = target.children.length;
|
|
@@ -142,8 +149,17 @@ export function SearchBar(props: SearchBarProps) {
|
|
|
142
149
|
return;
|
|
143
150
|
|
|
144
151
|
// Container width
|
|
152
|
+
console.log(
|
|
153
|
+
'resetButtonRef',
|
|
154
|
+
state.hasMore,
|
|
155
|
+
containerRect.width,
|
|
156
|
+
lastMaxWidth
|
|
157
|
+
);
|
|
145
158
|
let maxWidth = containerRect.width;
|
|
146
|
-
if (
|
|
159
|
+
if (
|
|
160
|
+
maxWidth === lastMaxWidth ||
|
|
161
|
+
(!state.hasMore && maxWidth > lastMaxWidth)
|
|
162
|
+
) {
|
|
147
163
|
return;
|
|
148
164
|
}
|
|
149
165
|
state.lastMaxWidth = maxWidth;
|
|
@@ -220,6 +236,7 @@ export function SearchBar(props: SearchBarProps) {
|
|
|
220
236
|
}
|
|
221
237
|
|
|
222
238
|
// Show or hide more button
|
|
239
|
+
state.hasMore = hasMore;
|
|
223
240
|
setElementVisible(buttonMore, hasMore);
|
|
224
241
|
setElementVisible(resetButton, true);
|
|
225
242
|
|