@samline/drawer 2.0.6 → 2.0.8

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.
@@ -1528,6 +1528,27 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1528
1528
  const drawerHeightRef = React__namespace.default.useRef(((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.getBoundingClientRect().height) || 0);
1529
1529
  const drawerWidthRef = React__namespace.default.useRef(((_drawerRef_current1 = drawerRef.current) == null ? void 0 : _drawerRef_current1.getBoundingClientRect().width) || 0);
1530
1530
  const initialDrawerHeight = React__namespace.default.useRef(0);
1531
+ const releaseHiddenFocusBeforeOpen = React__namespace.default.useCallback(()=>{
1532
+ var _drawerRef_current;
1533
+ if (!modal || autoFocus || typeof document === 'undefined') {
1534
+ return;
1535
+ }
1536
+ const activeElement = document.activeElement;
1537
+ if (!activeElement || activeElement === document.body) {
1538
+ return;
1539
+ }
1540
+ const activeElementNode = activeElement;
1541
+ if (((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.contains(activeElementNode)) || (activeElementNode.closest == null ? void 0 : activeElementNode.closest.call(activeElementNode, '[data-drawer]'))) {
1542
+ return;
1543
+ }
1544
+ if (typeof activeElementNode.blur !== 'function') {
1545
+ return;
1546
+ }
1547
+ activeElementNode.blur();
1548
+ }, [
1549
+ autoFocus,
1550
+ modal
1551
+ ]);
1531
1552
  const onSnapPointChange = React__namespace.default.useCallback((activeSnapPointIndex)=>{
1532
1553
  // Change openTime ref when we reach the last snap point to prevent dragging for 500ms incase it's scrollable.
1533
1554
  if (snapPoints && activeSnapPointIndex === snapPointsOffset.length - 1) openTime.current = new Date();
@@ -1579,26 +1600,13 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1579
1600
  autoFocus
1580
1601
  });
1581
1602
  useSafeLayoutEffect(()=>{
1582
- var _drawerRef_current;
1583
- if (!isOpen || !modal || autoFocus || typeof document === 'undefined') {
1603
+ if (!isOpen) {
1584
1604
  return;
1585
1605
  }
1586
- const activeElement = document.activeElement;
1587
- if (!activeElement || activeElement === document.body) {
1588
- return;
1589
- }
1590
- const activeElementNode = activeElement;
1591
- if (((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.contains(activeElementNode)) || (activeElementNode.closest == null ? void 0 : activeElementNode.closest.call(activeElementNode, '[data-drawer]'))) {
1592
- return;
1593
- }
1594
- if (typeof activeElementNode.blur !== 'function') {
1595
- return;
1596
- }
1597
- activeElementNode.blur();
1606
+ releaseHiddenFocusBeforeOpen();
1598
1607
  }, [
1599
- autoFocus,
1600
1608
  isOpen,
1601
- modal
1609
+ releaseHiddenFocusBeforeOpen
1602
1610
  ]);
1603
1611
  function getScale() {
1604
1612
  return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
@@ -2007,6 +2015,7 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
2007
2015
  onOpenChange: (open)=>{
2008
2016
  if (!dismissible && !open) return;
2009
2017
  if (open) {
2018
+ releaseHiddenFocusBeforeOpen();
2010
2019
  setHasBeenOpened(true);
2011
2020
  } else {
2012
2021
  closeDrawer(true);
@@ -1508,6 +1508,27 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1508
1508
  const drawerHeightRef = React__default.useRef(((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.getBoundingClientRect().height) || 0);
1509
1509
  const drawerWidthRef = React__default.useRef(((_drawerRef_current1 = drawerRef.current) == null ? void 0 : _drawerRef_current1.getBoundingClientRect().width) || 0);
1510
1510
  const initialDrawerHeight = React__default.useRef(0);
1511
+ const releaseHiddenFocusBeforeOpen = React__default.useCallback(()=>{
1512
+ var _drawerRef_current;
1513
+ if (!modal || autoFocus || typeof document === 'undefined') {
1514
+ return;
1515
+ }
1516
+ const activeElement = document.activeElement;
1517
+ if (!activeElement || activeElement === document.body) {
1518
+ return;
1519
+ }
1520
+ const activeElementNode = activeElement;
1521
+ if (((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.contains(activeElementNode)) || (activeElementNode.closest == null ? void 0 : activeElementNode.closest.call(activeElementNode, '[data-drawer]'))) {
1522
+ return;
1523
+ }
1524
+ if (typeof activeElementNode.blur !== 'function') {
1525
+ return;
1526
+ }
1527
+ activeElementNode.blur();
1528
+ }, [
1529
+ autoFocus,
1530
+ modal
1531
+ ]);
1511
1532
  const onSnapPointChange = React__default.useCallback((activeSnapPointIndex)=>{
1512
1533
  // Change openTime ref when we reach the last snap point to prevent dragging for 500ms incase it's scrollable.
1513
1534
  if (snapPoints && activeSnapPointIndex === snapPointsOffset.length - 1) openTime.current = new Date();
@@ -1559,26 +1580,13 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1559
1580
  autoFocus
1560
1581
  });
1561
1582
  useSafeLayoutEffect(()=>{
1562
- var _drawerRef_current;
1563
- if (!isOpen || !modal || autoFocus || typeof document === 'undefined') {
1583
+ if (!isOpen) {
1564
1584
  return;
1565
1585
  }
1566
- const activeElement = document.activeElement;
1567
- if (!activeElement || activeElement === document.body) {
1568
- return;
1569
- }
1570
- const activeElementNode = activeElement;
1571
- if (((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.contains(activeElementNode)) || (activeElementNode.closest == null ? void 0 : activeElementNode.closest.call(activeElementNode, '[data-drawer]'))) {
1572
- return;
1573
- }
1574
- if (typeof activeElementNode.blur !== 'function') {
1575
- return;
1576
- }
1577
- activeElementNode.blur();
1586
+ releaseHiddenFocusBeforeOpen();
1578
1587
  }, [
1579
- autoFocus,
1580
1588
  isOpen,
1581
- modal
1589
+ releaseHiddenFocusBeforeOpen
1582
1590
  ]);
1583
1591
  function getScale() {
1584
1592
  return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
@@ -1987,6 +1995,7 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1987
1995
  onOpenChange: (open)=>{
1988
1996
  if (!dismissible && !open) return;
1989
1997
  if (open) {
1998
+ releaseHiddenFocusBeforeOpen();
1990
1999
  setHasBeenOpened(true);
1991
2000
  } else {
1992
2001
  closeDrawer(true);
package/dist/vue/index.js CHANGED
@@ -28077,6 +28077,23 @@ function Root2({
28077
28077
  const drawerHeightRef = import_react9.default.useRef(drawerRef.current?.getBoundingClientRect().height || 0);
28078
28078
  const drawerWidthRef = import_react9.default.useRef(drawerRef.current?.getBoundingClientRect().width || 0);
28079
28079
  const initialDrawerHeight = import_react9.default.useRef(0);
28080
+ const releaseHiddenFocusBeforeOpen2 = import_react9.default.useCallback(() => {
28081
+ if (!modal || autoFocus || typeof document === "undefined") {
28082
+ return;
28083
+ }
28084
+ const activeElement = document.activeElement;
28085
+ if (!activeElement || activeElement === document.body) {
28086
+ return;
28087
+ }
28088
+ const activeElementNode = activeElement;
28089
+ if (drawerRef.current?.contains(activeElementNode) || activeElementNode.closest?.("[data-drawer]")) {
28090
+ return;
28091
+ }
28092
+ if (typeof activeElementNode.blur !== "function") {
28093
+ return;
28094
+ }
28095
+ activeElementNode.blur();
28096
+ }, [autoFocus, modal]);
28080
28097
  const onSnapPointChange = import_react9.default.useCallback((activeSnapPointIndex2) => {
28081
28098
  if (snapPoints && activeSnapPointIndex2 === snapPointsOffset.length - 1) openTime.current = /* @__PURE__ */ new Date();
28082
28099
  }, []);
@@ -28136,22 +28153,11 @@ function Root2({
28136
28153
  autoFocus
28137
28154
  });
28138
28155
  useSafeLayoutEffect(() => {
28139
- if (!isOpen || !modal || autoFocus || typeof document === "undefined") {
28140
- return;
28141
- }
28142
- const activeElement = document.activeElement;
28143
- if (!activeElement || activeElement === document.body) {
28156
+ if (!isOpen) {
28144
28157
  return;
28145
28158
  }
28146
- const activeElementNode = activeElement;
28147
- if (drawerRef.current?.contains(activeElementNode) || activeElementNode.closest?.("[data-drawer]")) {
28148
- return;
28149
- }
28150
- if (typeof activeElementNode.blur !== "function") {
28151
- return;
28152
- }
28153
- activeElementNode.blur();
28154
- }, [autoFocus, isOpen, modal]);
28159
+ releaseHiddenFocusBeforeOpen2();
28160
+ }, [isOpen, releaseHiddenFocusBeforeOpen2]);
28155
28161
  function getScale() {
28156
28162
  return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
28157
28163
  }
@@ -28535,6 +28541,7 @@ function Root2({
28535
28541
  onOpenChange: (open) => {
28536
28542
  if (!dismissible && !open) return;
28537
28543
  if (open) {
28544
+ releaseHiddenFocusBeforeOpen2();
28538
28545
  setHasBeenOpened(true);
28539
28546
  } else {
28540
28547
  closeDrawer2(true);
@@ -29128,7 +29135,7 @@ function openAncestorChain(parentId) {
29128
29135
  openAncestorChain(nextParentId);
29129
29136
  }
29130
29137
  if (!parentRuntime.controller.getSnapshot().state.isOpen) {
29131
- releaseHiddenFocusBeforeOpen(parentRuntime.options);
29138
+ releaseHiddenFocusBeforeOpen(parentRuntime.options, getRuntimeDrawerElement(parentRuntime));
29132
29139
  parentRuntime.controller.setOpen(true);
29133
29140
  notifyOpenStateChange(parentRuntime, true);
29134
29141
  renderVanillaDrawer(parentRuntime.id);
@@ -29143,18 +29150,36 @@ function cleanupRuntimeTrigger(runtime) {
29143
29150
  }
29144
29151
  function bindTriggerElement(runtime) {
29145
29152
  cleanupRuntimeTrigger(runtime);
29153
+ const drawerElement = getRuntimeDrawerElement(runtime);
29154
+ const builtInTriggerElement = getRuntimeTriggerElement(runtime);
29155
+ const cleanups = [];
29156
+ if (builtInTriggerElement) {
29157
+ const handleBuiltInTriggerClick = () => {
29158
+ releaseHiddenFocusBeforeOpen(runtime.options, drawerElement);
29159
+ };
29160
+ builtInTriggerElement.addEventListener("click", handleBuiltInTriggerClick);
29161
+ cleanups.push(() => {
29162
+ builtInTriggerElement.removeEventListener("click", handleBuiltInTriggerClick);
29163
+ });
29164
+ }
29146
29165
  if (!runtime.options.triggerElement) {
29166
+ runtime.cleanupTriggerElement = cleanups.length ? () => {
29167
+ cleanups.forEach((cleanup) => cleanup());
29168
+ } : null;
29147
29169
  return;
29148
29170
  }
29149
29171
  const triggerElement = runtime.options.triggerElement;
29150
29172
  const handleClick = () => {
29151
- releaseHiddenFocusBeforeOpen(runtime.options);
29173
+ releaseHiddenFocusBeforeOpen(runtime.options, drawerElement);
29152
29174
  runtime.controller.setOpen(true);
29153
29175
  renderVanillaDrawer(runtime.id);
29154
29176
  };
29155
29177
  triggerElement.addEventListener("click", handleClick);
29156
- runtime.cleanupTriggerElement = () => {
29178
+ cleanups.push(() => {
29157
29179
  triggerElement.removeEventListener("click", handleClick);
29180
+ });
29181
+ runtime.cleanupTriggerElement = () => {
29182
+ cleanups.forEach((cleanup) => cleanup());
29158
29183
  };
29159
29184
  }
29160
29185
  function notifyOpenStateChange(runtime, open) {
@@ -29184,15 +29209,32 @@ function notifyOpenStateChange(runtime, open) {
29184
29209
  function canUseDOM3() {
29185
29210
  return typeof window !== "undefined" && typeof document !== "undefined";
29186
29211
  }
29187
- function releaseHiddenFocusBeforeOpen(options) {
29212
+ function isElementInsideDrawer(element) {
29213
+ let currentElement = element;
29214
+ while (currentElement) {
29215
+ if (currentElement instanceof HTMLElement && currentElement.hasAttribute("data-drawer")) {
29216
+ return true;
29217
+ }
29218
+ currentElement = currentElement.parentElement;
29219
+ }
29220
+ return false;
29221
+ }
29222
+ function releaseHiddenFocusBeforeOpen(options, drawerElement) {
29188
29223
  if (!canUseDOM3() || options.modal === false || options.autoFocus) {
29189
29224
  return;
29190
29225
  }
29191
29226
  const activeElement = document.activeElement;
29192
- if (!activeElement || activeElement === document.body || typeof activeElement.blur !== "function") {
29227
+ if (!activeElement || activeElement === document.body) {
29193
29228
  return;
29194
29229
  }
29195
- activeElement.blur();
29230
+ const activeElementNode = activeElement;
29231
+ if (drawerElement?.contains(activeElementNode) || isElementInsideDrawer(activeElementNode)) {
29232
+ return;
29233
+ }
29234
+ if (typeof activeElementNode.blur !== "function") {
29235
+ return;
29236
+ }
29237
+ activeElementNode.blur();
29196
29238
  }
29197
29239
  function getRuntimeDrawerElement(runtime) {
29198
29240
  if (!runtime.element) {
@@ -29200,6 +29242,12 @@ function getRuntimeDrawerElement(runtime) {
29200
29242
  }
29201
29243
  return runtime.element.querySelector("[data-drawer]");
29202
29244
  }
29245
+ function getRuntimeTriggerElement(runtime) {
29246
+ if (!runtime.element) {
29247
+ return null;
29248
+ }
29249
+ return runtime.element.querySelector("[data-drawer-vanilla-trigger]");
29250
+ }
29203
29251
  function getViewportSizeForDirection(direction) {
29204
29252
  if (!canUseDOM3()) {
29205
29253
  return 0;
@@ -29248,7 +29296,7 @@ function renderVanillaDrawer(id) {
29248
29296
  onOpenChange: (open) => {
29249
29297
  const previousOpen = runtime.controller.getSnapshot().state.isOpen;
29250
29298
  if (open) {
29251
- releaseHiddenFocusBeforeOpen(runtime.options);
29299
+ releaseHiddenFocusBeforeOpen(runtime.options, getRuntimeDrawerElement(runtime));
29252
29300
  }
29253
29301
  runtime.controller.setOpen(open);
29254
29302
  if (previousOpen !== open) {
@@ -29297,7 +29345,7 @@ function buildVanillaController(id) {
29297
29345
  return createDrawer({ id, open }).getSnapshot();
29298
29346
  }
29299
29347
  if (open) {
29300
- releaseHiddenFocusBeforeOpen(runtime.options);
29348
+ releaseHiddenFocusBeforeOpen(runtime.options, getRuntimeDrawerElement(runtime));
29301
29349
  }
29302
29350
  const previousOpen = runtime.controller.getSnapshot().state.isOpen;
29303
29351
  const snapshot = runtime.controller.setOpen(open);
@@ -29370,7 +29418,7 @@ function createDrawer(options = {}) {
29370
29418
  }
29371
29419
  }
29372
29420
  if (nextOptions.open && !previousOpen) {
29373
- releaseHiddenFocusBeforeOpen(nextOptions);
29421
+ releaseHiddenFocusBeforeOpen(nextOptions, existing ? getRuntimeDrawerElement(existing) : null);
29374
29422
  }
29375
29423
  renderVanillaDrawer(id);
29376
29424
  if (nextOptions.parentId && nextOptions.open) {
@@ -28052,6 +28052,23 @@ function Root2({
28052
28052
  const drawerHeightRef = import_react9.default.useRef(drawerRef.current?.getBoundingClientRect().height || 0);
28053
28053
  const drawerWidthRef = import_react9.default.useRef(drawerRef.current?.getBoundingClientRect().width || 0);
28054
28054
  const initialDrawerHeight = import_react9.default.useRef(0);
28055
+ const releaseHiddenFocusBeforeOpen2 = import_react9.default.useCallback(() => {
28056
+ if (!modal || autoFocus || typeof document === "undefined") {
28057
+ return;
28058
+ }
28059
+ const activeElement = document.activeElement;
28060
+ if (!activeElement || activeElement === document.body) {
28061
+ return;
28062
+ }
28063
+ const activeElementNode = activeElement;
28064
+ if (drawerRef.current?.contains(activeElementNode) || activeElementNode.closest?.("[data-drawer]")) {
28065
+ return;
28066
+ }
28067
+ if (typeof activeElementNode.blur !== "function") {
28068
+ return;
28069
+ }
28070
+ activeElementNode.blur();
28071
+ }, [autoFocus, modal]);
28055
28072
  const onSnapPointChange = import_react9.default.useCallback((activeSnapPointIndex2) => {
28056
28073
  if (snapPoints && activeSnapPointIndex2 === snapPointsOffset.length - 1) openTime.current = /* @__PURE__ */ new Date();
28057
28074
  }, []);
@@ -28111,22 +28128,11 @@ function Root2({
28111
28128
  autoFocus
28112
28129
  });
28113
28130
  useSafeLayoutEffect(() => {
28114
- if (!isOpen || !modal || autoFocus || typeof document === "undefined") {
28115
- return;
28116
- }
28117
- const activeElement = document.activeElement;
28118
- if (!activeElement || activeElement === document.body) {
28131
+ if (!isOpen) {
28119
28132
  return;
28120
28133
  }
28121
- const activeElementNode = activeElement;
28122
- if (drawerRef.current?.contains(activeElementNode) || activeElementNode.closest?.("[data-drawer]")) {
28123
- return;
28124
- }
28125
- if (typeof activeElementNode.blur !== "function") {
28126
- return;
28127
- }
28128
- activeElementNode.blur();
28129
- }, [autoFocus, isOpen, modal]);
28134
+ releaseHiddenFocusBeforeOpen2();
28135
+ }, [isOpen, releaseHiddenFocusBeforeOpen2]);
28130
28136
  function getScale() {
28131
28137
  return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
28132
28138
  }
@@ -28510,6 +28516,7 @@ function Root2({
28510
28516
  onOpenChange: (open) => {
28511
28517
  if (!dismissible && !open) return;
28512
28518
  if (open) {
28519
+ releaseHiddenFocusBeforeOpen2();
28513
28520
  setHasBeenOpened(true);
28514
28521
  } else {
28515
28522
  closeDrawer2(true);
@@ -29103,7 +29110,7 @@ function openAncestorChain(parentId) {
29103
29110
  openAncestorChain(nextParentId);
29104
29111
  }
29105
29112
  if (!parentRuntime.controller.getSnapshot().state.isOpen) {
29106
- releaseHiddenFocusBeforeOpen(parentRuntime.options);
29113
+ releaseHiddenFocusBeforeOpen(parentRuntime.options, getRuntimeDrawerElement(parentRuntime));
29107
29114
  parentRuntime.controller.setOpen(true);
29108
29115
  notifyOpenStateChange(parentRuntime, true);
29109
29116
  renderVanillaDrawer(parentRuntime.id);
@@ -29118,18 +29125,36 @@ function cleanupRuntimeTrigger(runtime) {
29118
29125
  }
29119
29126
  function bindTriggerElement(runtime) {
29120
29127
  cleanupRuntimeTrigger(runtime);
29128
+ const drawerElement = getRuntimeDrawerElement(runtime);
29129
+ const builtInTriggerElement = getRuntimeTriggerElement(runtime);
29130
+ const cleanups = [];
29131
+ if (builtInTriggerElement) {
29132
+ const handleBuiltInTriggerClick = () => {
29133
+ releaseHiddenFocusBeforeOpen(runtime.options, drawerElement);
29134
+ };
29135
+ builtInTriggerElement.addEventListener("click", handleBuiltInTriggerClick);
29136
+ cleanups.push(() => {
29137
+ builtInTriggerElement.removeEventListener("click", handleBuiltInTriggerClick);
29138
+ });
29139
+ }
29121
29140
  if (!runtime.options.triggerElement) {
29141
+ runtime.cleanupTriggerElement = cleanups.length ? () => {
29142
+ cleanups.forEach((cleanup) => cleanup());
29143
+ } : null;
29122
29144
  return;
29123
29145
  }
29124
29146
  const triggerElement = runtime.options.triggerElement;
29125
29147
  const handleClick = () => {
29126
- releaseHiddenFocusBeforeOpen(runtime.options);
29148
+ releaseHiddenFocusBeforeOpen(runtime.options, drawerElement);
29127
29149
  runtime.controller.setOpen(true);
29128
29150
  renderVanillaDrawer(runtime.id);
29129
29151
  };
29130
29152
  triggerElement.addEventListener("click", handleClick);
29131
- runtime.cleanupTriggerElement = () => {
29153
+ cleanups.push(() => {
29132
29154
  triggerElement.removeEventListener("click", handleClick);
29155
+ });
29156
+ runtime.cleanupTriggerElement = () => {
29157
+ cleanups.forEach((cleanup) => cleanup());
29133
29158
  };
29134
29159
  }
29135
29160
  function notifyOpenStateChange(runtime, open) {
@@ -29159,15 +29184,32 @@ function notifyOpenStateChange(runtime, open) {
29159
29184
  function canUseDOM3() {
29160
29185
  return typeof window !== "undefined" && typeof document !== "undefined";
29161
29186
  }
29162
- function releaseHiddenFocusBeforeOpen(options) {
29187
+ function isElementInsideDrawer(element) {
29188
+ let currentElement = element;
29189
+ while (currentElement) {
29190
+ if (currentElement instanceof HTMLElement && currentElement.hasAttribute("data-drawer")) {
29191
+ return true;
29192
+ }
29193
+ currentElement = currentElement.parentElement;
29194
+ }
29195
+ return false;
29196
+ }
29197
+ function releaseHiddenFocusBeforeOpen(options, drawerElement) {
29163
29198
  if (!canUseDOM3() || options.modal === false || options.autoFocus) {
29164
29199
  return;
29165
29200
  }
29166
29201
  const activeElement = document.activeElement;
29167
- if (!activeElement || activeElement === document.body || typeof activeElement.blur !== "function") {
29202
+ if (!activeElement || activeElement === document.body) {
29168
29203
  return;
29169
29204
  }
29170
- activeElement.blur();
29205
+ const activeElementNode = activeElement;
29206
+ if (drawerElement?.contains(activeElementNode) || isElementInsideDrawer(activeElementNode)) {
29207
+ return;
29208
+ }
29209
+ if (typeof activeElementNode.blur !== "function") {
29210
+ return;
29211
+ }
29212
+ activeElementNode.blur();
29171
29213
  }
29172
29214
  function getRuntimeDrawerElement(runtime) {
29173
29215
  if (!runtime.element) {
@@ -29175,6 +29217,12 @@ function getRuntimeDrawerElement(runtime) {
29175
29217
  }
29176
29218
  return runtime.element.querySelector("[data-drawer]");
29177
29219
  }
29220
+ function getRuntimeTriggerElement(runtime) {
29221
+ if (!runtime.element) {
29222
+ return null;
29223
+ }
29224
+ return runtime.element.querySelector("[data-drawer-vanilla-trigger]");
29225
+ }
29178
29226
  function getViewportSizeForDirection(direction) {
29179
29227
  if (!canUseDOM3()) {
29180
29228
  return 0;
@@ -29223,7 +29271,7 @@ function renderVanillaDrawer(id) {
29223
29271
  onOpenChange: (open) => {
29224
29272
  const previousOpen = runtime.controller.getSnapshot().state.isOpen;
29225
29273
  if (open) {
29226
- releaseHiddenFocusBeforeOpen(runtime.options);
29274
+ releaseHiddenFocusBeforeOpen(runtime.options, getRuntimeDrawerElement(runtime));
29227
29275
  }
29228
29276
  runtime.controller.setOpen(open);
29229
29277
  if (previousOpen !== open) {
@@ -29272,7 +29320,7 @@ function buildVanillaController(id) {
29272
29320
  return createDrawer({ id, open }).getSnapshot();
29273
29321
  }
29274
29322
  if (open) {
29275
- releaseHiddenFocusBeforeOpen(runtime.options);
29323
+ releaseHiddenFocusBeforeOpen(runtime.options, getRuntimeDrawerElement(runtime));
29276
29324
  }
29277
29325
  const previousOpen = runtime.controller.getSnapshot().state.isOpen;
29278
29326
  const snapshot = runtime.controller.setOpen(open);
@@ -29345,7 +29393,7 @@ function createDrawer(options = {}) {
29345
29393
  }
29346
29394
  }
29347
29395
  if (nextOptions.open && !previousOpen) {
29348
- releaseHiddenFocusBeforeOpen(nextOptions);
29396
+ releaseHiddenFocusBeforeOpen(nextOptions, existing ? getRuntimeDrawerElement(existing) : null);
29349
29397
  }
29350
29398
  renderVanillaDrawer(id);
29351
29399
  if (nextOptions.parentId && nextOptions.open) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samline/drawer",
3
- "version": "2.0.6",
3
+ "version": "2.0.8",
4
4
  "description": "A universal drawer package for React, Vue, Svelte, vanilla JS, and browser usage.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",