@tangible/ui 0.2.14 → 0.2.15
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/components/DatePicker/DatePicker.d.ts +19 -1
- package/components/DatePicker/DatePicker.js +73 -16
- package/components/DatePicker/DateRangePicker.d.ts +19 -1
- package/components/DatePicker/DateRangePicker.js +77 -23
- package/components/DatePicker/PickerTrigger.d.ts +38 -0
- package/components/DatePicker/PickerTrigger.js +57 -0
- package/components/DatePicker/index.d.ts +3 -3
- package/components/DatePicker/index.js +2 -2
- package/components/DatePicker/types.d.ts +65 -2
- package/components/Modal/Modal.d.ts +1 -1
- package/components/Modal/Modal.js +49 -9
- package/components/Popover/Popover.js +13 -0
- package/components/index.d.ts +1 -1
- package/components/index.js +1 -1
- package/figma-tokens.json +1 -1
- package/package.json +1 -1
- package/skills/building-with-tui/SKILL.md +66 -2
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +6 -0
- package/styles/all.expanded.unlayered.css +6 -0
- package/styles/all.unlayered.css +1 -1
- package/styles/components/text-input.scss +21 -0
- package/tui-manifest.json +7 -2
|
@@ -10,6 +10,7 @@ import { IconButton } from '../IconButton/index.js';
|
|
|
10
10
|
const isBrowser = typeof document !== 'undefined';
|
|
11
11
|
function ModalRoot({ open, onClose, size = 'md', stickyHead, stickyFoot, 'aria-labelledby': labelledBy, 'aria-describedby': describedBy, initialFocusSelector, container, showCloseButton, closeLabel = 'Close', closeOnBackdropClick = true, closeOnEscape = true, preventScrollOnRestore = false, className, children, ...rest }) {
|
|
12
12
|
const dialogRef = useRef(null);
|
|
13
|
+
const anchorRef = useRef(null);
|
|
13
14
|
const restoreRef = useRef(null);
|
|
14
15
|
const warnedRef = useRef(false);
|
|
15
16
|
const warnedAriaLabelRef = useRef(false);
|
|
@@ -32,24 +33,58 @@ function ModalRoot({ open, onClose, size = 'md', stickyHead, stickyFoot, 'aria-l
|
|
|
32
33
|
'to provide an accessible name (WCAG 4.1.2).');
|
|
33
34
|
}
|
|
34
35
|
}, [open, labelledBy]);
|
|
35
|
-
//
|
|
36
|
+
// Compute portal mount point and capture the focus-restore target on open.
|
|
36
37
|
// Uses useLayoutEffect to run before paint — both renders complete before
|
|
37
38
|
// the browser shows anything, so no visible delay.
|
|
38
39
|
//
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
//
|
|
40
|
+
// Portal scoping resolves from `anchorRef` — a throwaway span rendered at the
|
|
41
|
+
// Modal's own position in the tree (see the first-render branch below) — NOT
|
|
42
|
+
// from document.activeElement. activeElement is not a reliable stand-in for
|
|
43
|
+
// the trigger: Safari/WebKit does not focus a <button> on click, so focus can
|
|
44
|
+
// still be sitting in a hidden, inert tab panel that a click moved away from.
|
|
45
|
+
// Scoping off it portalled the dialog into that hidden subtree, where the
|
|
46
|
+
// focus trap and scroll lock engaged around an invisible modal.
|
|
47
|
+
//
|
|
48
|
+
// Focus restore still reads activeElement (it wants "whatever had focus", and
|
|
49
|
+
// Modal has no reference to the trigger), so on WebKit it can restore to the
|
|
50
|
+
// pre-click element rather than the trigger. Cosmetic by comparison, and it
|
|
51
|
+
// cannot strand the user.
|
|
43
52
|
useLayoutEffect(() => {
|
|
44
53
|
if (!open || !isBrowser) {
|
|
45
54
|
return;
|
|
46
55
|
}
|
|
47
56
|
if (mount)
|
|
48
57
|
return; // Already captured for this open cycle
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
setMount(container ?? getPortalRootFor(trigger));
|
|
58
|
+
restoreRef.current = document.activeElement;
|
|
59
|
+
setMount(container ?? getPortalRootFor(anchorRef.current));
|
|
52
60
|
}, [open, container, mount]);
|
|
61
|
+
// Dev warning: a mount buried in a hidden/inert subtree renders an invisible
|
|
62
|
+
// modal with a live focus trap — the exact failure the anchor fix removes,
|
|
63
|
+
// now only reachable by rendering <Modal> inside a hidden panel yourself.
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (!isDev() || !open || !mount)
|
|
66
|
+
return;
|
|
67
|
+
let node = mount;
|
|
68
|
+
let buried = null;
|
|
69
|
+
while (node && node !== document.body) {
|
|
70
|
+
const el = node;
|
|
71
|
+
if (el.hasAttribute('hidden') || el.hasAttribute('inert')) {
|
|
72
|
+
buried = el;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
if (isBrowser && getComputedStyle(el).display === 'none') {
|
|
76
|
+
buried = el;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
node = el.parentElement;
|
|
80
|
+
}
|
|
81
|
+
if (buried) {
|
|
82
|
+
console.warn('[TUI Modal] Portal target is inside a hidden or inert subtree, so the dialog ' +
|
|
83
|
+
'will not be visible while its focus trap and scroll lock are active. The mount ' +
|
|
84
|
+
'point is resolved from where <Modal> sits in the tree — move it out of the ' +
|
|
85
|
+
'hidden container, or pass an explicit `container`.', buried);
|
|
86
|
+
}
|
|
87
|
+
}, [open, mount]);
|
|
53
88
|
// Reset state when modal closes, restore focus to trigger.
|
|
54
89
|
useEffect(() => {
|
|
55
90
|
if (open)
|
|
@@ -139,8 +174,13 @@ function ModalRoot({ open, onClose, size = 'md', stickyHead, stickyFoot, 'aria-l
|
|
|
139
174
|
}, [open, mount, initialFocusSelector, labelledBy]);
|
|
140
175
|
// Memoize context value to prevent unnecessary re-renders
|
|
141
176
|
const contextValue = useMemo(() => ({ onClose }), [onClose]);
|
|
142
|
-
if (!open
|
|
177
|
+
if (!open)
|
|
143
178
|
return null;
|
|
179
|
+
// First render of an open cycle: nothing but an in-tree anchor, so the layout
|
|
180
|
+
// effect above can resolve the portal root from the Modal's own DOM position.
|
|
181
|
+
// Unmounts on the very next render (pre-paint), so it never lays anything out.
|
|
182
|
+
if (!mount)
|
|
183
|
+
return _jsx("span", { ref: anchorRef, hidden: true });
|
|
144
184
|
return createPortal(_jsx(ModalContext.Provider, { value: contextValue, children: _jsxs("div", { className: "tui-modal", "data-state": "open", style: { pointerEvents: 'auto' }, children: [_jsx("div", { className: "tui-modal__backdrop", "aria-hidden": "true", onClick: closeOnBackdropClick ? onClose : undefined }), _jsxs("div", { ref: dialogRef, role: "dialog", "aria-modal": "true", "aria-labelledby": labelledBy, "aria-describedby": describedBy, className: cx('tui-modal__dialog', `is-size-${size}`, stickyHead && 'is-sticky-head', stickyFoot && 'is-sticky-foot', className), tabIndex: -1, ...rest, children: [showCloseButton && (_jsx(IconButton, { icon: "system/close", label: closeLabel, variant: "ghost", size: "sm", onClick: onClose, className: "tui-modal__close", showTooltip: true })), children] })] }) }), mount);
|
|
145
185
|
}
|
|
146
186
|
function ModalClose({ label = 'Close', className }) {
|
|
@@ -87,8 +87,21 @@ function PopoverTriggerComponent({ asChild = false, children }) {
|
|
|
87
87
|
'data-popover-open': open || undefined,
|
|
88
88
|
};
|
|
89
89
|
if (asChild && isValidElement(children)) {
|
|
90
|
+
// Compose, don't clobber: an asChild trigger that brings its own onClick
|
|
91
|
+
// (an IconButton with an analytics call, a picker's own handler) used to
|
|
92
|
+
// lose it silently to the spread below. The child runs first, and opts out
|
|
93
|
+
// of toggling the popover by calling preventDefault — same contract as
|
|
94
|
+
// Select.Trigger's composed handlers.
|
|
95
|
+
const childOnClick = children.props.onClick;
|
|
90
96
|
return cloneElement(children, {
|
|
91
97
|
...triggerProps,
|
|
98
|
+
onClick: childOnClick
|
|
99
|
+
? (e) => {
|
|
100
|
+
childOnClick(e);
|
|
101
|
+
if (!e.defaultPrevented)
|
|
102
|
+
handleClick();
|
|
103
|
+
}
|
|
104
|
+
: handleClick,
|
|
92
105
|
ref: setRefs,
|
|
93
106
|
});
|
|
94
107
|
}
|
package/components/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { Chips } from './Chips';
|
|
|
12
12
|
export { ColorPicker, ColorField, ColorArea, ColorSlider, defaultColorPickerLabels } from './ColorPicker';
|
|
13
13
|
export { GradientPicker, GradientBar, defaultGradientPickerLabels } from './GradientPicker';
|
|
14
14
|
export { ContentIndicator } from './ContentIndicator';
|
|
15
|
-
export { Calendar, DatePicker, DateRangePicker, defaultDateRangePresets, defaultCalendarLabels, defaultDatePickerLabels, defaultDateRangePickerLabels, } from './DatePicker';
|
|
15
|
+
export { Calendar, DatePicker, DatePickerTrigger, DateRangePicker, DateRangePickerTrigger, defaultDateRangePresets, defaultCalendarLabels, defaultDatePickerLabels, defaultDateRangePickerLabels, } from './DatePicker';
|
|
16
16
|
export { Combobox, ComboboxContent, ComboboxOption, ComboboxGroup, ComboboxLabel, useCombobox } from './Combobox';
|
|
17
17
|
export { MultiCombobox, MultiComboboxContent, MultiComboboxOption, MultiComboboxGroup, MultiComboboxLabel, useMultiCombobox } from './MultiCombobox';
|
|
18
18
|
export { Dropdown, DropdownTrigger, DropdownContent, DropdownItem, DropdownSeparator, DropdownHeader, useDropdown } from './Dropdown';
|
package/components/index.js
CHANGED
|
@@ -10,7 +10,7 @@ export { Chips } from './Chips/index.js';
|
|
|
10
10
|
export { ColorPicker, ColorField, ColorArea, ColorSlider, defaultColorPickerLabels } from './ColorPicker/index.js';
|
|
11
11
|
export { GradientPicker, GradientBar, defaultGradientPickerLabels } from './GradientPicker/index.js';
|
|
12
12
|
export { ContentIndicator } from './ContentIndicator/index.js';
|
|
13
|
-
export { Calendar, DatePicker, DateRangePicker, defaultDateRangePresets, defaultCalendarLabels, defaultDatePickerLabels, defaultDateRangePickerLabels, } from './DatePicker/index.js';
|
|
13
|
+
export { Calendar, DatePicker, DatePickerTrigger, DateRangePicker, DateRangePickerTrigger, defaultDateRangePresets, defaultCalendarLabels, defaultDatePickerLabels, defaultDateRangePickerLabels, } from './DatePicker/index.js';
|
|
14
14
|
export { Combobox, ComboboxContent, ComboboxOption, ComboboxGroup, ComboboxLabel, useCombobox } from './Combobox/index.js';
|
|
15
15
|
export { MultiCombobox, MultiComboboxContent, MultiComboboxOption, MultiComboboxGroup, MultiComboboxLabel, useMultiCombobox } from './MultiCombobox/index.js';
|
|
16
16
|
export { Dropdown, DropdownTrigger, DropdownContent, DropdownItem, DropdownSeparator, DropdownHeader, useDropdown } from './Dropdown/index.js';
|
package/figma-tokens.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.2.
|
|
2
|
+
"version": "0.2.15",
|
|
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.",
|
package/package.json
CHANGED
|
@@ -228,13 +228,77 @@ Useful primitives:
|
|
|
228
228
|
`className` is for layout integration (margin, grid placement), not appearance. Beyond the token
|
|
229
229
|
API the sanctioned escape hatch is to **swizzle** — copy the component source and own the fork.
|
|
230
230
|
|
|
231
|
+
### Replacing a trigger with `asChild`
|
|
232
|
+
|
|
233
|
+
`Select.Trigger`, `Dropdown.Trigger`, `Popover.Trigger`, `Tooltip.Trigger`, `Accordion.Trigger`,
|
|
234
|
+
`MultiSelect.Trigger`, `DatePicker.Trigger` and `DateRangePicker.Trigger` all take `asChild`,
|
|
235
|
+
rendering your element in place of theirs.
|
|
236
|
+
|
|
237
|
+
The two pickers render their trigger automatically when the root has no children, so
|
|
238
|
+
`<DatePicker />` is unchanged. Reach for `DatePicker.Trigger` when you want to place the trigger
|
|
239
|
+
yourself — which is what lets the whole popover (time field, Now, month/day/year, calendar) hang off
|
|
240
|
+
a text field the user can also type into freely:
|
|
241
|
+
|
|
242
|
+
```tsx
|
|
243
|
+
<DatePicker withTime onChange={(date) => setText(format(date))}>
|
|
244
|
+
<TextInput
|
|
245
|
+
value={text}
|
|
246
|
+
onChange={(e) => setText(e.target.value)}
|
|
247
|
+
suffix={
|
|
248
|
+
<DatePicker.Trigger asChild>
|
|
249
|
+
<IconButton icon="lms/calendar" label="Pick a date" variant="ghost" size="sm" />
|
|
250
|
+
</DatePicker.Trigger>
|
|
251
|
+
}
|
|
252
|
+
/>
|
|
253
|
+
</DatePicker>
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
TUI never writes into the field: `onChange` hands you a `Date` and you decide what string goes in,
|
|
257
|
+
which is why this works with formats TUI knows nothing about ("3pm ET" survives being typed).
|
|
258
|
+
Children with no `Trigger` among them leave the picker unopenable — a dev warning fires.
|
|
259
|
+
|
|
260
|
+
**Size a slot button one tier below the field** (`md` field → `sm` button). Button and IconButton
|
|
261
|
+
anchor to `--tui-control-height-*`, which is the *whole field's* height; TUI cancels the group's
|
|
262
|
+
padding so it no longer inflates the field, but a same-tier button still fills the content box edge
|
|
263
|
+
to edge.
|
|
264
|
+
|
|
265
|
+
Four things change versus a picker's default trigger, all deliberate:
|
|
266
|
+
|
|
267
|
+
- **Your element owns its accessible name**, so name it for the action ("Pick a date"). The default
|
|
268
|
+
trigger appends its value text to the name; `asChild` cannot, because there is no value span —
|
|
269
|
+
and a dangling `aria-labelledby` id would resolve the *entire* name to empty.
|
|
270
|
+
- **No `tui-input-group` chrome** is applied. That is the point (a bare button, not a bordered
|
|
271
|
+
field) and it is where the pickers diverge from `Select.Trigger`, which force-applies the class
|
|
272
|
+
even under `asChild`. It also means `aria-invalid` still lands on your element but paints nothing,
|
|
273
|
+
so an invalid trigger inside a `Field` needs one rule of your own:
|
|
274
|
+
|
|
275
|
+
```css
|
|
276
|
+
.my-date-trigger[aria-invalid='true'] {
|
|
277
|
+
border-color: var(--tui-theme-danger-base);
|
|
278
|
+
color: var(--tui-theme-danger-base);
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Everything else `Field` injects works unchanged — `Field.Label` reaches the accessible name, and
|
|
283
|
+
`Field.Error` is announced via `aria-describedby`.
|
|
284
|
+
- **`disabled` arrives as `aria-disabled` + `data-disabled`**, since your element may not be a
|
|
285
|
+
`<button>`. The popover refuses to open either way, in the open direction only — closing is never
|
|
286
|
+
blocked, so disabling a form mid-submit cannot strand an open popover.
|
|
287
|
+
- **Your element must be natively focusable and keyboard-activatable** — a `<button>` or `<a>`, not
|
|
288
|
+
a styled `<div>`. No key handler is attached under `asChild`; it relies on the child turning
|
|
289
|
+
Enter/Space into a click, which only real interactive elements do.
|
|
290
|
+
|
|
291
|
+
Your child's `onClick` still runs; call `preventDefault()` in it to suppress the toggle.
|
|
292
|
+
|
|
231
293
|
## Component names, and what isn't there
|
|
232
294
|
|
|
233
295
|
43 components. If you are hunting for a name: **Alert → `Notice`**, **Menu → `Dropdown`**,
|
|
234
296
|
**Table → `DataTable`**, **Pagination → `Pager`**, **Drawer → `Sidebar`** (drawer mode),
|
|
235
297
|
**Badge → `Chip`** or `ContentIndicator`, **Spinner → `Progress`** or `Button loading`.
|
|
236
|
-
No Toast/Snackbar, no Breadcrumb, no Skeleton, and no time picker —
|
|
237
|
-
`DateRangePicker`
|
|
298
|
+
No Toast/Snackbar, no Breadcrumb, no Skeleton, and no *standalone* time picker — but
|
|
299
|
+
`DatePicker` / `DateRangePicker` take `withTime` for an hour/minute field (12- or 24-hour via
|
|
300
|
+
`hour12`) plus a display-only `zoneLabel`; the value is a plain `Date` with wall-clock semantics,
|
|
301
|
+
so timezone interpretation stays yours.
|
|
238
302
|
|
|
239
303
|
Two clusters are easy to pick wrong:
|
|
240
304
|
|