@geckoui/geckoui 2.0.3 → 2.0.4

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.d.mts CHANGED
@@ -5552,6 +5552,16 @@ interface DrawerProps {
5552
5552
  * Default is true
5553
5553
  * */
5554
5554
  dismissOnEscape?: boolean;
5555
+ /**
5556
+ * Keep the children in the DOM while the drawer is closed.
5557
+ * By default they unmount once the slide out finishes, so a form inside starts fresh on
5558
+ * every open and an `autoFocus` field only takes focus when it is shown.
5559
+ * A closed drawer is inert either way: nothing in it can be focused or reached by
5560
+ * assistive technology.
5561
+ *
5562
+ * Default: false
5563
+ * */
5564
+ keepMounted?: boolean;
5555
5565
  /**
5556
5566
  * Inline styles for the drawer root.
5557
5567
  * `GeckoUIProvider` uses it to stack drawers opened with `Drawer.show()`.
@@ -5579,6 +5589,10 @@ interface DrawerProps {
5579
5589
  * </Drawer>
5580
5590
  * ```
5581
5591
  *
5592
+ * Closed drawers unmount their children once the slide out finishes, so a form inside
5593
+ * starts fresh on every open and an `autoFocus` field only takes focus when it is shown.
5594
+ * Pass `keepMounted` to keep the children alive while closed instead.
5595
+ *
5582
5596
  * @example
5583
5597
  * Mobile navigation menu:
5584
5598
  *
@@ -5599,7 +5613,7 @@ interface DrawerProps {
5599
5613
  * </Drawer>
5600
5614
  * ```
5601
5615
  */
5602
- declare function Drawer({ open, allowClickOutside, onClose, hideBackdrop, placement, backdropClassName, className, children, dismissOnEscape, style }: DrawerProps): react_jsx_runtime.JSX.Element;
5616
+ declare function Drawer({ open, allowClickOutside, onClose, hideBackdrop, placement, backdropClassName, className, children, dismissOnEscape, keepMounted, style }: DrawerProps): react_jsx_runtime.JSX.Element;
5603
5617
  declare namespace Drawer {
5604
5618
  var show: (node: ReactNode, options?: Omit<DrawerProps, "open" | "children">) => string;
5605
5619
  var dismiss: (id?: string) => void;
package/dist/index.d.ts CHANGED
@@ -5552,6 +5552,16 @@ interface DrawerProps {
5552
5552
  * Default is true
5553
5553
  * */
5554
5554
  dismissOnEscape?: boolean;
5555
+ /**
5556
+ * Keep the children in the DOM while the drawer is closed.
5557
+ * By default they unmount once the slide out finishes, so a form inside starts fresh on
5558
+ * every open and an `autoFocus` field only takes focus when it is shown.
5559
+ * A closed drawer is inert either way: nothing in it can be focused or reached by
5560
+ * assistive technology.
5561
+ *
5562
+ * Default: false
5563
+ * */
5564
+ keepMounted?: boolean;
5555
5565
  /**
5556
5566
  * Inline styles for the drawer root.
5557
5567
  * `GeckoUIProvider` uses it to stack drawers opened with `Drawer.show()`.
@@ -5579,6 +5589,10 @@ interface DrawerProps {
5579
5589
  * </Drawer>
5580
5590
  * ```
5581
5591
  *
5592
+ * Closed drawers unmount their children once the slide out finishes, so a form inside
5593
+ * starts fresh on every open and an `autoFocus` field only takes focus when it is shown.
5594
+ * Pass `keepMounted` to keep the children alive while closed instead.
5595
+ *
5582
5596
  * @example
5583
5597
  * Mobile navigation menu:
5584
5598
  *
@@ -5599,7 +5613,7 @@ interface DrawerProps {
5599
5613
  * </Drawer>
5600
5614
  * ```
5601
5615
  */
5602
- declare function Drawer({ open, allowClickOutside, onClose, hideBackdrop, placement, backdropClassName, className, children, dismissOnEscape, style }: DrawerProps): react_jsx_runtime.JSX.Element;
5616
+ declare function Drawer({ open, allowClickOutside, onClose, hideBackdrop, placement, backdropClassName, className, children, dismissOnEscape, keepMounted, style }: DrawerProps): react_jsx_runtime.JSX.Element;
5603
5617
  declare namespace Drawer {
5604
5618
  var show: (node: ReactNode, options?: Omit<DrawerProps, "open" | "children">) => string;
5605
5619
  var dismiss: (id?: string) => void;
package/dist/index.js CHANGED
@@ -9529,6 +9529,7 @@ function Drawer({
9529
9529
  className,
9530
9530
  children,
9531
9531
  dismissOnEscape = true,
9532
+ keepMounted = false,
9532
9533
  style
9533
9534
  }) {
9534
9535
  const drawerRef = (0, import_react81.useRef)(null);
@@ -9540,14 +9541,18 @@ function Drawer({
9540
9541
  const ready = readyFor === placement;
9541
9542
  const visible = open && ready;
9542
9543
  const [closing, setClosing] = (0, import_react81.useState)(false);
9543
- const wasOpen = (0, import_react81.useRef)(open);
9544
+ const [prevOpen, setPrevOpen] = (0, import_react81.useState)(open);
9545
+ if (prevOpen !== open) {
9546
+ setPrevOpen(open);
9547
+ setClosing(!open);
9548
+ }
9544
9549
  (0, import_react81.useEffect)(() => {
9545
- if (wasOpen.current === open) return;
9546
- wasOpen.current = open;
9547
- if (open) return;
9548
- setClosing(true);
9550
+ if (!closing) return;
9549
9551
  const timer = setTimeout(() => setClosing(false), OVERLAY_ANIMATION_DURATION);
9550
9552
  return () => clearTimeout(timer);
9553
+ }, [closing]);
9554
+ (0, import_react81.useLayoutEffect)(() => {
9555
+ if (drawerRef.current) drawerRef.current.inert = !open;
9551
9556
  }, [open]);
9552
9557
  const onCloseRef = (0, import_react81.useRef)(onClose);
9553
9558
  onCloseRef.current = onClose;
@@ -9583,7 +9588,7 @@ function Drawer({
9583
9588
  className: classNames("GeckoUIDrawer__drawer", className),
9584
9589
  role: "dialog",
9585
9590
  "aria-modal": !allowClickOutside,
9586
- children
9591
+ children: (open || closing || keepMounted) && children
9587
9592
  }
9588
9593
  )
9589
9594
  ] });
package/dist/index.mjs CHANGED
@@ -9392,7 +9392,7 @@ import { useCallback as useCallback10, useEffect as useEffect23, useRef as useRe
9392
9392
  import { createPortal as createPortal2 } from "react-dom";
9393
9393
 
9394
9394
  // src/components/Drawer/Drawer.tsx
9395
- import { useCallback as useCallback9, useEffect as useEffect22, useRef as useRef33, useState as useState29 } from "react";
9395
+ import { useCallback as useCallback9, useEffect as useEffect22, useLayoutEffect as useLayoutEffect2, useRef as useRef33, useState as useState29 } from "react";
9396
9396
  import { jsx as jsx97, jsxs as jsxs46 } from "react/jsx-runtime";
9397
9397
  function Drawer({
9398
9398
  open = false,
@@ -9404,6 +9404,7 @@ function Drawer({
9404
9404
  className,
9405
9405
  children,
9406
9406
  dismissOnEscape = true,
9407
+ keepMounted = false,
9407
9408
  style
9408
9409
  }) {
9409
9410
  const drawerRef = useRef33(null);
@@ -9415,14 +9416,18 @@ function Drawer({
9415
9416
  const ready = readyFor === placement;
9416
9417
  const visible = open && ready;
9417
9418
  const [closing, setClosing] = useState29(false);
9418
- const wasOpen = useRef33(open);
9419
+ const [prevOpen, setPrevOpen] = useState29(open);
9420
+ if (prevOpen !== open) {
9421
+ setPrevOpen(open);
9422
+ setClosing(!open);
9423
+ }
9419
9424
  useEffect22(() => {
9420
- if (wasOpen.current === open) return;
9421
- wasOpen.current = open;
9422
- if (open) return;
9423
- setClosing(true);
9425
+ if (!closing) return;
9424
9426
  const timer = setTimeout(() => setClosing(false), OVERLAY_ANIMATION_DURATION);
9425
9427
  return () => clearTimeout(timer);
9428
+ }, [closing]);
9429
+ useLayoutEffect2(() => {
9430
+ if (drawerRef.current) drawerRef.current.inert = !open;
9426
9431
  }, [open]);
9427
9432
  const onCloseRef = useRef33(onClose);
9428
9433
  onCloseRef.current = onClose;
@@ -9458,7 +9463,7 @@ function Drawer({
9458
9463
  className: classNames("GeckoUIDrawer__drawer", className),
9459
9464
  role: "dialog",
9460
9465
  "aria-modal": !allowClickOutside,
9461
- children
9466
+ children: (open || closing || keepMounted) && children
9462
9467
  }
9463
9468
  )
9464
9469
  ] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geckoui/geckoui",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "license": "MIT",
5
5
  "description": "The only thing our Gecko eats is bugs!",
6
6
  "keywords": [