@swan-io/shared-business 8.13.0 → 8.13.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.
- package/package.json +1 -1
- package/src/components/ChoicePicker.js +34 -22
package/package.json
CHANGED
|
@@ -112,11 +112,14 @@ export const ChoicePicker = ({ tile = true, items, getId = identity, large = fal
|
|
|
112
112
|
return;
|
|
113
113
|
}
|
|
114
114
|
// auto scroll to selected value on mobile
|
|
115
|
-
const
|
|
115
|
+
const container = containerRef.current;
|
|
116
|
+
if (container == null) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
116
119
|
const index = items.findIndex(item => value === item);
|
|
117
|
-
if (index !== -1 &&
|
|
118
|
-
const width =
|
|
119
|
-
|
|
120
|
+
if (index !== -1 && container.element != null) {
|
|
121
|
+
const width = container.element.offsetWidth;
|
|
122
|
+
container.scrollTo({ x: index * width, animated: false });
|
|
120
123
|
}
|
|
121
124
|
// if no value is selected, select first item
|
|
122
125
|
if (value == null && items[0] != null) {
|
|
@@ -129,10 +132,13 @@ export const ChoicePicker = ({ tile = true, items, getId = identity, large = fal
|
|
|
129
132
|
if (desktop) {
|
|
130
133
|
return;
|
|
131
134
|
}
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
|
|
135
|
+
const container = containerRef.current;
|
|
136
|
+
if (container == null) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (container.element != null) {
|
|
140
|
+
const scrollLeft = container.element.scrollLeft;
|
|
141
|
+
const width = container.element.offsetWidth;
|
|
136
142
|
const index = clampValue(0, items.length - 1)(Math.round(scrollLeft / width));
|
|
137
143
|
const item = items[index];
|
|
138
144
|
if (item != null) {
|
|
@@ -146,37 +152,43 @@ export const ChoicePicker = ({ tile = true, items, getId = identity, large = fal
|
|
|
146
152
|
};
|
|
147
153
|
const onPressPrevious = () => {
|
|
148
154
|
var _a;
|
|
149
|
-
const
|
|
150
|
-
if (
|
|
151
|
-
|
|
152
|
-
|
|
155
|
+
const container = containerRef.current;
|
|
156
|
+
if (container == null) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (container.element != null) {
|
|
160
|
+
const scrollLeft = container.element.scrollLeft;
|
|
161
|
+
const width = container.element.offsetWidth;
|
|
153
162
|
const index = Math.round(scrollLeft / width);
|
|
154
163
|
const previousIndex = Math.max(0, index - 1);
|
|
155
164
|
// remove scroll snap during scroll animation to avoid weird behavior on older browsers
|
|
156
|
-
|
|
165
|
+
container.element.style.scrollSnapType = "none";
|
|
157
166
|
(_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({ x: previousIndex * width, animated: true });
|
|
158
|
-
detectScrollAnimationEnd(
|
|
167
|
+
detectScrollAnimationEnd(container.element).onResolve(() => {
|
|
159
168
|
// set back scroll snap
|
|
160
169
|
// @ts-expect-error
|
|
161
|
-
|
|
170
|
+
container.element.style.scrollSnapType = null;
|
|
162
171
|
});
|
|
163
172
|
}
|
|
164
173
|
};
|
|
165
174
|
const onPressNext = () => {
|
|
166
175
|
var _a;
|
|
167
|
-
const
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
176
|
+
const container = containerRef.current;
|
|
177
|
+
if (container == null) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (container.element != null) {
|
|
181
|
+
const scrollLeft = container.element.scrollLeft;
|
|
182
|
+
const width = container.element.offsetWidth;
|
|
171
183
|
const index = Math.round(scrollLeft / width);
|
|
172
184
|
const nextIndex = Math.min(items.length - 1, index + 1);
|
|
173
185
|
// remove scroll snap during scroll animation to avoid weird behavior on older browsers
|
|
174
|
-
|
|
186
|
+
container.element.style.scrollSnapType = "none";
|
|
175
187
|
(_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({ x: nextIndex * width, animated: true });
|
|
176
|
-
detectScrollAnimationEnd(
|
|
188
|
+
detectScrollAnimationEnd(container.element).onResolve(() => {
|
|
177
189
|
// set back scroll snap
|
|
178
190
|
// @ts-expect-error
|
|
179
|
-
|
|
191
|
+
container.element.style.scrollSnapType = null;
|
|
180
192
|
});
|
|
181
193
|
}
|
|
182
194
|
};
|