@blockle/blocks 0.8.3 → 0.8.5

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/dist/index.cjs CHANGED
@@ -415,16 +415,18 @@ const usePreventBodyScroll = (enabled = true) => {
415
415
  };
416
416
  }, [enabled]);
417
417
  };
418
+ const isBrowser = typeof window !== "undefined";
418
419
  const useRestoreFocus = (active) => {
419
- const [target, setTarget] = react.useState(null);
420
- useIsomorphicLayoutEffect(() => {
421
- if (active && !target) {
422
- setTarget(document.activeElement);
423
- }
424
- }, [active]);
420
+ const target = react.useRef(null);
421
+ if (isBrowser && active && !target.current) {
422
+ target.current = document.activeElement;
423
+ }
425
424
  react.useEffect(() => {
426
- if (!active && target instanceof HTMLElement) {
427
- target.focus();
425
+ if (target.current && !active && target.current instanceof HTMLElement) {
426
+ target.current.focus();
427
+ }
428
+ if (!active) {
429
+ target.current = null;
428
430
  }
429
431
  }, [active]);
430
432
  };
package/dist/index.mjs CHANGED
@@ -415,16 +415,18 @@ const usePreventBodyScroll = (enabled = true) => {
415
415
  };
416
416
  }, [enabled]);
417
417
  };
418
+ const isBrowser = typeof window !== "undefined";
418
419
  const useRestoreFocus = (active) => {
419
- const [target, setTarget] = useState(null);
420
- useIsomorphicLayoutEffect(() => {
421
- if (active && !target) {
422
- setTarget(document.activeElement);
423
- }
424
- }, [active]);
420
+ const target = useRef(null);
421
+ if (isBrowser && active && !target.current) {
422
+ target.current = document.activeElement;
423
+ }
425
424
  useEffect(() => {
426
- if (!active && target instanceof HTMLElement) {
427
- target.focus();
425
+ if (target.current && !active && target.current instanceof HTMLElement) {
426
+ target.current.focus();
427
+ }
428
+ if (!active) {
429
+ target.current = null;
428
430
  }
429
431
  }, [active]);
430
432
  };
@@ -425,7 +425,7 @@ type ComponentTheme<T extends RecordLike> = ComponentThemeToStyles<T> & {
425
425
  defaultVariants?: ComponentThemeDefaultVariants<T>;
426
426
  };
427
427
  type ThemeComponentsStyles = {
428
- [K in keyof ComponentThemes]: ComponentTheme<ComponentThemes[K]>;
428
+ [K in keyof ComponentThemes]?: ComponentTheme<ComponentThemes[K]>;
429
429
  };
430
430
  declare function makeComponentTheme<T extends keyof ThemeComponentsStyles>(component: T, componentTheme: ThemeComponentsStyles[T]): ThemeComponentsStyles[T];
431
431
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockle/blocks",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "description": "Blocks design system",
5
5
  "repository": "git@github.com:Blockle/blocks.git",
6
6
  "license": "MIT",