oneslash-design-system 2.27.1 → 2.28.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.
@@ -16,6 +16,11 @@ interface ModalProps {
16
16
  'aria-label'?: string;
17
17
  /** `top` sits the panel at the top below sm, so a phone keyboard does not cover a field in it. Centered from sm up. Default 'center'. */
18
18
  placement?: 'center' | 'top';
19
+ /**
20
+ * Where focus goes on close when the element that opened the Modal is no longer on the page, such as
21
+ * a row the Modal deleted. Without it, focus falls to the page. Unused while the opener is still there.
22
+ */
23
+ returnFocus?: () => HTMLElement | null | undefined;
19
24
  }
20
- export default function Modal({ isOpen, title, secondTitle, children, onClose, actions, size, initialFocus, 'aria-label': ariaLabel, placement, }: ModalProps): React.JSX.Element | null;
25
+ export default function Modal({ isOpen, title, secondTitle, children, onClose, actions, size, initialFocus, 'aria-label': ariaLabel, placement, returnFocus, }: ModalProps): React.JSX.Element | null;
21
26
  export {};
@@ -5,7 +5,7 @@ import { useOverlayTransition } from './useOverlayTransition';
5
5
  import { initialFocusCandidates } from '../internal/modal';
6
6
  import { PICKABLE, claimEvent, isTopOverlay, lockScroll, popOverlay, pushOverlay, trapTab, unlockScroll } from '../internal/overlayStack';
7
7
  export default function Modal(_a) {
8
- var isOpen = _a.isOpen, title = _a.title, secondTitle = _a.secondTitle, children = _a.children, onClose = _a.onClose, actions = _a.actions, _b = _a.size, size = _b === void 0 ? 'medium' : _b, _c = _a.initialFocus, initialFocus = _c === void 0 ? 'first' : _c, ariaLabel = _a["aria-label"], _d = _a.placement, placement = _d === void 0 ? 'center' : _d;
8
+ var isOpen = _a.isOpen, title = _a.title, secondTitle = _a.secondTitle, children = _a.children, onClose = _a.onClose, actions = _a.actions, _b = _a.size, size = _b === void 0 ? 'medium' : _b, _c = _a.initialFocus, initialFocus = _c === void 0 ? 'first' : _c, ariaLabel = _a["aria-label"], _d = _a.placement, placement = _d === void 0 ? 'center' : _d, returnFocus = _a.returnFocus;
9
9
  var panelRef = useRef(null);
10
10
  var bodyRef = useRef(null);
11
11
  var titleId = useId();
@@ -13,6 +13,8 @@ export default function Modal(_a) {
13
13
  // Keep onClose in a ref so a new function each render doesn't re-run the focus effect
14
14
  var onCloseRef = useRef(onClose);
15
15
  onCloseRef.current = onClose;
16
+ var returnFocusRef = useRef(returnFocus);
17
+ returnFocusRef.current = returnFocus;
16
18
  // Move focus into the panel, trap Tab inside it, close on Escape,
17
19
  // lock page scroll, and give focus back to the trigger on close.
18
20
  // Escape and Tab act only while this Modal is the top overlay (see internal/overlayStack).
@@ -49,11 +51,14 @@ export default function Modal(_a) {
49
51
  };
50
52
  window.addEventListener('keydown', handleKeyDown);
51
53
  return function () {
52
- var _a;
54
+ var _a, _b, _c;
53
55
  window.removeEventListener('keydown', handleKeyDown);
54
56
  popOverlay(titleId);
55
57
  unlockScroll();
56
- (_a = previouslyFocused === null || previouslyFocused === void 0 ? void 0 : previouslyFocused.focus) === null || _a === void 0 ? void 0 : _a.call(previouslyFocused);
58
+ if (previouslyFocused === null || previouslyFocused === void 0 ? void 0 : previouslyFocused.isConnected)
59
+ (_a = previouslyFocused.focus) === null || _a === void 0 ? void 0 : _a.call(previouslyFocused);
60
+ else
61
+ (_c = (_b = returnFocusRef.current) === null || _b === void 0 ? void 0 : _b.call(returnFocusRef)) === null || _c === void 0 ? void 0 : _c.focus();
57
62
  };
58
63
  }, [isOpen, mounted]);
59
64
  // Determine width based on size prop
@@ -2,6 +2,7 @@
2
2
  import React, { useState, useRef, useLayoutEffect, useEffect, useId } from 'react';
3
3
  import { createPortal } from 'react-dom';
4
4
  import { useOverlayTransition } from './useOverlayTransition';
5
+ import { claimEvent, isInOpenOverlay } from '../internal/overlayStack';
5
6
  // useLayoutEffect warns on a server render, where it cannot run; useEffect is the same there and silent
6
7
  var useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
7
8
  var VIEWPORT_MARGIN = 8;
@@ -74,13 +75,17 @@ export default function Tooltip(_a) {
74
75
  target.setAttribute('aria-describedby', tooltipId);
75
76
  return function () { return target.removeAttribute('aria-describedby'); };
76
77
  }, [mounted, tooltipId]);
77
- // Escape dismisses an open tooltip
78
+ // Escape dismisses an open tooltip. In a Modal or Drawer it does only that, and a second Escape
79
+ // closes the overlay. The event is claimed, not stopped, so a SidePane still closes on it.
78
80
  useEffect(function () {
79
81
  if (!open)
80
82
  return;
81
83
  var handleKeyDown = function (e) {
82
- if (e.key === 'Escape')
83
- hide();
84
+ if (e.key !== 'Escape')
85
+ return;
86
+ hide();
87
+ if (isInOpenOverlay(triggerRef.current))
88
+ claimEvent(e);
84
89
  };
85
90
  document.addEventListener('keydown', handleKeyDown);
86
91
  return function () { return document.removeEventListener('keydown', handleKeyDown); };
@@ -8,6 +8,7 @@ export declare function pushOverlay(id: string, panel?: Overlay['panel']): void;
8
8
  export declare function popOverlay(id: string): void;
9
9
  export declare function isTopOverlay(id: string): boolean;
10
10
  export declare function isInTopOverlay(node: unknown): boolean;
11
+ export declare function isInOpenOverlay(node: unknown): boolean;
11
12
  export declare function claimEvent(event: object): boolean;
12
13
  export declare function lockScroll(): void;
13
14
  export declare function unlockScroll(): void;
@@ -21,6 +21,12 @@ export function isInTopOverlay(node) {
21
21
  var top = stack[stack.length - 1];
22
22
  return !(top === null || top === void 0 ? void 0 : top.panel) || top.panel.contains(node);
23
23
  }
24
+ // True when an overlay is open and the top one holds `node`
25
+ export function isInOpenOverlay(node) {
26
+ var _a;
27
+ var top = stack[stack.length - 1];
28
+ return !!((_a = top === null || top === void 0 ? void 0 : top.panel) === null || _a === void 0 ? void 0 : _a.contains(node));
29
+ }
24
30
  // Every overlay hears the same keydown on window. A browser runs React's update between two
25
31
  // listeners, so the top overlay may already be gone when the next one asks: the first to claim
26
32
  // an event acts on it, and the others leave it.
@@ -10,3 +10,5 @@ export declare const WithActions: Story;
10
10
  export declare const LongContent: Story;
11
11
  export declare const FocusInBody: Story;
12
12
  export declare const WithSelect: Story;
13
+ export declare const RemovedOpenerProbe: Story;
14
+ export declare const RemovedOpenerReturnFocusProbe: Story;
@@ -111,3 +111,31 @@ export var WithSelect = {
111
111
  render: function (args) { return <WithSelectModal {...args}/>; },
112
112
  args: { title: "Move Project", size: "small" },
113
113
  };
114
+ // A row whose Delete opens a confirm; confirming removes the row, and with it the opener
115
+ var RemovedOpenerProbeBox = function (_a) {
116
+ var withReturnFocus = _a.withReturnFocus;
117
+ var _b = useState(["Alpha", "Beta"]), rows = _b[0], setRows = _b[1];
118
+ var _c = useState(null), deleting = _c[0], setDeleting = _c[1];
119
+ var heading = React.useRef(null);
120
+ return (<div style={{ padding: "24px" }}>
121
+ <h2 ref={heading} tabIndex={-1}>Rows</h2>
122
+ {rows.map(function (row) { return (<div key={row}>
123
+ {row}{" "}
124
+ <button type="button" onClick={function () { return setDeleting(row); }}>{"Delete ".concat(row)}</button>
125
+ </div>); })}
126
+ <Modal isOpen={deleting !== null} size="small" title="Delete Row" onClose={function () { return setDeleting(null); }} returnFocus={withReturnFocus ? function () { return heading.current; } : undefined}>
127
+ <button type="button" onClick={function () { setRows(rows.filter(function (r) { return r !== deleting; })); setDeleting(null); }}>
128
+ Delete
129
+ </button>
130
+ </Modal>
131
+ </div>);
132
+ };
133
+ export var RemovedOpenerProbe = {
134
+ // For tests/interactions.spec.ts only: hidden from the sidebar and the docs, and skipped by the visual gate
135
+ tags: ["!dev", "!autodocs", "test-only"],
136
+ render: function () { return <RemovedOpenerProbeBox />; },
137
+ };
138
+ export var RemovedOpenerReturnFocusProbe = {
139
+ tags: ["!dev", "!autodocs", "test-only"],
140
+ render: function () { return <RemovedOpenerProbeBox withReturnFocus/>; },
141
+ };
@@ -7,3 +7,4 @@ export declare const Default: Story;
7
7
  export declare const OnIconButton: Story;
8
8
  export declare const LongText: Story;
9
9
  export declare const MultipleTooltips: Story;
10
+ export declare const InModalProbe: Story;
@@ -2,6 +2,7 @@ import React from "react";
2
2
  import Tooltip from "../components/tooltip";
3
3
  import Button from "../components/button";
4
4
  import IconButton from "../components/iconButton";
5
+ import Modal from "../components/modal";
5
6
  var meta = {
6
7
  title: "Components/Tooltip",
7
8
  component: Tooltip,
@@ -50,3 +51,19 @@ export var MultipleTooltips = {
50
51
  </Tooltip>
51
52
  </div>); },
52
53
  };
54
+ var InModalProbeBox = function () {
55
+ var _a = React.useState(true), open = _a[0], setOpen = _a[1];
56
+ return (<>
57
+ <p data-testid="modal-state">{open ? "open" : "closed"}</p>
58
+ <Modal isOpen={open} title="Probe" onClose={function () { return setOpen(false); }}>
59
+ <Tooltip title="Settings">
60
+ <button type="button">Settings</button>
61
+ </Tooltip>
62
+ </Modal>
63
+ </>);
64
+ };
65
+ export var InModalProbe = {
66
+ // For tests/interactions.spec.ts only: hidden from the sidebar and the docs, and skipped by the visual gate
67
+ tags: ["!dev", "!autodocs", "test-only"],
68
+ render: function () { return <InModalProbeBox />; },
69
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "oneslash-design-system",
3
3
  "description": "A design system for the Oneslash projects",
4
- "version": "2.27.1",
4
+ "version": "2.28.1",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "./dist/index.js",
@@ -70,6 +70,8 @@
70
70
  "react-dom": "^18 || ^19"
71
71
  },
72
72
  "devDependencies": {
73
+ "@fontsource/fira-code": "5.3.0",
74
+ "@fontsource/inter": "5.3.0",
73
75
  "@playwright/test": "1.64.1",
74
76
  "@storybook/addon-essentials": "8.6",
75
77
  "@storybook/react-vite": "8.6",