@hestia-earth/ui-components 0.31.29 → 0.31.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/common/utils.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const filterParams: (obj: any) => {
|
|
|
15
15
|
export declare const waitFor: (variable: string, callback: () => void) => void | NodeJS.Timeout;
|
|
16
16
|
export declare const bottom: (element: HTMLElement) => number;
|
|
17
17
|
export declare const isScrolledBelow: (element: HTMLElement) => boolean;
|
|
18
|
-
export declare const scrollToEl: (id: string, retries?: number) => void;
|
|
18
|
+
export declare const scrollToEl: (id: string | Element, args?: ScrollIntoViewOptions, retries?: number) => void;
|
|
19
19
|
export declare const scrollTop: () => void;
|
|
20
20
|
export declare const safeJSONParse: <T>(value: string, defaultValue?: any) => any;
|
|
21
21
|
export declare const safeJSONStringify: (value: string) => string;
|
|
@@ -132,9 +132,11 @@ const filterParams = (obj) => {
|
|
|
132
132
|
const waitFor = (variable, callback) => get(window, variable, false) ? callback() : setTimeout(() => waitFor(variable, callback), 100);
|
|
133
133
|
const bottom = (element) => element.offsetTop + element.getBoundingClientRect().height;
|
|
134
134
|
const isScrolledBelow = (element) => (element ? window.scrollY > bottom(element) : false);
|
|
135
|
-
const scrollToEl = (id,
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
const scrollToEl = (id, args = {
|
|
136
|
+
behavior: 'smooth'
|
|
137
|
+
}, retries = 0) => {
|
|
138
|
+
const el = typeof id === 'string' ? document.getElementById(id) : id;
|
|
139
|
+
setTimeout(() => (el ? el.scrollIntoView(args) : retries < 10 ? scrollToEl(id, args, retries + 1) : null), 100);
|
|
138
140
|
};
|
|
139
141
|
const scrollTop = () => window.scrollTo(0, 0);
|
|
140
142
|
const safeJSONParse = (value, defaultValue) => {
|
|
@@ -9340,7 +9342,7 @@ const focusFirstGroupError = (element) => {
|
|
|
9340
9342
|
*/
|
|
9341
9343
|
const focusFirstError = (element) => {
|
|
9342
9344
|
const firstError = element.querySelectorAll('.is-error-danger')?.[0] || element.querySelectorAll('.is-error-warning')?.[0];
|
|
9343
|
-
return firstError ? firstError
|
|
9345
|
+
return firstError ? scrollToEl(firstError, { behavior: 'smooth', block: 'center' }) : focusFirstGroupError(element);
|
|
9344
9346
|
};
|
|
9345
9347
|
class FilesFormComponent {
|
|
9346
9348
|
constructor() {
|