sinwan-ui-core 1.3.0 → 1.3.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/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to this package are documented in this file. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this package uses [Semantic Versioning](https://semver.org/).
4
4
 
5
+ ## [1.3.1]
6
+
7
+ ### Fixed
8
+
9
+ - A closing `DialogContent` (dialogs, sheets, drawers, alert dialogs) gives focus back to what opened it only when focus is still inside the dialog or was lost. Before, it always refocused the trigger once the exit animation ended, about 200 ms after closing. That undid focus the app had moved on purpose: after scanning a label, the quantity field lost focus to the "Scan" button.
10
+
5
11
  ## [1.3.0]
6
12
 
7
13
  ### Added
@@ -238,6 +238,12 @@ var DialogOverlay2 = cc((props) => {
238
238
  })
239
239
  });
240
240
  });
241
+ function focusIsInsideOrLost(content) {
242
+ const active = document.activeElement;
243
+ if (!active || active === document.body || !active.isConnected)
244
+ return true;
245
+ return content?.contains(active) ?? false;
246
+ }
241
247
  var DialogContent2 = cc((props) => {
242
248
  const dataAttrs = _$createLiveRest(props, [
243
249
  "children",
@@ -294,13 +300,18 @@ var DialogContent2 = cc((props) => {
294
300
  "data-vaul-drawer-direction": () => props["data-vaul-drawer-direction"],
295
301
  class: () => _$unwrap(props).class,
296
302
  ref: function contentRef(el) {
297
- contentEl = el;
298
303
  if (el) {
304
+ contentEl = el;
299
305
  previousFocus = document.activeElement;
300
306
  el.focus?.();
301
- } else if (previousFocus) {
302
- previousFocus.focus?.();
307
+ return;
303
308
  }
309
+ const closing = contentEl;
310
+ const restore = previousFocus;
311
+ contentEl = null;
312
+ previousFocus = null;
313
+ if (restore && focusIsInsideOrLost(closing))
314
+ restore.focus?.();
304
315
  },
305
316
  tabIndex: -1,
306
317
  onclick: function stopBubble(e) {
package/dist/index.js CHANGED
@@ -86,7 +86,7 @@ import {
86
86
  TooltipRoot2,
87
87
  TooltipTrigger2,
88
88
  TooltipContent2
89
- } from "./chunks/chunk-4a2neay9.js";
89
+ } from "./chunks/chunk-648ssfj3.js";
90
90
  import {
91
91
  ThemeKey2,
92
92
  ThemeProvider2,
package/dist/overlay.js CHANGED
@@ -21,7 +21,7 @@ import {
21
21
  TooltipRoot2,
22
22
  TooltipTrigger2,
23
23
  TooltipContent2
24
- } from "./chunks/chunk-4a2neay9.js";
24
+ } from "./chunks/chunk-648ssfj3.js";
25
25
  import"./chunks/chunk-bw9vp0y9.js";
26
26
  import"./chunks/chunk-7r6fwdyt.js";
27
27
  import"./chunks/chunk-9whagkb6.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sinwan-ui-core",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Headless behaviour primitives for Sinwan UI components: overlays, floating positioning, dismiss layers, controls, slots, theme and direction.",
5
5
  "author": "Mohammed Ben Cheikh",
6
6
  "license": "MIT",