@tangible/ui 0.2.11 → 0.2.12
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/README.md +35 -22
- package/components/Accordion/Accordion.js +2 -2
- package/components/Combobox/Combobox.js +37 -5
- package/components/Combobox/types.d.ts +6 -0
- package/components/DatePicker/DatePicker.d.ts +3 -0
- package/components/DatePicker/DatePicker.js +8 -2
- package/components/DatePicker/DateRangePicker.d.ts +3 -0
- package/components/DatePicker/DateRangePicker.js +8 -2
- package/components/DatePicker/types.d.ts +36 -0
- package/components/Dropdown/Dropdown.js +2 -1
- package/components/MultiCombobox/MultiCombobox.js +1 -1
- package/components/MultiSelect/MultiSelect.d.ts +1 -1
- package/components/MultiSelect/MultiSelect.js +29 -5
- package/components/MultiSelect/types.d.ts +13 -0
- package/components/Pager/Pager.d.ts +65 -1
- package/components/Pager/Pager.js +83 -10
- package/components/Pager/index.d.ts +1 -1
- package/components/Pager/types.d.ts +39 -0
- package/components/Pager/types.js +6 -0
- package/components/Popover/Popover.js +2 -1
- package/components/SearchSelect/SearchSelect.d.ts +1 -1
- package/components/SearchSelect/SearchSelect.js +3 -5
- package/components/SearchSelect/types.d.ts +0 -2
- package/components/Select/Select.d.ts +1 -1
- package/components/Select/Select.js +29 -5
- package/components/Select/types.d.ts +13 -0
- package/components/Table/DataTable.d.ts +6 -0
- package/components/Textarea/Textarea.js +7 -0
- package/components/Tooltip/Tooltip.js +2 -1
- package/components/index.d.ts +2 -2
- package/components/index.js +1 -1
- package/figma-tokens.json +4018 -0
- package/icons/icons.svg +12 -2
- package/icons/lms/index.d.ts +12 -0
- package/icons/lms/index.js +83 -17
- package/icons/manifest.json +80 -0
- package/icons/membersync/index.js +9 -9
- package/icons/player/index.js +4 -4
- package/icons/reaction/index.js +4 -4
- package/icons/registry.d.ts +20 -0
- package/icons/registry.js +10 -0
- package/icons/system/index.d.ts +8 -0
- package/icons/system/index.js +65 -21
- package/package.json +5 -1
- package/skills/building-with-tui/SKILL.md +328 -0
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +145 -256
- package/styles/all.expanded.unlayered.css +145 -256
- package/styles/all.unlayered.css +1 -1
- package/styles/components/color-picker.scss +16 -3
- package/styles/components/combobox.scss +33 -58
- package/styles/components/date-picker.scss +17 -9
- package/styles/components/dropdown.scss +11 -6
- package/styles/components/gradient-picker.scss +4 -4
- package/styles/components/multi-combobox.scss +17 -37
- package/styles/components/multi-select.scss +14 -50
- package/styles/components/pager.scss +155 -17
- package/styles/components/radio.scss +37 -0
- package/styles/components/search-select.scss +14 -36
- package/styles/components/select.scss +22 -51
- package/styles/components/text-input.scss +79 -21
- package/styles/system/_constants.scss +7 -1
- package/tui-manifest.json +143 -6
- package/utils/compose-refs.d.ts +29 -3
- package/utils/compose-refs.js +51 -12
package/README.md
CHANGED
|
@@ -4,14 +4,26 @@ Design system for Tangible WordPress plugins. React components, CSS custom prope
|
|
|
4
4
|
|
|
5
5
|
**Live Storybook:** https://storybook-tangible-ui.pages.dev
|
|
6
6
|
|
|
7
|
+
**Building an app with this?** Read
|
|
8
|
+
[`skills/building-with-tui/SKILL.md`](skills/building-with-tui/SKILL.md) first — it covers the
|
|
9
|
+
wiring that fails *silently* rather than erroring (the interface wrapper, portal hosts, the
|
|
10
|
+
dark-mode bridge, `Field`'s ARIA injection). It ships inside the package too, at
|
|
11
|
+
`node_modules/@tangible/ui/skills/building-with-tui/SKILL.md`, so a coding agent working in a
|
|
12
|
+
consuming repo can find it without this repo checked out.
|
|
13
|
+
|
|
7
14
|
## Components
|
|
8
15
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- **
|
|
12
|
-
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
16
|
+
43 components.
|
|
17
|
+
|
|
18
|
+
- **Primitives:** Button, IconButton, Icon, Chip, ChipGroup, Chips, Avatar, Progress, Rating,
|
|
19
|
+
Tooltip, ContentIndicator
|
|
20
|
+
- **Layout:** Accordion, Card, Modal, Notice, Popover, Sidebar, Tabs, Toolbar, OverlapStack
|
|
21
|
+
- **Data:** DataTable, Pager, StepList, StepIndicator, MoveHandle
|
|
22
|
+
- **Form controls:** TextInput, Textarea, SearchInput, Select, MultiSelect, Combobox,
|
|
23
|
+
MultiCombobox, SearchSelect, Checkbox, Switch, Radio/RadioGroup, SegmentedControl, Slider,
|
|
24
|
+
DatePicker, DateRangePicker, ColorPicker, ColorField, GradientPicker, Field
|
|
25
|
+
- **Menus:** Dropdown
|
|
26
|
+
- **CSS-only inputs:** text, textarea, select, checkbox, radio, toggle, file (no JS required)
|
|
15
27
|
|
|
16
28
|
## Getting Started
|
|
17
29
|
|
|
@@ -21,24 +33,19 @@ Design system for Tangible WordPress plugins. React components, CSS custom prope
|
|
|
21
33
|
npm install @tangible/ui
|
|
22
34
|
```
|
|
23
35
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
Some components require additional packages. Install only what you use:
|
|
36
|
+
That is the whole install — there is nothing else to add. Two runtime dependencies come with it:
|
|
27
37
|
|
|
28
|
-
| Package |
|
|
29
|
-
|
|
30
|
-
| `@floating-ui/react` | Select, MultiSelect, Combobox, Dropdown, Tooltip, Popover | ~90 KB |
|
|
38
|
+
| Package | Used by | Size |
|
|
39
|
+
|---------|---------|------|
|
|
40
|
+
| `@floating-ui/react` | Select, MultiSelect, Combobox, MultiCombobox, SearchSelect, Dropdown, Tooltip, Popover, DatePicker, ColorField | ~90 KB |
|
|
31
41
|
| `@tanstack/react-table` | DataTable | ~50 KB |
|
|
32
42
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
# If using DataTable
|
|
38
|
-
npm install @tanstack/react-table
|
|
39
|
-
```
|
|
43
|
+
They are declared as `dependencies`, not optional peers, so npm installs them whether or not you
|
|
44
|
+
import the components that need them. Both tree-shake out of your *bundle* if nothing reaches
|
|
45
|
+
them — the cost is install size, not shipped size.
|
|
40
46
|
|
|
41
|
-
|
|
47
|
+
One consequence under pnpm: `@tanstack/react-table` is transitive with no root symlink, so
|
|
48
|
+
`ColumnDef` will not resolve from your app code. Use `DataTableProps<T>['columns']` instead.
|
|
42
49
|
|
|
43
50
|
### Import styles
|
|
44
51
|
|
|
@@ -194,12 +201,15 @@ All form controls share a unified sizing system:
|
|
|
194
201
|
|
|
195
202
|
### Icons
|
|
196
203
|
|
|
197
|
-
|
|
204
|
+
Six sets in the registry, 237 icons: `system` (99), `lms` (44), `reaction` (36), `player` (24),
|
|
205
|
+
`membersync` (22), `cred` (12). Reference one by path; `IconName` is a literal union, so a typo
|
|
206
|
+
fails typecheck. `@tangible/ui/icons/manifest` is the machine-readable list.
|
|
198
207
|
|
|
199
208
|
```tsx
|
|
200
209
|
import { Icon } from '@tangible/ui';
|
|
201
210
|
|
|
202
|
-
<Icon name="system/check" />
|
|
211
|
+
<Icon name="system/check" /> {/* decorative — hidden from assistive tech */}
|
|
212
|
+
<Icon name="system/lock" label="Locked" /> {/* informative — label makes it announced */}
|
|
203
213
|
<Icon name="reaction/clap-fill" size="lg" />
|
|
204
214
|
```
|
|
205
215
|
|
|
@@ -224,6 +234,9 @@ npm run test:visual:update # Regenerate visual baselines
|
|
|
224
234
|
|
|
225
235
|
## Documentation
|
|
226
236
|
|
|
237
|
+
- `skills/building-with-tui/SKILL.md` — **Consuming** TUI: the wiring, the ARIA plumbing, and
|
|
238
|
+
the traps that fail silently. Written for coding agents; useful to people too. Shipped in the
|
|
239
|
+
published package.
|
|
227
240
|
- `CONTRIBUTING.md` — The pattern language: how components are built here
|
|
228
241
|
- `CLAUDE.md` — Architecture, patterns, conventions, gotchas
|
|
229
242
|
- `CONTEXT.md` — Project background and design philosophy
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import React, { cloneElement, isValidElement, useCallback, useId, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { cx } from '../../utils/cx.js';
|
|
4
|
-
import { composeRefs } from '../../utils/compose-refs.js';
|
|
4
|
+
import { composeRefs, getElementRef } from '../../utils/compose-refs.js';
|
|
5
5
|
import { mergeProps } from '../../utils/merge-props.js';
|
|
6
6
|
import { Icon } from '../Icon/index.js';
|
|
7
7
|
import { AccordionContext, AccordionItemContext, useAccordionContext, useAccordionItemContext } from './AccordionContext.js';
|
|
@@ -222,7 +222,7 @@ function AccordionTrigger({ asChild = false, 'aria-label': ariaLabel, children,
|
|
|
222
222
|
onClick: handleClick,
|
|
223
223
|
onKeyDown: handleKeyDown,
|
|
224
224
|
};
|
|
225
|
-
const childRef = children
|
|
225
|
+
const childRef = getElementRef(children);
|
|
226
226
|
const merged = mergeProps(children.props, triggerProps);
|
|
227
227
|
merged.ref = composeRefs(triggerRef, childRef);
|
|
228
228
|
const element = cloneElement(children, merged);
|
|
@@ -45,6 +45,7 @@ function ComboboxRoot({ value: controlledValue, defaultValue, onValueChange, inp
|
|
|
45
45
|
const { controlId: inputId, listboxId } = useListboxIds(inputIdProp, 'input');
|
|
46
46
|
// Refs
|
|
47
47
|
const inputRef = useRef(null);
|
|
48
|
+
const wrapperRef = useRef(null);
|
|
48
49
|
const listRef = useRef([]);
|
|
49
50
|
// Active index for navigation (-1 means no active option)
|
|
50
51
|
const [activeIndex, setActiveIndex] = useState(-1);
|
|
@@ -94,12 +95,38 @@ function ComboboxRoot({ value: controlledValue, defaultValue, onValueChange, inp
|
|
|
94
95
|
});
|
|
95
96
|
// Shared interaction stack (listbox engine) — no click/typeahead: the input
|
|
96
97
|
// opens itself and typing IS the search.
|
|
98
|
+
// The field box is the POSITION reference (the panel anchors and sizes to
|
|
99
|
+
// it); the input stays the DOM reference, which is what lets Floating UI read
|
|
100
|
+
// role="combobox" off it and leave Home/End to the text caret. Anchoring to
|
|
101
|
+
// the input put the panel inside the group's padding and over the field's
|
|
102
|
+
// bottom edge.
|
|
103
|
+
//
|
|
104
|
+
// Must be a stable callback: an inline arrow is a new function each render,
|
|
105
|
+
// so React detaches and reattaches it, and setPositionReference wraps the
|
|
106
|
+
// node in a fresh object and re-runs positioning — an infinite update loop.
|
|
107
|
+
const handleWrapperRef = useCallback((node) => {
|
|
108
|
+
wrapperRef.current = node;
|
|
109
|
+
refs.setPositionReference(node);
|
|
110
|
+
}, [refs]);
|
|
111
|
+
// Clicking anywhere in the field box types into it, the way a text field
|
|
112
|
+
// does. Without this the padding ring is a dead zone that also blurs.
|
|
113
|
+
const handleWrapperMouseDown = useCallback((e) => {
|
|
114
|
+
if (e.target !== inputRef.current) {
|
|
115
|
+
e.preventDefault();
|
|
116
|
+
inputRef.current?.focus();
|
|
117
|
+
}
|
|
118
|
+
}, []);
|
|
97
119
|
const { getReferenceProps, getFloatingProps, getItemProps } = useListboxNavigation(context, {
|
|
98
120
|
listRef,
|
|
99
121
|
activeIndex: activeIndex >= 0 ? activeIndex : null,
|
|
100
122
|
onNavigate: (index) => setActiveIndex(index ?? -1),
|
|
101
123
|
disabledIndices,
|
|
102
124
|
withClick: false,
|
|
125
|
+
// The whole field box belongs to this control, but only the input is the
|
|
126
|
+
// domReference — so a press on the wrapper's padding ring (or the chevron,
|
|
127
|
+
// which is pointer-events:none) would otherwise read as an outside press
|
|
128
|
+
// and dismiss the panel.
|
|
129
|
+
dismissOutsidePress: (event) => !(event.target instanceof Node && wrapperRef.current?.contains(event.target)),
|
|
103
130
|
});
|
|
104
131
|
// Active option ID for aria-activedescendant (hash-based for stability during filtering)
|
|
105
132
|
const activeOptionId = activeIndex >= 0 && orderedOptions[activeIndex]
|
|
@@ -208,6 +235,7 @@ function ComboboxRoot({ value: controlledValue, defaultValue, onValueChange, inp
|
|
|
208
235
|
unregisterOption,
|
|
209
236
|
refs,
|
|
210
237
|
inputRef,
|
|
238
|
+
wrapperRef,
|
|
211
239
|
listRef,
|
|
212
240
|
getReferenceProps,
|
|
213
241
|
getFloatingProps,
|
|
@@ -257,24 +285,28 @@ function ComboboxRoot({ value: controlledValue, defaultValue, onValueChange, inp
|
|
|
257
285
|
onBlur: handleInputBlur,
|
|
258
286
|
onKeyDown: handleInputKeyDown,
|
|
259
287
|
});
|
|
260
|
-
return (_jsx(ComboboxActionsContext.Provider, { value: actionsValue, children: _jsx(ComboboxStateContext.Provider, { value: stateValue, children: _jsxs("div", { className: "tui-combobox", children: [_jsxs("div", { className:
|
|
288
|
+
return (_jsx(ComboboxActionsContext.Provider, { value: actionsValue, children: _jsx(ComboboxStateContext.Provider, { value: stateValue, children: _jsxs("div", { className: "tui-combobox", children: [_jsxs("div", { ref: handleWrapperRef, className: cx('tui-input-group', 'tui-combobox__input-wrapper', size !== 'md' && `is-size-${size}`), onMouseDown: handleWrapperMouseDown, children: [_jsx("input", { ref: (node) => {
|
|
261
289
|
inputRef.current = node;
|
|
262
290
|
refs.setReference(node);
|
|
263
|
-
}, type: "text", id: inputId, className: cx('tui-combobox__input',
|
|
291
|
+
}, type: "text", id: inputId, className: cx('tui-combobox__input', inputClassName), role: "combobox", "aria-expanded": open, "aria-controls": open ? listboxId : undefined, "aria-autocomplete": "list", "aria-activedescendant": activeOptionId, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-required": ariaRequired, disabled: disabled, placeholder: placeholder, value: inputValue, autoComplete: "off", ...referenceProps, onChange: handleInputChange }), clearable && inputValue && !disabled && (_jsx("button", { type: "button", className: "tui-combobox__clear", onClick: handleClear, onMouseDown: (e) => e.preventDefault(), "aria-label": labels.clear, tabIndex: -1, children: _jsx(Icon, { name: "system/close" }) })), _jsx("span", { className: "tui-combobox__icon", "aria-hidden": "true", children: _jsx(Icon, { name: "system/chevron-down" }) })] }), children] }) }) }));
|
|
264
292
|
}
|
|
265
293
|
ComboboxRoot.displayName = 'Combobox';
|
|
266
294
|
// =============================================================================
|
|
267
295
|
// Combobox.Content
|
|
268
296
|
// =============================================================================
|
|
269
297
|
function ComboboxContentComponent({ className, children }) {
|
|
270
|
-
const { open, listboxId, inputId, refs, floatingStyles, getFloatingProps, listRef, activeIndex, orderedOptions, } = useComboboxContext();
|
|
298
|
+
const { open, listboxId, inputId, refs, floatingStyles, getFloatingProps, listRef, activeIndex, orderedOptions, wrapperRef, } = useComboboxContext();
|
|
271
299
|
// Track whether dropdown has ever been opened. Before first open, mount
|
|
272
300
|
// children in a hidden div for option registration (defaultValue resolution).
|
|
273
301
|
// After first open, only mount children when open (in portal).
|
|
274
302
|
const hasEverOpened = useRef(false);
|
|
275
303
|
if (open)
|
|
276
304
|
hasEverOpened.current = true;
|
|
277
|
-
|
|
305
|
+
// Both of these want the field box, and asking Floating UI for it is the
|
|
306
|
+
// wrong move: with a position reference set, refs.reference.current is no
|
|
307
|
+
// longer guaranteed to be a DOM element (it can be a virtual element), and
|
|
308
|
+
// getPortalRootFor calls .closest() on it. Use the wrapper ref directly.
|
|
309
|
+
const portalRoot = getPortalRootFor(wrapperRef.current);
|
|
278
310
|
const contentContext = useMemo(() => ({
|
|
279
311
|
listRef,
|
|
280
312
|
activeIndex,
|
|
@@ -283,7 +315,7 @@ function ComboboxContentComponent({ className, children }) {
|
|
|
283
315
|
// Always render for option registration
|
|
284
316
|
return (_jsxs(_Fragment, { children: [!open && !hasEverOpened.current && (_jsx("div", { id: listboxId, role: "listbox", style: { display: 'none' }, "aria-hidden": "true", children: _jsx(ComboboxContentContext.Provider, { value: contentContext, children: children }) })), open && (_jsx(FloatingPortal, { root: portalRoot, children: _jsx("div", { ref: refs.setFloating, id: listboxId, role: "listbox", "aria-labelledby": inputId, className: cx('tui-combobox__content', className), style: {
|
|
285
317
|
...floatingStyles,
|
|
286
|
-
minWidth:
|
|
318
|
+
minWidth: wrapperRef.current?.offsetWidth,
|
|
287
319
|
pointerEvents: 'auto',
|
|
288
320
|
}, tabIndex: -1, ...getFloatingProps(), children: _jsx(ComboboxContentContext.Provider, { value: contentContext, children: children }) }) }))] }));
|
|
289
321
|
}
|
|
@@ -197,6 +197,12 @@ export type ComboboxActionsContextValue = {
|
|
|
197
197
|
setFloating: (node: HTMLElement | null) => void;
|
|
198
198
|
};
|
|
199
199
|
inputRef: RefObject<HTMLInputElement | null>;
|
|
200
|
+
/**
|
|
201
|
+
* The field box (.tui-combobox__input-wrapper) — the input-group host. Content
|
|
202
|
+
* anchors the portal root and the panel's min-width to it, not to the input,
|
|
203
|
+
* which is inset by the group's padding.
|
|
204
|
+
*/
|
|
205
|
+
wrapperRef: RefObject<HTMLDivElement | null>;
|
|
200
206
|
listRef: MutableRefObject<(HTMLElement | null)[]>;
|
|
201
207
|
getReferenceProps: (userProps?: React.HTMLProps<Element>) => Record<string, unknown>;
|
|
202
208
|
getFloatingProps: (userProps?: React.HTMLProps<HTMLElement>) => Record<string, unknown>;
|
|
@@ -18,6 +18,9 @@ export declare const DatePicker: React.ForwardRefExoticComponent<import("./types
|
|
|
18
18
|
labels?: import("./types").DatePickerLabels;
|
|
19
19
|
calendarLabels?: import("./types").CalendarLabels;
|
|
20
20
|
'aria-label'?: string;
|
|
21
|
+
'aria-labelledby'?: string;
|
|
22
|
+
'aria-describedby'?: string;
|
|
23
|
+
'aria-invalid'?: boolean | "true" | "false";
|
|
21
24
|
className?: string;
|
|
22
25
|
id?: string;
|
|
23
26
|
} & React.RefAttributes<HTMLButtonElement>>;
|
|
@@ -73,10 +73,16 @@ export function TimeField({ value, onChange, hour12, zoneLabel, labels, }) {
|
|
|
73
73
|
setHours(next === 'pm' ? base + 12 : base);
|
|
74
74
|
}, children: [_jsx(SegmentedControl.Item, { value: "am", children: labels.am }), _jsx(SegmentedControl.Item, { value: "pm", children: labels.pm })] })), zoneLabel != null && _jsx("span", { className: "tui-date-picker__zone", children: zoneLabel })] }));
|
|
75
75
|
}
|
|
76
|
-
export const DatePicker = React.forwardRef(function DatePicker({ value: valueProp, defaultValue, onChange, withTime = false, hour12 = true, zoneLabel, min, max, isDayDisabled, weekStartsOn = 1, locale: localeProp, disabled, labels: labelsProp, calendarLabels, 'aria-label': ariaLabel, className, id, }, ref) {
|
|
76
|
+
export const DatePicker = React.forwardRef(function DatePicker({ value: valueProp, defaultValue, onChange, withTime = false, hour12 = true, zoneLabel, min, max, isDayDisabled, weekStartsOn = 1, locale: localeProp, disabled, labels: labelsProp, calendarLabels, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, className, id, }, ref) {
|
|
77
77
|
const labels = { ...defaultDatePickerLabels, ...labelsProp };
|
|
78
78
|
const locale = resolveLocale(localeProp);
|
|
79
79
|
const [open, setOpen] = React.useState(false);
|
|
80
|
+
// The value span joins the accessible name when a label is injected, so the
|
|
81
|
+
// chosen date stays audible instead of being replaced by the label alone.
|
|
82
|
+
const generatedId = React.useId();
|
|
83
|
+
// useId unconditionally — `id ?? React.useId()` short-circuits the hook,
|
|
84
|
+
// so the hook order would change if `id` ever went from set to unset.
|
|
85
|
+
const valueId = `${id ?? generatedId}-value`;
|
|
80
86
|
const [value, setValue] = useControllableState({
|
|
81
87
|
value: valueProp,
|
|
82
88
|
defaultValue: defaultValue ?? null,
|
|
@@ -105,7 +111,7 @@ export const DatePicker = React.forwardRef(function DatePicker({ value: valuePro
|
|
|
105
111
|
: formatDay(value, locale)
|
|
106
112
|
: null;
|
|
107
113
|
const monthNames = getMonthNames(locale);
|
|
108
|
-
return (_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { ref: ref, type: "button", id: id, disabled: disabled, className: cx('tui-input-group', 'tui-date-picker__trigger', disabled && 'is-disabled', className), "aria-haspopup": "dialog", "aria-expanded": open, "aria-label": ariaLabel ?? (formatted ? labels.trigger(formatted) : labels.triggerEmpty), children: [_jsx("span", { className: cx('tui-date-picker__trigger-value', !formatted && 'is-placeholder'), children: formatted ?? labels.placeholder }), _jsx("span", { className: "tui-input-group__suffix", children: _jsx(Icon, { name: "lms/calendar", size: "sm" }) })] }) }), _jsxs(PopoverContent, { modal: true, side: "bottom", align: "start", className: "tui-date-picker", "aria-label": title, children: [_jsxs("div", { className: "tui-date-picker__head", children: [_jsx("span", { className: "tui-date-picker__title", children: title }), _jsx(Button, { className: "tui-date-picker__now", variant: "ghost", theme: "primary", size: "sm", label: labels.now, onClick: () => commit(clampDay(new Date(), min, max)) }), _jsx(IconButton, { className: "tui-date-picker__close", icon: "system/close", label: labels.close, variant: "ghost", size: "sm", onClick: () => setOpen(false) })] }), withTime && (_jsx(TimeField, { value: base, onChange: commit, hour12: hour12, zoneLabel: zoneLabel, labels: labels })), _jsxs("div", { className: "tui-date-picker__fields", role: "group", "aria-label": labels.dateSection, children: [_jsx("div", { className: "tui-date-picker__month", children: _jsxs(Select, { value: String(base.getMonth()), onValueChange: (m) => {
|
|
114
|
+
return (_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { ref: ref, type: "button", id: id, disabled: disabled, className: cx('tui-input-group', 'tui-date-picker__trigger', disabled && 'is-disabled', className), "aria-haspopup": "dialog", "aria-expanded": open, "aria-label": ariaLabel ?? (formatted ? labels.trigger(formatted) : labels.triggerEmpty), "aria-labelledby": ariaLabelledBy ? `${ariaLabelledBy} ${valueId}` : undefined, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, children: [_jsx("span", { id: valueId, className: cx('tui-date-picker__trigger-value', !formatted && 'is-placeholder'), children: formatted ?? labels.placeholder }), _jsx("span", { className: "tui-input-group__suffix", children: _jsx(Icon, { name: "lms/calendar", size: "sm" }) })] }) }), _jsxs(PopoverContent, { modal: true, side: "bottom", align: "start", className: "tui-date-picker", "aria-label": title, children: [_jsxs("div", { className: "tui-date-picker__head", children: [_jsx("span", { className: "tui-date-picker__title", children: title }), _jsx(Button, { className: "tui-date-picker__now", variant: "ghost", theme: "primary", size: "sm", label: labels.now, onClick: () => commit(clampDay(new Date(), min, max)) }), _jsx(IconButton, { className: "tui-date-picker__close", icon: "system/close", label: labels.close, variant: "ghost", size: "sm", onClick: () => setOpen(false) })] }), withTime && (_jsx(TimeField, { value: base, onChange: commit, hour12: hour12, zoneLabel: zoneLabel, labels: labels })), _jsxs("div", { className: "tui-date-picker__fields", role: "group", "aria-label": labels.dateSection, children: [_jsx("div", { className: "tui-date-picker__month", children: _jsxs(Select, { value: String(base.getMonth()), onValueChange: (m) => {
|
|
109
115
|
const next = new Date(base);
|
|
110
116
|
next.setDate(Math.min(next.getDate(), daysInMonth(new Date(next.getFullYear(), Number(m), 1))));
|
|
111
117
|
next.setMonth(Number(m));
|
|
@@ -11,6 +11,9 @@ export declare const DateRangePicker: React.ForwardRefExoticComponent<import("./
|
|
|
11
11
|
labels?: import("./types").DateRangePickerLabels;
|
|
12
12
|
calendarLabels?: import("./types").CalendarLabels;
|
|
13
13
|
'aria-label'?: string;
|
|
14
|
+
'aria-labelledby'?: string;
|
|
15
|
+
'aria-describedby'?: string;
|
|
16
|
+
'aria-invalid'?: boolean | "true" | "false";
|
|
14
17
|
className?: string;
|
|
15
18
|
id?: string;
|
|
16
19
|
} & React.RefAttributes<HTMLButtonElement>>;
|
|
@@ -21,10 +21,16 @@ import { defaultDateRangePickerLabels } from './types.js';
|
|
|
21
21
|
//
|
|
22
22
|
// =============================================================================
|
|
23
23
|
const EMPTY_RANGE = { from: null, to: null };
|
|
24
|
-
export const DateRangePicker = React.forwardRef(function DateRangePicker({ value: valueProp, defaultValue, onChange, withTime = false, presets = defaultDateRangePresets, min, max, isDayDisabled, weekStartsOn = 1, locale: localeProp, disabled, labels: labelsProp, calendarLabels, 'aria-label': ariaLabel, className, id, }, ref) {
|
|
24
|
+
export const DateRangePicker = React.forwardRef(function DateRangePicker({ value: valueProp, defaultValue, onChange, withTime = false, presets = defaultDateRangePresets, min, max, isDayDisabled, weekStartsOn = 1, locale: localeProp, disabled, labels: labelsProp, calendarLabels, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, className, id, }, ref) {
|
|
25
25
|
const labels = { ...defaultDateRangePickerLabels, ...labelsProp };
|
|
26
26
|
const locale = resolveLocale(localeProp);
|
|
27
27
|
const [open, setOpen] = React.useState(false);
|
|
28
|
+
// The value span joins the accessible name when a label is injected, so the
|
|
29
|
+
// chosen range stays audible instead of being replaced by the label alone.
|
|
30
|
+
const generatedId = React.useId();
|
|
31
|
+
// useId unconditionally — `id ?? React.useId()` short-circuits the hook,
|
|
32
|
+
// so the hook order would change if `id` ever went from set to unset.
|
|
33
|
+
const valueId = `${id ?? generatedId}-value`;
|
|
28
34
|
const [value, setValue] = useControllableState({
|
|
29
35
|
value: valueProp,
|
|
30
36
|
defaultValue: defaultValue ?? null,
|
|
@@ -78,7 +84,7 @@ export const DateRangePicker = React.forwardRef(function DateRangePicker({ value
|
|
|
78
84
|
// Second calendar stays one month ahead; hide nav overlap by letting the
|
|
79
85
|
// left calendar own "previous" and the right own "next".
|
|
80
86
|
const showPresets = presets !== false && presets.length > 0;
|
|
81
|
-
return (_jsxs(Popover, { open: open, onOpenChange: handleOpenChange, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { ref: ref, type: "button", id: id, disabled: disabled, className: cx('tui-input-group', 'tui-date-range-picker__trigger', disabled && 'is-disabled', className), "aria-haspopup": "dialog", "aria-expanded": open, "aria-label": ariaLabel ?? (formatted ? labels.trigger(formatted) : labels.triggerEmpty), children: [_jsx("span", { className: cx('tui-date-range-picker__trigger-value', !formatted && 'is-placeholder'), children: formatted ?? labels.placeholder }), _jsx("span", { className: "tui-input-group__suffix", children: _jsx(Icon, { name: "lms/calendar", size: "sm" }) })] }) }), _jsxs(PopoverContent, { modal: true, side: "bottom", align: "start", className: "tui-date-range-picker", "aria-label": labels.triggerEmpty, children: [_jsxs("div", { className: "tui-date-range-picker__body", children: [showPresets && (_jsx("div", { className: "tui-date-range-picker__presets", role: "group", "aria-label": labels.presets, children: presets.map((preset) => (_jsx(Button, { className: "tui-date-range-picker__preset", variant: "ghost", theme: "primary", size: "sm", label: preset.label, onClick: () => applyPreset(preset) }, preset.label))) })), _jsxs("div", { className: "tui-date-range-picker__main", children: [_jsxs("div", { className: "tui-date-range-picker__fields", children: [_jsx(RangeField, { label: labels.from, value: fieldText(draft.from), locale: locale, onCommit: (d) => {
|
|
87
|
+
return (_jsxs(Popover, { open: open, onOpenChange: handleOpenChange, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { ref: ref, type: "button", id: id, disabled: disabled, className: cx('tui-input-group', 'tui-date-range-picker__trigger', disabled && 'is-disabled', className), "aria-haspopup": "dialog", "aria-expanded": open, "aria-label": ariaLabel ?? (formatted ? labels.trigger(formatted) : labels.triggerEmpty), "aria-labelledby": ariaLabelledBy ? `${ariaLabelledBy} ${valueId}` : undefined, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, children: [_jsx("span", { id: valueId, className: cx('tui-date-range-picker__trigger-value', !formatted && 'is-placeholder'), children: formatted ?? labels.placeholder }), _jsx("span", { className: "tui-input-group__suffix", children: _jsx(Icon, { name: "lms/calendar", size: "sm" }) })] }) }), _jsxs(PopoverContent, { modal: true, side: "bottom", align: "start", className: "tui-date-range-picker", "aria-label": labels.triggerEmpty, children: [_jsxs("div", { className: "tui-date-range-picker__body", children: [showPresets && (_jsx("div", { className: "tui-date-range-picker__presets", role: "group", "aria-label": labels.presets, children: presets.map((preset) => (_jsx(Button, { className: "tui-date-range-picker__preset", variant: "ghost", theme: "primary", size: "sm", label: preset.label, onClick: () => applyPreset(preset) }, preset.label))) })), _jsxs("div", { className: "tui-date-range-picker__main", children: [_jsxs("div", { className: "tui-date-range-picker__fields", children: [_jsx(RangeField, { label: labels.from, value: fieldText(draft.from), locale: locale, onCommit: (d) => {
|
|
82
88
|
setDraft((prev) => {
|
|
83
89
|
const next = { ...prev, from: d };
|
|
84
90
|
if (next.to && isBeforeDay(next.to, d))
|
|
@@ -98,6 +98,24 @@ export type DatePickerProps = CalendarBaseProps & {
|
|
|
98
98
|
labels?: DatePickerLabels;
|
|
99
99
|
calendarLabels?: CalendarLabels;
|
|
100
100
|
'aria-label'?: string;
|
|
101
|
+
/**
|
|
102
|
+
* ID of the element that labels the trigger. `Field.Control` injects this,
|
|
103
|
+
* and it outranks `aria-label` per AccName 2A — which is why the trigger's
|
|
104
|
+
* own `aria-label` fallback does not have to change. The trigger's value span
|
|
105
|
+
* is appended so the current date stays audible.
|
|
106
|
+
*/
|
|
107
|
+
'aria-labelledby'?: string;
|
|
108
|
+
/**
|
|
109
|
+
* ID of element(s) that describe the trigger. `Field.Control` injects this
|
|
110
|
+
* so helper text and errors are announced; without it the injection is
|
|
111
|
+
* silently dropped (no rest-spread on this component).
|
|
112
|
+
*/
|
|
113
|
+
'aria-describedby'?: string;
|
|
114
|
+
/**
|
|
115
|
+
* Marks the control invalid. Lands on the trigger button, which also wears
|
|
116
|
+
* `tui-input-group` — that is what lights the danger border.
|
|
117
|
+
*/
|
|
118
|
+
'aria-invalid'?: boolean | 'true' | 'false';
|
|
101
119
|
className?: string;
|
|
102
120
|
id?: string;
|
|
103
121
|
};
|
|
@@ -133,6 +151,24 @@ export type DateRangePickerProps = CalendarBaseProps & {
|
|
|
133
151
|
labels?: DateRangePickerLabels;
|
|
134
152
|
calendarLabels?: CalendarLabels;
|
|
135
153
|
'aria-label'?: string;
|
|
154
|
+
/**
|
|
155
|
+
* ID of the element that labels the trigger. `Field.Control` injects this,
|
|
156
|
+
* and it outranks `aria-label` per AccName 2A — which is why the trigger's
|
|
157
|
+
* own `aria-label` fallback does not have to change. The trigger's value span
|
|
158
|
+
* is appended so the current date stays audible.
|
|
159
|
+
*/
|
|
160
|
+
'aria-labelledby'?: string;
|
|
161
|
+
/**
|
|
162
|
+
* ID of element(s) that describe the trigger. `Field.Control` injects this
|
|
163
|
+
* so helper text and errors are announced; without it the injection is
|
|
164
|
+
* silently dropped (no rest-spread on this component).
|
|
165
|
+
*/
|
|
166
|
+
'aria-describedby'?: string;
|
|
167
|
+
/**
|
|
168
|
+
* Marks the control invalid. Lands on the trigger button, which also wears
|
|
169
|
+
* `tui-input-group` — that is what lights the danger border.
|
|
170
|
+
*/
|
|
171
|
+
'aria-invalid'?: boolean | 'true' | 'false';
|
|
136
172
|
className?: string;
|
|
137
173
|
id?: string;
|
|
138
174
|
};
|
|
@@ -3,6 +3,7 @@ import React, { useCallback, useEffect, useLayoutEffect, useId, useMemo, useRef,
|
|
|
3
3
|
import { useFloating, offset, flip, shift, autoUpdate, FloatingPortal, useDismiss, useInteractions, useListNavigation, useRole, FloatingFocusManager, } from '@floating-ui/react';
|
|
4
4
|
import { cx } from '../../utils/cx.js';
|
|
5
5
|
import { getPortalRootFor } from '../../utils/portal.js';
|
|
6
|
+
import { getElementRef } from '../../utils/compose-refs.js';
|
|
6
7
|
import { Button } from '../Button/index.js';
|
|
7
8
|
import { DropdownContext, useDropdownContext } from './DropdownContext.js';
|
|
8
9
|
import { toPlacement } from './types.js';
|
|
@@ -83,7 +84,7 @@ function DropdownTriggerComponent({ asChild = false, children }) {
|
|
|
83
84
|
const setRefs = useCallback((node) => {
|
|
84
85
|
triggerRef.current = node;
|
|
85
86
|
if (asChild && isValidElement(children)) {
|
|
86
|
-
const childRef = children
|
|
87
|
+
const childRef = getElementRef(children);
|
|
87
88
|
if (typeof childRef === 'function') {
|
|
88
89
|
childRef(node);
|
|
89
90
|
}
|
|
@@ -384,7 +384,7 @@ function MultiComboboxRoot({ value: controlledValue, defaultValue, onValueChange
|
|
|
384
384
|
// Note: chips carry no size prop — token-field chips size em-relative to
|
|
385
385
|
// the host control (0.875em in styles.scss), which outranks Chip's
|
|
386
386
|
// font-size presets, so a size here would be dead code.
|
|
387
|
-
return (_jsx(MultiComboboxActionsContext.Provider, { value: actionsValue, children: _jsx(MultiComboboxStateContext.Provider, { value: stateValue, children: _jsxs("div", { className: "tui-multicombobox", children: [_jsxs("div", { ref: refs.setReference, className: cx('tui-multicombobox__control', size !== 'md' && `is-size-${size}`, overflow === 'trim' && 'is-overflow-trim'), "data-overflow-start": overflow === 'trim' && overflowStart ? '' : undefined, onMouseDown: handleWrapperMouseDown, children: [_jsxs("div", { ref: tokensRef, className: "tui-multicombobox__tokens", onScroll: overflow === 'trim' ? handleTokensScroll : undefined, children: [value.map((v) => {
|
|
387
|
+
return (_jsx(MultiComboboxActionsContext.Provider, { value: actionsValue, children: _jsx(MultiComboboxStateContext.Provider, { value: stateValue, children: _jsxs("div", { className: "tui-multicombobox", children: [_jsxs("div", { ref: refs.setReference, className: cx('tui-input-group', 'tui-multicombobox__control', size !== 'md' && `is-size-${size}`, overflow === 'trim' && 'is-overflow-trim'), "data-overflow-start": overflow === 'trim' && overflowStart ? '' : undefined, onMouseDown: handleWrapperMouseDown, children: [_jsxs("div", { ref: tokensRef, className: "tui-multicombobox__tokens", onScroll: overflow === 'trim' ? handleTokensScroll : undefined, children: [value.map((v) => {
|
|
388
388
|
const label = labelFor(v);
|
|
389
389
|
return (_jsx(Chip, { className: "tui-multicombobox__chip", disabled: disabled, removeLabel: labels.remove(label), onRemove: () => removeValue(v), children: label }, toKey(v)));
|
|
390
390
|
}), _jsx("input", { ref: (node) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type MultiSelectProps, type MultiSelectTriggerProps, type MultiSelectContentProps, type MultiSelectOptionProps } from './types';
|
|
2
|
-
declare function MultiSelectRoot({ id: triggerIdProp, value: controlledValue, defaultValue, onValueChange, open: controlledOpen, defaultOpen, onOpenChange, disabled, placeholder, size, display, maxChips, max, onMaxReached, labels: labelsProp, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, children, }: MultiSelectProps): import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
declare function MultiSelectRoot({ id: triggerIdProp, value: controlledValue, defaultValue, onValueChange, open: controlledOpen, defaultOpen, onOpenChange, disabled, placeholder, size, display, maxChips, max, onMaxReached, labels: labelsProp, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'aria-required': ariaRequired, children, }: MultiSelectProps): import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
declare namespace MultiSelectRoot {
|
|
4
4
|
var displayName: string;
|
|
5
5
|
}
|
|
@@ -3,6 +3,7 @@ import React, { useCallback, useEffect, useMemo, useRef, useState, cloneElement,
|
|
|
3
3
|
import { FloatingPortal } from '@floating-ui/react';
|
|
4
4
|
import { cx } from '../../utils/cx.js';
|
|
5
5
|
import { getPortalRootFor } from '../../utils/portal.js';
|
|
6
|
+
import { composeRefs, getElementRef } from '../../utils/compose-refs.js';
|
|
6
7
|
import { useOptionRegistry, useOptionRegistration, useListboxIds, useListboxFloating, useListboxNavigation, useListboxBlurGuard, useTriggerPointerDownFix, useFocusTriggerOnOpen, useActiveOptionScroll, optionIdForIndex, createListboxGroupComponents, } from '../../utils/listbox/index.js';
|
|
7
8
|
import { Icon } from '../Icon/index.js';
|
|
8
9
|
import { Chip } from '../Chip/index.js';
|
|
@@ -11,7 +12,7 @@ import { toKey, defaultMultiSelectLabels, } from './types.js';
|
|
|
11
12
|
// =============================================================================
|
|
12
13
|
// MultiSelect Root
|
|
13
14
|
// =============================================================================
|
|
14
|
-
function MultiSelectRoot({ id: triggerIdProp, value: controlledValue, defaultValue, onValueChange, open: controlledOpen, defaultOpen, onOpenChange, disabled = false, placeholder = '', size = 'md', display = 'count', maxChips = 3, max, onMaxReached, labels: labelsProp, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, children, }) {
|
|
15
|
+
function MultiSelectRoot({ id: triggerIdProp, value: controlledValue, defaultValue, onValueChange, open: controlledOpen, defaultOpen, onOpenChange, disabled = false, placeholder = '', size = 'md', display = 'count', maxChips = 3, max, onMaxReached, labels: labelsProp, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'aria-required': ariaRequired, children, }) {
|
|
15
16
|
// Merge caller labels with defaults
|
|
16
17
|
const labels = useMemo(() => ({ ...defaultMultiSelectLabels, ...labelsProp }), [labelsProp]);
|
|
17
18
|
// Controlled/uncontrolled value
|
|
@@ -217,6 +218,8 @@ function MultiSelectRoot({ id: triggerIdProp, value: controlledValue, defaultVal
|
|
|
217
218
|
ariaLabel,
|
|
218
219
|
ariaLabelledBy,
|
|
219
220
|
ariaDescribedBy,
|
|
221
|
+
ariaInvalid,
|
|
222
|
+
ariaRequired,
|
|
220
223
|
// Stable callbacks
|
|
221
224
|
setOpen,
|
|
222
225
|
toggleOption,
|
|
@@ -245,6 +248,8 @@ function MultiSelectRoot({ id: triggerIdProp, value: controlledValue, defaultVal
|
|
|
245
248
|
ariaLabel,
|
|
246
249
|
ariaLabelledBy,
|
|
247
250
|
ariaDescribedBy,
|
|
251
|
+
ariaInvalid,
|
|
252
|
+
ariaRequired,
|
|
248
253
|
// Callbacks are stable (useCallback with stable deps)
|
|
249
254
|
setOpen,
|
|
250
255
|
toggleOption,
|
|
@@ -295,7 +300,7 @@ MultiSelectRoot.displayName = 'MultiSelect';
|
|
|
295
300
|
// MultiSelect.Trigger
|
|
296
301
|
// =============================================================================
|
|
297
302
|
function MultiSelectTriggerComponent({ asChild = false, className, children, }) {
|
|
298
|
-
const { open, setOpen, disabled, placeholder, size, display, maxChips, max, maxReached, labels, triggerId, listboxId, ariaLabel, ariaLabelledBy, ariaDescribedBy, getSelectedOptions, clearAll, refs, getReferenceProps, activeIndex, orderedOptions, toggleOption, isSelected, } = useMultiSelectContext();
|
|
303
|
+
const { open, setOpen, disabled, placeholder, size, display, maxChips, max, maxReached, labels, triggerId, listboxId, ariaLabel, ariaLabelledBy, ariaDescribedBy, ariaInvalid, ariaRequired, getSelectedOptions, clearAll, refs, getReferenceProps, activeIndex, orderedOptions, toggleOption, isSelected, } = useMultiSelectContext();
|
|
299
304
|
const sizeClass = size !== 'md' ? `is-size-${size}` : undefined;
|
|
300
305
|
const selectedOptions = getSelectedOptions();
|
|
301
306
|
const hasSelection = selectedOptions.length > 0;
|
|
@@ -369,11 +374,28 @@ function MultiSelectTriggerComponent({ asChild = false, className, children, })
|
|
|
369
374
|
// Live region (rendered outside button, sibling to trigger)
|
|
370
375
|
const liveRegion = (_jsx("span", { className: "tui-visually-hidden", role: "status", "aria-live": "polite", "aria-atomic": "true", children: statusMessage }));
|
|
371
376
|
// Base trigger props
|
|
377
|
+
// asChild: compose the child's own ref with Floating UI's reference setter.
|
|
378
|
+
// Without this the child's ref is silently discarded — a consumer passing
|
|
379
|
+
// <MultiSelect.Trigger asChild><MyButton ref={myRef}/></MultiSelect.Trigger>
|
|
380
|
+
// never gets a node, with no error to explain why.
|
|
381
|
+
//
|
|
382
|
+
// Computed unconditionally and memoised, not inside the asChild branch below:
|
|
383
|
+
// hooks cannot be conditional, and an inline composeRefs would hand React a
|
|
384
|
+
// new callback on every render, detaching and re-attaching the reference each
|
|
385
|
+
// time. Floating UI's own setReference is stable, so that churn would be a
|
|
386
|
+
// real regression for a popup that re-renders per keystroke.
|
|
387
|
+
const childRef = asChild && isValidElement(children) ? getElementRef(children) : undefined;
|
|
388
|
+
const composedReferenceRef = React.useMemo(() => composeRefs(refs.setReference, childRef), [refs.setReference, childRef]);
|
|
372
389
|
const triggerProps = {
|
|
373
390
|
id: triggerId,
|
|
374
391
|
'aria-label': ariaLabel,
|
|
375
392
|
'aria-labelledby': ariaLabelledBy,
|
|
376
393
|
'aria-describedby': ariaDescribedBy,
|
|
394
|
+
// Both land on the trigger, which also carries `tui-input-group` — the
|
|
395
|
+
// shared primitive keys its danger border off [aria-invalid="true"] on
|
|
396
|
+
// that same element. Putting them on an inner node fails silently.
|
|
397
|
+
'aria-invalid': ariaInvalid,
|
|
398
|
+
'aria-required': ariaRequired,
|
|
377
399
|
'aria-haspopup': 'listbox',
|
|
378
400
|
'aria-expanded': open,
|
|
379
401
|
'aria-controls': open ? listboxId : undefined,
|
|
@@ -405,17 +427,19 @@ function MultiSelectTriggerComponent({ asChild = false, className, children, })
|
|
|
405
427
|
...childProps,
|
|
406
428
|
// Re-assert must-have props that child cannot override
|
|
407
429
|
id: triggerId,
|
|
408
|
-
ref:
|
|
430
|
+
ref: composedReferenceRef,
|
|
409
431
|
'aria-haspopup': 'listbox',
|
|
410
432
|
'aria-expanded': open,
|
|
411
433
|
'aria-controls': open ? listboxId : undefined,
|
|
412
434
|
'aria-activedescendant': floatingProps['aria-activedescendant'],
|
|
413
435
|
'aria-describedby': ariaDescribedBy,
|
|
436
|
+
'aria-invalid': ariaInvalid,
|
|
437
|
+
'aria-required': ariaRequired,
|
|
414
438
|
// asChild: use aria-disabled + data-disabled since element may not support native disabled
|
|
415
439
|
'aria-disabled': disabled || undefined,
|
|
416
440
|
'data-state': open ? 'open' : 'closed',
|
|
417
441
|
'data-disabled': disabled || undefined,
|
|
418
|
-
className: cx(childProps.className, 'tui-multiselect__trigger', sizeClass, className),
|
|
442
|
+
className: cx(childProps.className, 'tui-input-group', 'tui-multiselect__trigger', sizeClass, className),
|
|
419
443
|
// Composed handlers override both spreads
|
|
420
444
|
onClick: composeHandler(triggerProps.onClick, childProps.onClick),
|
|
421
445
|
// Handle Backspace/Delete before composed handlers (typeahead may intercept)
|
|
@@ -436,7 +460,7 @@ function MultiSelectTriggerComponent({ asChild = false, className, children, })
|
|
|
436
460
|
}
|
|
437
461
|
// Default: render button with optional custom content
|
|
438
462
|
const triggerContent = children ?? defaultTriggerContent;
|
|
439
|
-
return (_jsxs(_Fragment, { children: [_jsx("button", { ref: refs.setReference, type: "button", id: triggerId, className: cx('tui-multiselect__trigger', sizeClass, className), disabled: disabled, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-haspopup": "listbox", "aria-expanded": open, "aria-controls": open ? listboxId : undefined, "data-state": open ? 'open' : 'closed', ...floatingProps,
|
|
463
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { ref: refs.setReference, type: "button", id: triggerId, className: cx('tui-input-group', 'tui-multiselect__trigger', sizeClass, className), disabled: disabled, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-required": ariaRequired, "aria-haspopup": "listbox", "aria-expanded": open, "aria-controls": open ? listboxId : undefined, "data-state": open ? 'open' : 'closed', ...floatingProps,
|
|
440
464
|
// Handle Backspace/Delete AFTER floatingProps to ensure we catch it
|
|
441
465
|
// (typeahead may intercept these for its buffer)
|
|
442
466
|
onKeyDown: (e) => {
|
|
@@ -118,6 +118,17 @@ export type MultiSelectProps = {
|
|
|
118
118
|
* ID of element(s) that describe this select.
|
|
119
119
|
*/
|
|
120
120
|
'aria-describedby'?: string;
|
|
121
|
+
/**
|
|
122
|
+
* Marks the control invalid. Lands on the trigger, which also wears
|
|
123
|
+
* `tui-input-group` — that is what lights the danger border.
|
|
124
|
+
* Injected automatically by `Field.Control` when the Field has an error.
|
|
125
|
+
*/
|
|
126
|
+
'aria-invalid'?: boolean | 'true' | 'false';
|
|
127
|
+
/**
|
|
128
|
+
* Marks the control required. Injected automatically by `Field.Control`
|
|
129
|
+
* when the Field is required.
|
|
130
|
+
*/
|
|
131
|
+
'aria-required'?: boolean | 'true' | 'false';
|
|
121
132
|
/**
|
|
122
133
|
* Optional trigger ID override.
|
|
123
134
|
* Useful for Field integration via htmlFor.
|
|
@@ -205,6 +216,8 @@ export type MultiSelectActionsContextValue = {
|
|
|
205
216
|
ariaLabel?: string;
|
|
206
217
|
ariaLabelledBy?: string;
|
|
207
218
|
ariaDescribedBy?: string;
|
|
219
|
+
ariaInvalid?: boolean | 'true' | 'false';
|
|
220
|
+
ariaRequired?: boolean | 'true' | 'false';
|
|
208
221
|
setOpen: (open: boolean) => void;
|
|
209
222
|
toggleOption: (optionValue: OptionValue, textValue: string) => void;
|
|
210
223
|
clearAll: () => void;
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import type { SizeStandard } from '../../types/sizes';
|
|
2
2
|
import { type PagerLabels } from './types';
|
|
3
3
|
export type PagerMode = 'simple' | 'ends' | 'full' | 'smart';
|
|
4
|
+
/**
|
|
5
|
+
* Relationship between nav segments.
|
|
6
|
+
*
|
|
7
|
+
* - `'flush'`: joined into one connected group — shared borders, no gap,
|
|
8
|
+
* squared inner corners. Today's behaviour, and the default.
|
|
9
|
+
* - `'detached'`: separate buttons with their own borders and full radius,
|
|
10
|
+
* spaced by `--tui-pager-nav-gap`. Prev/next become ghost affordances
|
|
11
|
+
* sitting outside the group rather than outline segments completing it.
|
|
12
|
+
*
|
|
13
|
+
* `flush` is the shared system term (cf. Accordion). Its opposite is named for
|
|
14
|
+
* what the items actually are: an accordion item is a content surface, so
|
|
15
|
+
* `card` fits there; a page number is a button, so `detached` names the axis
|
|
16
|
+
* that actually varies instead.
|
|
17
|
+
*/
|
|
18
|
+
export type PagerVariant = 'flush' | 'detached';
|
|
4
19
|
export type PagerProps = {
|
|
5
20
|
/** Current page (1-indexed) */
|
|
6
21
|
currentPage: number;
|
|
@@ -26,6 +41,55 @@ export type PagerProps = {
|
|
|
26
41
|
maxNumbers?: number;
|
|
27
42
|
/** Style for prev/next: 'text' shows labels, 'icon' shows chevrons */
|
|
28
43
|
navStyle?: 'text' | 'icon';
|
|
44
|
+
/**
|
|
45
|
+
* Whether nav segments are joined into one group or spaced apart.
|
|
46
|
+
* @default 'flush'
|
|
47
|
+
*/
|
|
48
|
+
variant?: PagerVariant;
|
|
49
|
+
/**
|
|
50
|
+
* Show the "Page X of Y" region. The page size selector has its own
|
|
51
|
+
* condition (`pageSizeOptions` + `onPageSizeChange`), so this governs the
|
|
52
|
+
* region, not the select.
|
|
53
|
+
*
|
|
54
|
+
* Defaults to `true` in every mode — including `simple`, where the status
|
|
55
|
+
* line is arguably redundant. Auto-hiding there is what most consumers
|
|
56
|
+
* probably want, but it would silently change layout for existing `simple`
|
|
57
|
+
* users, so it stays opt-out.
|
|
58
|
+
* @default true
|
|
59
|
+
*/
|
|
60
|
+
showInfo?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Add dedicated first-page / last-page buttons outside prev/next.
|
|
63
|
+
*
|
|
64
|
+
* Most valuable in `simple` mode and at high page counts — in `smart`,
|
|
65
|
+
* `ends` and `full` the numbered group already carries a "1" and a last
|
|
66
|
+
* page, so these mainly save the user having to find them. Opt-in for that
|
|
67
|
+
* reason: four nav buttons is a lot of chrome to add by default.
|
|
68
|
+
*
|
|
69
|
+
* In `flush` they join the connected group at the ends, which means prev and
|
|
70
|
+
* next stop being the end segments — the border-collapse rules key off
|
|
71
|
+
* actual position rather than kind, so this needs no special casing.
|
|
72
|
+
* @default false
|
|
73
|
+
*/
|
|
74
|
+
showFirstLast?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Add a "Go to page" field.
|
|
77
|
+
*
|
|
78
|
+
* For hundreds of pages, where the numbered buttons and even first/last are
|
|
79
|
+
* still slow. Commits on Enter or via its own submit button — deliberately
|
|
80
|
+
* not on blur, which would move the page out from under a user who tabbed
|
|
81
|
+
* away mid-edit. Out-of-range entries clamp to the nearest valid page rather
|
|
82
|
+
* than erroring, and the existing `role="status"` region announces where the
|
|
83
|
+
* jump actually landed.
|
|
84
|
+
*
|
|
85
|
+
* It renders outside the `<nav>` landmark, which is the connected button
|
|
86
|
+
* group itself — so someone arriving by landmark finds prev/next and the
|
|
87
|
+
* numbers, not this field. It follows immediately in tab order. Moving it
|
|
88
|
+
* inside would mean wrapping the group rather than being it, and the field
|
|
89
|
+
* would then have to sit beside the buttons instead of at the trailing edge.
|
|
90
|
+
* @default false
|
|
91
|
+
*/
|
|
92
|
+
showJump?: boolean;
|
|
29
93
|
/** Hide the entire pager (useful when only 1 page) */
|
|
30
94
|
hidden?: boolean;
|
|
31
95
|
/** Additional class name */
|
|
@@ -36,4 +100,4 @@ export type PagerProps = {
|
|
|
36
100
|
*/
|
|
37
101
|
labels?: PagerLabels;
|
|
38
102
|
};
|
|
39
|
-
export declare function Pager({ currentPage, totalPages, onPageChange, pageSize, pageSizeOptions, onPageSizeChange, size, mode, maxNumbers, navStyle, hidden, className, labels: labelsProp, }: PagerProps): import("react/jsx-runtime").JSX.Element | null;
|
|
103
|
+
export declare function Pager({ currentPage, totalPages, onPageChange, pageSize, pageSizeOptions, onPageSizeChange, size, mode, maxNumbers, navStyle, variant, showInfo, showFirstLast, showJump, hidden, className, labels: labelsProp, }: PagerProps): import("react/jsx-runtime").JSX.Element | null;
|