@tangible/ui 0.2.43 → 0.2.45

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.
@@ -212,5 +212,5 @@ export function ColorPicker({ value: controlledValue, defaultValue = '#000000',
212
212
  return (_jsxs("div", { ref: rootRef, className: cx('tui-color-picker', disabled && 'is-disabled', className), role: "group", "aria-label": ariaLabel ?? L.group, ...rest, children: [_jsx(ColorArea, { hsva: hsva, onValueChange: ({ s, v }) => patch({ s, v }), disabled: disabled, "aria-label": L.area, valueText: L.areaValueText(Math.round(hsva.s * 100), Math.round(hsva.v * 100)) }), _jsx(ColorSlider, { "aria-label": L.hue, value: hsva.h, min: 0, max: 360, track: HUE_TRACK, valueText: L.hueValueText(Math.round(hsva.h)), onValueChange: (h) => patch({ h }), disabled: disabled }), alpha && (_jsx(ColorSlider, { "aria-label": L.alpha, value: hsva.a * 100, min: 0, max: 100, checkerboard: true, track: alphaTrack(opaqueHex), valueText: L.alphaValueText(Math.round(hsva.a * 100)), onValueChange: (a) => patch({ a: a / 100 }), disabled: disabled })), _jsxs("div", { className: "tui-color-picker__value", children: [offeredFormats.length > 1 && (_jsxs(Select, { value: format, onValueChange: (v) => setFormat(v), disabled: disabled, "aria-label": L.format, children: [_jsx(Select.Trigger, { className: "tui-color-picker__format" }), _jsx(Select.Content, { children: offeredFormats.map((f) => (_jsx(Select.Option, { value: f, children: L.formats[f] }, f))) })] })), _jsx("div", { className: "tui-color-picker__field-group", children: useChannels ? (_jsx(Channels, { format: format, hsva: hsva, alpha: alpha, disabled: disabled, onChange: commitHsva, channelLabels: L.channels, groupLabel: L.channelGroup(L.formats[format] ?? format) })) : (_jsx("input", { className: "tui-color-picker__field-input", type: "text", autoComplete: "off", spellCheck: false, value: fieldText, onChange: (e) => setDraft(e.target.value), onBlur: commitText, onKeyDown: (e) => {
213
213
  if (e.key === 'Enter')
214
214
  commitText();
215
- }, "aria-label": L.value, disabled: disabled })) }), _jsxs(Tooltip, { type: "label", children: [_jsx(Tooltip.Trigger, { asChild: true, children: _jsx(IconButton, { className: "tui-color-picker__copy", icon: CopyIcon, label: L.copy, variant: "ghost", size: "sm", disabled: disabled, onClick: handleCopy }) }), _jsx(Tooltip.Content, { children: copied ? L.copied : L.copy })] })] }), _jsx("span", { className: "tui-visually-hidden", role: "status", "aria-live": "polite", children: copied ? L.copied : '' }), _jsx("p", { className: cx('tui-color-picker__var', !isVar && 'is-empty'), "aria-live": "polite", children: isVar && (_jsxs(_Fragment, { children: [L.variable, " ", _jsx("code", { children: parsed.name })] })) })] }));
215
+ }, "aria-label": L.value, disabled: disabled })) }), _jsxs(Tooltip, { type: "label", closeOnPress: false, children: [_jsx(Tooltip.Trigger, { asChild: true, children: _jsx(IconButton, { className: "tui-color-picker__copy", icon: CopyIcon, label: L.copy, variant: "ghost", size: "sm", disabled: disabled, onClick: handleCopy }) }), _jsx(Tooltip.Content, { children: copied ? L.copied : L.copy })] })] }), _jsx("span", { className: "tui-visually-hidden", role: "status", "aria-live": "polite", children: copied ? L.copied : '' }), _jsx("p", { className: cx('tui-color-picker__var', !isVar && 'is-empty'), "aria-live": "polite", children: isVar && (_jsxs(_Fragment, { children: [L.variable, " ", _jsx("code", { children: parsed.name })] })) })] }));
216
216
  }
@@ -182,7 +182,7 @@ export function GradientPicker({ value: controlledValue, defaultValue = formatGr
182
182
  // stop after the reorder — close it instead.
183
183
  setOpenStop(null);
184
184
  patch({ stops: reverseStops(stops) });
185
- } }) }), _jsx(Tooltip.Content, { children: L.reverse })] }), _jsxs(Tooltip, { type: "label", children: [_jsx(Tooltip.Trigger, { asChild: true, children: _jsx(IconButton, { icon: CopyIcon, label: L.copy, variant: "ghost", size: "sm", disabled: disabled, onClick: handleCopy }) }), _jsx(Tooltip.Content, { children: copied ? L.copied : L.copy })] })] }), _jsxs("div", { className: "tui-gradient-picker__stops", children: [_jsx("span", { className: "tui-gradient-picker__label tui-text-style-overline", children: L.stopsHeading }), stops.map((stop, i) => (_jsxs("div", { className: "tui-gradient-picker__stop", children: [_jsxs(Popover, { open: openStop === i, onOpenChange: (open) => setOpenStop(open ? i : null), children: [_jsx(Popover.Trigger, { asChild: true, children: _jsx("button", { type: "button", className: "tui-gradient-picker__swatch", "aria-label": L.editStop(i + 1), disabled: disabled, children: _jsx("span", { className: "tui-gradient-picker__swatch-fill", "aria-hidden": "true", style: { '--_swatch': stop.color } }) }) }), _jsx(Popover.Content, { side: "bottom", align: "start", modal: true, "aria-label": L.editStop(i + 1), className: "tui-gradient-picker__stop-popover", children: _jsx(ColorPicker, { value: stop.color, onValueChange: (color) => updateStop(i, { color }), alpha: alpha, formats: formats }) })] }), _jsx(NumberField, { label: L.stopPosition(i + 1), hideLabel: true, value: stop.position, min: stops[i - 1]?.position ?? 0, max: stops[i + 1]?.position ?? 100, suffix: "%", disabled: disabled, onCommit: (position) => updateStop(i, { position: round1(position) }), className: "tui-gradient-picker__stop-position" }), _jsx(IconButton, { ref: (el) => {
185
+ } }) }), _jsx(Tooltip.Content, { children: L.reverse })] }), _jsxs(Tooltip, { type: "label", closeOnPress: false, children: [_jsx(Tooltip.Trigger, { asChild: true, children: _jsx(IconButton, { icon: CopyIcon, label: L.copy, variant: "ghost", size: "sm", disabled: disabled, onClick: handleCopy }) }), _jsx(Tooltip.Content, { children: copied ? L.copied : L.copy })] })] }), _jsxs("div", { className: "tui-gradient-picker__stops", children: [_jsx("span", { className: "tui-gradient-picker__label tui-text-style-overline", children: L.stopsHeading }), stops.map((stop, i) => (_jsxs("div", { className: "tui-gradient-picker__stop", children: [_jsxs(Popover, { open: openStop === i, onOpenChange: (open) => setOpenStop(open ? i : null), children: [_jsx(Popover.Trigger, { asChild: true, children: _jsx("button", { type: "button", className: "tui-gradient-picker__swatch", "aria-label": L.editStop(i + 1), disabled: disabled, children: _jsx("span", { className: "tui-gradient-picker__swatch-fill", "aria-hidden": "true", style: { '--_swatch': stop.color } }) }) }), _jsx(Popover.Content, { side: "bottom", align: "start", modal: true, "aria-label": L.editStop(i + 1), className: "tui-gradient-picker__stop-popover", children: _jsx(ColorPicker, { value: stop.color, onValueChange: (color) => updateStop(i, { color }), alpha: alpha, formats: formats }) })] }), _jsx(NumberField, { label: L.stopPosition(i + 1), hideLabel: true, value: stop.position, min: stops[i - 1]?.position ?? 0, max: stops[i + 1]?.position ?? 100, suffix: "%", disabled: disabled, onCommit: (position) => updateStop(i, { position: round1(position) }), className: "tui-gradient-picker__stop-position" }), _jsx(IconButton, { ref: (el) => {
186
186
  removeRefs.current[i] = el;
187
187
  }, icon: TrashIcon, label: L.removeStop(i + 1), variant: "ghost", theme: "danger", size: "sm", disabled: disabled || stops.length <= 2, onClick: () => removeStop(i, true) })] }, i))), _jsx(Button, { ref: (el) => {
188
188
  addRef.current = el;
@@ -213,10 +213,13 @@ export function Pager({ currentPage, totalPages, onPageChange, pageSize, pageSiz
213
213
  next: labels.nextText,
214
214
  last: labels.lastText,
215
215
  }[it.kind];
216
+ // Boundary buttons are aria-disabled, not native disabled: Next
217
+ // becomes disabled by the very press that reaches the last page,
218
+ // and disabling the focused button would drop focus to <body>.
216
219
  if (navStyle === 'icon') {
217
- return (_jsx(IconButton, { icon: NAV_ICONS[it.kind], label: label, showTooltip: true, size: size, theme: "secondary", variant: navVariant, disabled: it.disabled, onClick: () => go(it.page), className: "tui-pager__item" }, it.kind));
220
+ return (_jsx(IconButton, { icon: NAV_ICONS[it.kind], label: label, showTooltip: true, size: size, theme: "secondary", variant: navVariant, "aria-disabled": it.disabled || undefined, onClick: () => !it.disabled && go(it.page), className: "tui-pager__item" }, it.kind));
218
221
  }
219
- return (_jsx(Button, { size: size, theme: "secondary", variant: navVariant, disabled: it.disabled, onClick: () => go(it.page), "aria-label": label, className: "tui-pager__item", children: text }, it.kind));
222
+ return (_jsx(Button, { size: size, theme: "secondary", variant: navVariant, "aria-disabled": it.disabled || undefined, onClick: () => !it.disabled && go(it.page), "aria-label": label, className: "tui-pager__item", children: text }, it.kind));
220
223
  }
221
224
  // Page number
222
225
  if (it.kind === 'page') {
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from 'react';
3
3
  import { cx } from '../../utils/cx.js';
4
+ import { Button } from '../Button/index.js';
4
5
  import { defaultBulkActionsBarLabels } from './types.js';
5
6
  export function BulkActionsBar({ count, onClear, clearLabel = 'Clear', children, className, 'aria-controls': ariaControls, labels: labelsProp, }) {
6
7
  const labels = { ...defaultBulkActionsBarLabels, ...labelsProp };
@@ -9,5 +10,5 @@ export function BulkActionsBar({ count, onClear, clearLabel = 'Clear', children,
9
10
  return (
10
11
  // role="group", not "toolbar" — toolbar implies roving arrow-key
11
12
  // navigation these independently-focusable controls don't implement.
12
- _jsxs("div", { role: "group", "aria-label": labels.actions(count), "aria-controls": ariaControls, className: cx('tui-table__bulkActions', className), children: [_jsx("span", { className: "tui-table__bulkActions__count", children: labels.selected(count) }), _jsxs("div", { className: "tui-table__bulkActions__actions", children: [children, onClear && (_jsx("button", { type: "button", onClick: onClear, className: "tui-table__bulkActions__clear tui-button is-style-outline is-size-xs", children: clearLabel }))] })] }));
13
+ _jsxs("div", { role: "group", "aria-label": labels.actions(count), "aria-controls": ariaControls, className: cx('tui-table__bulkActions', className), children: [_jsx("span", { className: "tui-table__bulkActions__count", children: labels.selected(count) }), _jsxs("div", { className: "tui-table__bulkActions__actions", children: [children, onClear && (_jsx(Button, { size: "sm", variant: "ghost", theme: "secondary", onClick: onClear, className: "tui-table__bulkActions__clear", children: clearLabel }))] })] }));
13
14
  }
@@ -1,6 +1,6 @@
1
1
  import type { TooltipProviderProps, TooltipProps, TooltipTriggerProps, TooltipContentProps } from './types';
2
2
  declare function TooltipProviderComponent({ delayDuration, closeDelayDuration, skipDelayDuration, children, }: TooltipProviderProps): import("react/jsx-runtime").JSX.Element;
3
- declare function TooltipRoot({ open: controlledOpen, onOpenChange, defaultOpen, delayDuration: localDelay, type, children, }: TooltipProps): import("react/jsx-runtime").JSX.Element;
3
+ declare function TooltipRoot({ open: controlledOpen, onOpenChange, defaultOpen, delayDuration: localDelay, type, closeOnPress, children, }: TooltipProps): import("react/jsx-runtime").JSX.Element;
4
4
  declare function TooltipTriggerComponent({ asChild, 'aria-label': ariaLabel, children, }: TooltipTriggerProps): import("react/jsx-runtime").JSX.Element;
5
5
  declare function TooltipContentComponent(props: TooltipContentProps): import("react/jsx-runtime").JSX.Element | null;
6
6
  type TooltipCompound = typeof TooltipRoot & {
@@ -9,6 +9,45 @@ import { getElementRef } from '../../utils/compose-refs.js';
9
9
  import { TooltipContext, TooltipProviderContext, useTooltipContext, useTooltipProviderContext, } from './TooltipContext.js';
10
10
  import { toPlacement } from './types.js';
11
11
  // =============================================================================
12
+ // Press and popup helpers
13
+ // =============================================================================
14
+ /** Elements whose press does something, so it closes the tooltip. */
15
+ const ACTIVATABLE = 'button, a[href], input, select, textarea, summary, [role="button"], [role="link"], ' +
16
+ '[role="combobox"], [role="menuitem"], [role="tab"], [role="switch"], [role="checkbox"], ' +
17
+ '[role="radio"], [aria-haspopup]:not([aria-haspopup="false"])';
18
+ /** A disabled control: pressing it does nothing, so it isn't a press. */
19
+ const DISABLED = ':disabled, [aria-disabled="true"]';
20
+ /** Links: Space scrolls the page rather than following one. */
21
+ const LINK = 'a[href], [role="link"]';
22
+ /**
23
+ * Where Enter and Space are typing, not activation; a pointer press here is
24
+ * click-to-focus, not a press either.
25
+ */
26
+ const TEXT_ENTRY = 'textarea, select, [contenteditable]:not([contenteditable="false"]), ' +
27
+ 'input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"])' +
28
+ ':not([type="radio"]):not([type="image"]):not([type="file"]):not([type="color"])';
29
+ /**
30
+ * An open popup trigger. aria-expanded alone also means "this section is
31
+ * expanded" (Accordion, Sidebar.Toggle, a NavMenu toggle), and those keep
32
+ * their tooltips, so it counts only on an element that says it has a popup:
33
+ * aria-haspopup (Popover, Dropdown, Select, the pickers) or a combobox.
34
+ */
35
+ const OPEN_POPUP_TRIGGER = '[aria-expanded="true"]:is([aria-haspopup]:not([aria-haspopup="false"]), [role="combobox"])';
36
+ /**
37
+ * The trigger's popup is open: on the trigger, or (for the wrapper span) on
38
+ * a control inside it.
39
+ */
40
+ function isPopupOpen(trigger) {
41
+ if (!trigger)
42
+ return false;
43
+ return trigger.matches(OPEN_POPUP_TRIGGER) || trigger.querySelector(OPEN_POPUP_TRIGGER) !== null;
44
+ }
45
+ /** Strictly inside the element's border box (a zero-size box contains nothing). */
46
+ function isInsideBox(el, x, y) {
47
+ const r = el.getBoundingClientRect();
48
+ return x > r.left && x < r.right && y > r.top && y < r.bottom;
49
+ }
50
+ // =============================================================================
12
51
  // TooltipProvider
13
52
  // =============================================================================
14
53
  function TooltipProviderComponent({ delayDuration = 400, closeDelayDuration = 150, skipDelayDuration = 300, children, }) {
@@ -20,7 +59,7 @@ function TooltipProviderComponent({ delayDuration = 400, closeDelayDuration = 15
20
59
  // =============================================================================
21
60
  // Tooltip Root
22
61
  // =============================================================================
23
- function TooltipRoot({ open: controlledOpen, onOpenChange, defaultOpen = false, delayDuration: localDelay, type = 'description', children, }) {
62
+ function TooltipRoot({ open: controlledOpen, onOpenChange, defaultOpen = false, delayDuration: localDelay, type = 'description', closeOnPress = true, children, }) {
24
63
  const providerContext = useTooltipProviderContext();
25
64
  const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);
26
65
  const isControlled = controlledOpen !== undefined;
@@ -56,15 +95,47 @@ function TooltipRoot({ open: controlledOpen, onOpenChange, defaultOpen = false,
56
95
  }
57
96
  }, []);
58
97
  const { warmth, skipDelayDuration, activeClose } = providerContext;
98
+ // A press on the trigger closes the tooltip and keeps it closed until the
99
+ // user moves on (Radix's behaviour). The trigger did something: it opened a
100
+ // popover, a menu, a drawer. The label has done its job, and left showing it
101
+ // paints over whatever just opened. 'pointer' clears when the pointer leaves
102
+ // the trigger, and deliberately survives blur: focus returning to the
103
+ // trigger when its popup closes, with the pointer still on it, must not
104
+ // bring the tooltip back. 'keyboard' clears on blur, so tabbing away and
105
+ // back shows it again.
106
+ const suppressedRef = useRef(null);
107
+ // Blocked: suppressed by a press, or the trigger's popup is open. The popup
108
+ // check reads the DOM at open time, because Popover, Dropdown, Select and
109
+ // Sidebar all publish their state as aria-expanded on the trigger element,
110
+ // whatever wraps it.
111
+ const isBlocked = useCallback(() => {
112
+ if (suppressedRef.current)
113
+ return true;
114
+ return isPopupOpen(triggerRef.current);
115
+ }, []);
59
116
  const handleOpen = useCallback(() => {
117
+ if (isBlocked()) {
118
+ if (openTimeoutRef.current) {
119
+ clearTimeout(openTimeoutRef.current);
120
+ openTimeoutRef.current = null;
121
+ }
122
+ return;
123
+ }
60
124
  clearAllTimeouts();
61
125
  // Warm group: a tooltip is showing, or one just closed. Open at once.
62
126
  if (warmth && isWarm(warmth)) {
63
127
  setOpen(true);
64
128
  return;
65
129
  }
66
- openTimeoutRef.current = setTimeout(() => setOpen(true), resolvedDelay);
67
- }, [clearAllTimeouts, resolvedDelay, setOpen, warmth]);
130
+ openTimeoutRef.current = setTimeout(() => {
131
+ openTimeoutRef.current = null;
132
+ // The popup may have opened during the delay (a keyboard shortcut, a
133
+ // click on something else that controls it).
134
+ if (isBlocked())
135
+ return;
136
+ setOpen(true);
137
+ }, resolvedDelay);
138
+ }, [clearAllTimeouts, isBlocked, resolvedDelay, setOpen, warmth]);
68
139
  // Warmth membership. Open counts toward the group being warm; closing keeps
69
140
  // it warm for skipDelayDuration, unless it was dismissed. One at a time: a
70
141
  // tooltip opening in a warm group closes the previous one at once, rather
@@ -80,19 +151,19 @@ function TooltipRoot({ open: controlledOpen, onOpenChange, defaultOpen = false,
80
151
  return;
81
152
  dismissedRef.current = false;
82
153
  markOpen(warmth);
83
- const closeNow = () => {
154
+ const closeForNext = () => {
84
155
  clearAllTimeouts();
85
156
  setOpenRef.current(false);
86
157
  };
87
158
  if (activeClose) {
88
159
  const previous = activeClose.current;
89
- activeClose.current = closeNow;
160
+ activeClose.current = closeForNext;
90
161
  if (previous)
91
162
  previous();
92
163
  }
93
164
  return () => {
94
165
  markClosed(warmth, dismissedRef.current ? 0 : skipDelayDuration);
95
- if (activeClose?.current === closeNow)
166
+ if (activeClose?.current === closeForNext)
96
167
  activeClose.current = null;
97
168
  };
98
169
  }, [open, warmth, activeClose, skipDelayDuration, clearAllTimeouts]);
@@ -110,10 +181,119 @@ function TooltipRoot({ open: controlledOpen, onOpenChange, defaultOpen = false,
110
181
  setOpen(false);
111
182
  }
112
183
  }, [clearAllTimeouts, resolvedCloseDelay, setOpen]);
184
+ // Close at once, without the close delay. Not a dismissal: the group stays
185
+ // warm (see handlePress). Read open through a ref so a press on a closed
186
+ // tooltip doesn't fire onOpenChange(false), and setOpen through setOpenRef
187
+ // so closeNow is stable (Content's popup observer subscribes with it).
188
+ const openRef = useRef(open);
189
+ openRef.current = open;
190
+ const closeNow = useCallback(() => {
191
+ clearAllTimeouts();
192
+ if (openRef.current)
193
+ setOpenRef.current(false);
194
+ }, [clearAllTimeouts]);
195
+ // A mouseleave isn't always the pointer leaving. When a modal's scrim
196
+ // opens over a resting pointer, the browser reports a leave because the
197
+ // trigger is covered, with the pointer still inside its box. Releasing then
198
+ // would bring the tooltip back the moment the scrim goes (the pointer
199
+ // "re-enters"). So a leave from inside the box releases only once the
200
+ // pointer actually moves out of it.
201
+ const stopLeaveWatchRef = useRef(null);
202
+ const stopTabWatchRef = useRef(null);
203
+ // Removes both document listeners: the leave watch and the Tab watch.
204
+ const stopLeaveWatch = useCallback(() => {
205
+ stopLeaveWatchRef.current?.();
206
+ stopLeaveWatchRef.current = null;
207
+ stopTabWatchRef.current?.();
208
+ stopTabWatchRef.current = null;
209
+ }, []);
210
+ // While a pointer press is held, a Tab arriving on the trigger releases it:
211
+ // click, Tab away, Tab back with the pointer parked, and the tooltip shows,
212
+ // as any Tab arrival does. Only a Tab: "last key was Tab" is cleared by any
213
+ // other key, so a focus restore after Escape stays suppressed (which is
214
+ // the point of a pointer press surviving blur). :focus-visible can't tell
215
+ // the two apart: after Escape, a restore matches it too.
216
+ const tabArrivalRef = useRef(false);
217
+ const watchTabArrival = useCallback(() => {
218
+ tabArrivalRef.current = false;
219
+ if (stopTabWatchRef.current)
220
+ return;
221
+ const onKey = (e) => {
222
+ tabArrivalRef.current = e.key === 'Tab';
223
+ };
224
+ const onPointer = () => {
225
+ tabArrivalRef.current = false;
226
+ };
227
+ document.addEventListener('keydown', onKey, true);
228
+ document.addEventListener('pointerdown', onPointer, true);
229
+ stopTabWatchRef.current = () => {
230
+ document.removeEventListener('keydown', onKey, true);
231
+ document.removeEventListener('pointerdown', onPointer, true);
232
+ };
233
+ }, []);
234
+ // A press is NOT a warmth dismissal, unlike Escape. Escape is aimed at the
235
+ // tooltip ("go away"); a press is aimed at the control, and the user is
236
+ // still working along this group. Click Bold, glide to Italic, and Italic's
237
+ // label shows at once, as it would have without the click (Radix keeps the
238
+ // group warm on press too). The trigger whose popup opened is blocked by
239
+ // aria-expanded either way; other triggers may still show their labels at
240
+ // once while a non-modal popup is open, as they would on any hover.
241
+ const closeOnPressRef = useRef(closeOnPress);
242
+ closeOnPressRef.current = closeOnPress;
243
+ const handlePress = useCallback((kind) => {
244
+ if (!closeOnPressRef.current)
245
+ return;
246
+ // A pointer press outranks the click that follows it.
247
+ if (suppressedRef.current !== 'pointer')
248
+ suppressedRef.current = kind;
249
+ if (kind === 'pointer')
250
+ watchTabArrival();
251
+ closeNow();
252
+ }, [closeNow, watchTabArrival]);
253
+ const clearPress = useCallback(() => {
254
+ suppressedRef.current = null;
255
+ tabArrivalRef.current = false;
256
+ stopLeaveWatch();
257
+ }, [stopLeaveWatch]);
258
+ const releasePress = useCallback((kind, at) => {
259
+ if (suppressedRef.current !== kind)
260
+ return;
261
+ const trigger = triggerRef.current;
262
+ if (kind === 'keyboard' || !at || !trigger || !isInsideBox(trigger, at.x, at.y)) {
263
+ clearPress();
264
+ return;
265
+ }
266
+ if (stopLeaveWatchRef.current)
267
+ return;
268
+ const onMove = (e) => {
269
+ if (isInsideBox(trigger, e.clientX, e.clientY))
270
+ return;
271
+ if (suppressedRef.current === 'pointer')
272
+ clearPress();
273
+ };
274
+ document.addEventListener('pointermove', onMove, true);
275
+ stopLeaveWatchRef.current = () => document.removeEventListener('pointermove', onMove, true);
276
+ }, [clearPress]);
277
+ // A touch that becomes a scroll ends in pointercancel: no click, no leave.
278
+ // Release, or the held press would outlive the gesture.
279
+ const cancelPress = useCallback(() => {
280
+ if (suppressedRef.current === 'pointer')
281
+ clearPress();
282
+ }, [clearPress]);
283
+ // Focus arrived on the trigger. A Tab arrival releases a held pointer press
284
+ // (see watchTabArrival); then open as usual.
285
+ const handleFocus = useCallback(() => {
286
+ if (suppressedRef.current === 'pointer' && tabArrivalRef.current)
287
+ clearPress();
288
+ handleOpen();
289
+ }, [clearPress, handleOpen]);
113
290
  // Cleanup on unmount
114
291
  useEffect(() => {
115
- return () => clearAllTimeouts();
116
- }, [clearAllTimeouts]);
292
+ return () => {
293
+ clearAllTimeouts();
294
+ stopLeaveWatch();
295
+ };
296
+ }, [clearAllTimeouts, stopLeaveWatch]);
117
297
  const contextValue = useMemo(() => ({
118
298
  open,
119
299
  setOpen,
@@ -126,14 +306,19 @@ function TooltipRoot({ open: controlledOpen, onOpenChange, defaultOpen = false,
126
306
  handleClose,
127
307
  cancelClose,
128
308
  dismiss,
129
- }), [open, setOpen, contentId, type, resolvedDelay, resolvedCloseDelay, handleOpen, handleClose, cancelClose, dismiss]);
309
+ closeNow,
310
+ handlePress,
311
+ releasePress,
312
+ cancelPress,
313
+ handleFocus,
314
+ }), [open, setOpen, contentId, type, resolvedDelay, resolvedCloseDelay, handleOpen, handleClose, cancelClose, dismiss, closeNow, handlePress, releasePress, cancelPress, handleFocus]);
130
315
  return (_jsx(TooltipContext.Provider, { value: contextValue, children: children }));
131
316
  }
132
317
  // =============================================================================
133
318
  // TooltipTrigger
134
319
  // =============================================================================
135
320
  function TooltipTriggerComponent({ asChild = false, 'aria-label': ariaLabel, children, }) {
136
- const { open, triggerRef, contentId, type, handleOpen, handleClose } = useTooltipContext();
321
+ const { open, triggerRef, contentId, type, handleOpen, handleClose, handlePress, releasePress, cancelPress, handleFocus, } = useTooltipContext();
137
322
  // A label tooltip adds no ARIA, so the trigger has to be named already.
138
323
  const warnedRef = useRef(false);
139
324
  useEffect(() => {
@@ -169,11 +354,77 @@ function TooltipTriggerComponent({ asChild = false, 'aria-label': ariaLabel, chi
169
354
  }
170
355
  }
171
356
  }, [asChild, children, triggerRef]);
357
+ // Pressing the trigger closes the tooltip (see handlePress). Only a press
358
+ // that activates something counts: one that lands on an enabled control,
359
+ // whether the trigger is that control (an asChild button) or holds it (the
360
+ // wrapper span around a Button). Not a press: a trigger that is plain
361
+ // content (an info icon in the wrapper, an asChild Avatar), so tapping it
362
+ // to read the tooltip on touch keeps working; a text field, where a press
363
+ // is click-to-focus and its help tooltip should then show; a disabled
364
+ // control, which does nothing.
365
+ const pressedControl = (target) => {
366
+ const trigger = triggerRef.current;
367
+ const control = target instanceof Element ? target.closest(ACTIVATABLE) : null;
368
+ if (!control || !trigger || !trigger.contains(control))
369
+ return null;
370
+ if (control.matches(TEXT_ENTRY) || control.matches(DISABLED))
371
+ return null;
372
+ return control;
373
+ };
374
+ const activates = (target) => pressedControl(target) !== null;
375
+ const onPointerDown = (e) => {
376
+ // Primary button only: not a right-click (context menu), a middle-click
377
+ // (new tab) or a pen eraser.
378
+ if (e.button !== 0)
379
+ return;
380
+ if (activates(e.target))
381
+ handlePress('pointer');
382
+ };
383
+ // Keyboard activation: Enter/Space, and the click they produce on a button
384
+ // or link (detail 0). Space on a link scrolls the page instead.
385
+ const onKeyDown = (e) => {
386
+ if (e.key !== 'Enter' && e.key !== ' ')
387
+ return;
388
+ const control = pressedControl(e.target);
389
+ if (!control)
390
+ return;
391
+ if (e.key === ' ' && control.matches(LINK))
392
+ return;
393
+ handlePress('keyboard');
394
+ };
395
+ const onClick = (e) => {
396
+ if (e.button !== 0 || !activates(e.target))
397
+ return;
398
+ if (e.detail > 0) {
399
+ handlePress('pointer');
400
+ return;
401
+ }
402
+ // A detail-0 click is a keyboard press only when focus is on the trigger.
403
+ // A screen reader's virtual cursor (or code) can click without focusing,
404
+ // and a 'keyboard' press is released only by blur: it would stick, and
405
+ // block hover for sighted users. Such a click needs no suppression: a
406
+ // popup it opens blocks the tooltip through aria-expanded.
407
+ const trigger = triggerRef.current;
408
+ if (trigger && trigger.contains(document.activeElement))
409
+ handlePress('keyboard');
410
+ };
411
+ const onMouseLeave = (e) => {
412
+ releasePress('pointer', { x: e.clientX, y: e.clientY });
413
+ handleClose();
414
+ };
415
+ const onBlur = () => {
416
+ releasePress('keyboard');
417
+ handleClose();
418
+ };
172
419
  const triggerProps = {
173
420
  onMouseEnter: handleOpen,
174
- onMouseLeave: handleClose,
175
- onFocus: handleOpen,
176
- onBlur: handleClose,
421
+ onMouseLeave,
422
+ onFocus: handleFocus,
423
+ onBlur,
424
+ onPointerDown,
425
+ onPointerCancel: cancelPress,
426
+ onKeyDown,
427
+ onClick,
177
428
  'aria-describedby': open && type === 'description' ? contentId : undefined,
178
429
  'data-tooltip-open': open || undefined,
179
430
  };
@@ -183,12 +434,16 @@ function TooltipTriggerComponent({ asChild = false, 'aria-label': ariaLabel, chi
183
434
  // preventDefault. Its own aria-describedby is kept, with the content id
184
435
  // appended while a description tooltip is open; never an empty string.
185
436
  const childProps = children.props;
186
- const compose = (theirs, ours) => {
437
+ //
438
+ // Press handling passes `always`: it runs whatever the child did. A child
439
+ // calling preventDefault on pointerdown is managing focus (the select
440
+ // family's Safari fix does), not opting out of the tooltip closing.
441
+ const compose = (theirs, ours, always = false) => {
187
442
  if (typeof theirs !== 'function')
188
443
  return ours;
189
444
  return (e) => {
190
445
  theirs(e);
191
- if (!e.defaultPrevented)
446
+ if (always || !e.defaultPrevented)
192
447
  ours(e);
193
448
  };
194
449
  };
@@ -199,9 +454,13 @@ function TooltipTriggerComponent({ asChild = false, 'aria-label': ariaLabel, chi
199
454
  return cloneElement(children, {
200
455
  ...triggerProps,
201
456
  onMouseEnter: compose(childProps.onMouseEnter, handleOpen),
202
- onMouseLeave: compose(childProps.onMouseLeave, handleClose),
203
- onFocus: compose(childProps.onFocus, handleOpen),
204
- onBlur: compose(childProps.onBlur, handleClose),
457
+ onMouseLeave: compose(childProps.onMouseLeave, onMouseLeave),
458
+ onFocus: compose(childProps.onFocus, handleFocus),
459
+ onBlur: compose(childProps.onBlur, onBlur),
460
+ onPointerDown: compose(childProps.onPointerDown, onPointerDown, true),
461
+ onPointerCancel: compose(childProps.onPointerCancel, cancelPress, true),
462
+ onKeyDown: compose(childProps.onKeyDown, onKeyDown, true),
463
+ onClick: compose(childProps.onClick, onClick, true),
205
464
  'aria-describedby': describedBy || undefined,
206
465
  ref: setRefs,
207
466
  });
@@ -223,8 +482,32 @@ function TooltipContentComponent(props) {
223
482
  }
224
483
  // Inner component: only mounted when open. All Floating UI hooks live here.
225
484
  function TooltipContentInner({ side = 'top', align = 'center', sideOffset = 8, theme = 'dark', className, children, }) {
226
- const { triggerRef, contentId, type, cancelClose, handleClose, dismiss } = useTooltipContext();
485
+ const { triggerRef, contentId, type, cancelClose, handleClose, dismiss, closeNow } = useTooltipContext();
227
486
  const arrowRef = useRef(null);
487
+ // The trigger's popup opened while the tooltip was showing, by a route that
488
+ // isn't a press (ArrowDown on a Select, a shortcut, a parent's state): close.
489
+ // Otherwise the tooltip sits on top of the popup it labels, on layer-top.
490
+ useEffect(() => {
491
+ const trigger = triggerRef.current;
492
+ if (!trigger)
493
+ return;
494
+ if (isPopupOpen(trigger)) {
495
+ closeNow();
496
+ return;
497
+ }
498
+ if (typeof MutationObserver === 'undefined')
499
+ return;
500
+ const observer = new MutationObserver(() => {
501
+ if (isPopupOpen(trigger))
502
+ closeNow();
503
+ });
504
+ observer.observe(trigger, {
505
+ attributes: true,
506
+ attributeFilter: ['aria-expanded', 'aria-haspopup', 'role'],
507
+ subtree: true,
508
+ });
509
+ return () => observer.disconnect();
510
+ }, [triggerRef, closeNow]);
228
511
  const { refs, floatingStyles, context } = useFloating({
229
512
  placement: toPlacement(side, align),
230
513
  open: true, // Always true when mounted (gate handles the conditional)
@@ -67,6 +67,19 @@ export type TooltipProps = {
67
67
  * @default 'description'
68
68
  */
69
69
  type?: TooltipType;
70
+ /**
71
+ * Close when the trigger is pressed (pointerdown on the primary button,
72
+ * Enter or Space, or the click they produce), and stay closed until the
73
+ * pointer leaves or focus leaves and comes back. That keeps a label from
74
+ * sitting over the popover, menu or drawer its trigger just opened.
75
+ *
76
+ * Set `false` when the tooltip is the press's feedback, such as a copy
77
+ * button whose tooltip swaps to "Copied". The tooltip still never opens
78
+ * while the trigger's popup is open (`aria-expanded="true"` with
79
+ * `aria-haspopup`), whatever this is set to.
80
+ * @default true
81
+ */
82
+ closeOnPress?: boolean;
70
83
  children: React.ReactNode;
71
84
  };
72
85
  export type TooltipTriggerProps = {
@@ -135,6 +148,23 @@ export type TooltipContextValue = {
135
148
  cancelClose: () => void;
136
149
  /** Close now as a dismissal (Escape): it doesn't warm the group. */
137
150
  dismiss: () => void;
151
+ /** Close now, skipping the close delay. Not a dismissal: the group stays warm. */
152
+ closeNow: () => void;
153
+ /** The trigger was pressed: close, and stay closed until the press is released. */
154
+ handlePress: (kind: 'pointer' | 'keyboard') => void;
155
+ /**
156
+ * The pointer left the trigger ('pointer', with where it was) or focus left
157
+ * it ('keyboard'). A pointer "leave" from inside the trigger's box (a scrim
158
+ * covered it) releases only once the pointer moves out.
159
+ */
160
+ releasePress: (kind: 'pointer' | 'keyboard', at?: {
161
+ x: number;
162
+ y: number;
163
+ }) => void;
164
+ /** pointercancel on the trigger (a touch became a scroll): release a pointer press. */
165
+ cancelPress: () => void;
166
+ /** Focus arrived on the trigger: a Tab arrival releases a pointer press, then open. */
167
+ handleFocus: () => void;
138
168
  };
139
169
  /**
140
170
  * Convert side + align to Floating UI placement.
package/figma-tokens.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.2.43",
2
+ "version": "0.2.45",
3
3
  "source": "publish/styles/all.expanded.css",
4
4
  "prefix": "tui-",
5
5
  "note": "Layer 1 primitives only. Component API tokens (--tui-{component}-*) are never defined in CSS — they exist only as fallback reads — so they have no Figma representation. CONTRACT: consumers read TUI defaults from this file at build time (variables[].cssVar, the \"Light\"/\"Dark\" mode names, and alias chains into TUI/Primitives). Renaming a cssVar or a mode is a breaking change to those consumers even when the CSS value is unchanged — a rename silently becomes an undefined default downstream — so treat it as at least a minor bump and call it out in the CHANGELOG.",
package/icons/icons.svg CHANGED
@@ -1,4 +1,4 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" data-tui-icon-sprite="all" data-tui-icon-sprite-version="0.2.43" aria-hidden="true" focusable="false" style="position:absolute;width:0;height:0;overflow:hidden">
1
+ <svg xmlns="http://www.w3.org/2000/svg" data-tui-icon-sprite="all" data-tui-icon-sprite-version="0.2.45" aria-hidden="true" focusable="false" style="position:absolute;width:0;height:0;overflow:hidden">
2
2
  <symbol id="tui-cred-badge-check" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M10.893 4.558a1.377 1.377 0 0 1 2.214 0c.381.515 1.068.7 1.656.444a1.377 1.377 0 0 1 1.917 1.106c.072.637.575 1.14 1.212 1.213a1.377 1.377 0 0 1 1.106 1.916 1.38 1.38 0 0 0 .444 1.656c.744.55.744 1.663 0 2.214a1.38 1.38 0 0 0-.444 1.656 1.377 1.377 0 0 1-1.106 1.917 1.38 1.38 0 0 0-1.212 1.212 1.377 1.377 0 0 1-1.917 1.106 1.38 1.38 0 0 0-1.656.444 1.377 1.377 0 0 1-2.214 0 1.38 1.38 0 0 0-1.656-.444 1.377 1.377 0 0 1-1.916-1.106 1.38 1.38 0 0 0-1.213-1.212 1.377 1.377 0 0 1-1.106-1.917 1.38 1.38 0 0 0-.444-1.656 1.377 1.377 0 0 1 0-2.214c.515-.381.7-1.068.444-1.656a1.377 1.377 0 0 1 1.106-1.916 1.38 1.38 0 0 0 1.213-1.213 1.377 1.377 0 0 1 1.916-1.106 1.38 1.38 0 0 0 1.656-.444m5.193 5.91a.75.75 0 0 0-1.172-.936l-3.531 4.414-1.914-1.532a.75.75 0 1 0-.937 1.172l3.085 2.468z" clip-rule="evenodd"/></symbol>
3
3
  <symbol id="tui-cred-badge-ribbon" viewBox="0 0 24 24"><path d="M11.032 3.488a1.205 1.205 0 0 1 1.936 0c.334.451.935.612 1.45.388a1.205 1.205 0 0 1 1.677.969c.063.557.503.997 1.06 1.06.805.092 1.291.935.969 1.678a1.204 1.204 0 0 0 .388 1.449c.65.481.65 1.455 0 1.936a1.205 1.205 0 0 0-.388 1.45 1.205 1.205 0 0 1-.969 1.677 1.204 1.204 0 0 0-1.06 1.06 1.205 1.205 0 0 1-1.678.969 1.205 1.205 0 0 0-1.449.388c-.481.65-1.455.65-1.936 0a1.204 1.204 0 0 0-1.45-.388 1.205 1.205 0 0 1-1.677-.969 1.205 1.205 0 0 0-1.06-1.06 1.205 1.205 0 0 1-.969-1.678 1.205 1.205 0 0 0-.388-1.449 1.205 1.205 0 0 1 0-1.936c.451-.334.612-.935.388-1.45a1.205 1.205 0 0 1 .969-1.677 1.205 1.205 0 0 0 1.06-1.06 1.205 1.205 0 0 1 1.678-.969 1.205 1.205 0 0 0 1.449-.388M8 17.482c.442.175.953.185 1.437-.025a.88.88 0 0 1 1.054.282 1.877 1.877 0 0 0 3.018 0 .88.88 0 0 1 1.054-.282c.484.21.995.2 1.437.025V21l-4-2.286L8 21z"/></symbol>
4
4
  <symbol id="tui-cred-badge" viewBox="0 0 24 24"><path d="M13.107 4.558a1.377 1.377 0 0 0-2.214 0c-.381.515-1.068.7-1.656.444a1.377 1.377 0 0 0-1.916 1.106 1.38 1.38 0 0 1-1.213 1.213 1.377 1.377 0 0 0-1.106 1.916 1.38 1.38 0 0 1-.444 1.656 1.377 1.377 0 0 0 0 2.214c.515.381.7 1.068.444 1.656a1.377 1.377 0 0 0 1.106 1.917c.637.072 1.14.575 1.213 1.212a1.377 1.377 0 0 0 1.916 1.106 1.38 1.38 0 0 1 1.656.444c.55.744 1.663.744 2.214 0a1.38 1.38 0 0 1 1.656-.444 1.377 1.377 0 0 0 1.917-1.106 1.38 1.38 0 0 1 1.212-1.212 1.377 1.377 0 0 0 1.106-1.917 1.38 1.38 0 0 1 .444-1.656 1.377 1.377 0 0 0 0-2.214 1.38 1.38 0 0 1-.444-1.656 1.377 1.377 0 0 0-1.106-1.916 1.38 1.38 0 0 1-1.212-1.213 1.377 1.377 0 0 0-1.917-1.106 1.38 1.38 0 0 1-1.656-.444"/></symbol>
@@ -1 +1 @@
1
- export const SPRITE_VERSION = '0.2.43';
1
+ export const SPRITE_VERSION = '0.2.45';
package/icons/sprite.php CHANGED
@@ -21,7 +21,7 @@
21
21
  */
22
22
 
23
23
  // Replaced with the package version at build time.
24
- $GLOBALS['tangible_ui_icon_sprite_copies'][__DIR__] = '0.2.43';
24
+ $GLOBALS['tangible_ui_icon_sprite_copies'][__DIR__] = '0.2.45';
25
25
 
26
26
  if (!function_exists('tangible_ui_print_icon_sprite')) {
27
27
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangible/ui",
3
- "version": "0.2.43",
3
+ "version": "0.2.45",
4
4
  "description": "React design system for Tangible's products: standalone React apps and WordPress plugins. Components, CSS custom property tokens, cascade layers.",
5
5
  "type": "module",
6
6
  "main": "./components/index.js",
@@ -816,6 +816,18 @@ track and a bare `1fr` track alike. Use `grid-template-columns: minmax(0, 1fr)`,
816
816
  `min-width: 0` on the item. A DataTable placed directly in the track is fine: its root is the
817
817
  scroll container.
818
818
 
819
+ ### Fixed bars while a dialog is open
820
+
821
+ A Modal (CommandPalette, the vanilla modal) locks page scroll. With classic scrollbars that frees
822
+ the scrollbar's width, and TUI pads `<body>` by it so the page doesn't shift. `position: fixed`
823
+ elements ignore body padding, so an end-anchored bar of yours (an admin bar, a fixed header's
824
+ actions) would still move. While locked, `<body>` carries the width as
825
+ `--tui-scroll-lock-gutter-right` (or `-left` on a right-to-left page); shift by it:
826
+
827
+ ```css
828
+ .my-fixed-header { right: var(--tui-scroll-lock-gutter-right, 0px); }
829
+ ```
830
+
819
831
  ## Vanilla modal (no React)
820
832
 
821
833
  For templates and plugin PHP with no React build (Tangible Blocks, L&L): `@tangible/ui` ships a framework-free modal on the native `<dialog>`. It replaces MicroModal; there is no compat layer, so the markup differs.