@tangible/ui 0.2.10 → 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.
Files changed (75) hide show
  1. package/README.md +35 -22
  2. package/components/Accordion/Accordion.js +2 -2
  3. package/components/Combobox/Combobox.js +37 -5
  4. package/components/Combobox/types.d.ts +6 -0
  5. package/components/DatePicker/DatePicker.d.ts +3 -0
  6. package/components/DatePicker/DatePicker.js +8 -2
  7. package/components/DatePicker/DateRangePicker.d.ts +3 -0
  8. package/components/DatePicker/DateRangePicker.js +8 -2
  9. package/components/DatePicker/types.d.ts +36 -0
  10. package/components/Dropdown/Dropdown.js +2 -1
  11. package/components/MultiCombobox/MultiCombobox.js +1 -1
  12. package/components/MultiSelect/MultiSelect.d.ts +1 -1
  13. package/components/MultiSelect/MultiSelect.js +29 -5
  14. package/components/MultiSelect/types.d.ts +13 -0
  15. package/components/Pager/Pager.d.ts +65 -1
  16. package/components/Pager/Pager.js +83 -10
  17. package/components/Pager/index.d.ts +1 -1
  18. package/components/Pager/types.d.ts +39 -0
  19. package/components/Pager/types.js +6 -0
  20. package/components/Popover/Popover.js +2 -1
  21. package/components/SearchSelect/SearchSelect.d.ts +1 -1
  22. package/components/SearchSelect/SearchSelect.js +3 -5
  23. package/components/SearchSelect/types.d.ts +0 -2
  24. package/components/Select/Select.d.ts +1 -1
  25. package/components/Select/Select.js +29 -5
  26. package/components/Select/types.d.ts +13 -0
  27. package/components/Table/DataTable.d.ts +49 -3
  28. package/components/Table/DataTable.js +83 -4
  29. package/components/Textarea/Textarea.js +7 -0
  30. package/components/Tooltip/Tooltip.js +2 -1
  31. package/components/index.d.ts +2 -2
  32. package/components/index.js +1 -1
  33. package/figma-tokens.json +4018 -0
  34. package/icons/icons.svg +12 -2
  35. package/icons/lms/index.d.ts +12 -0
  36. package/icons/lms/index.js +83 -17
  37. package/icons/manifest.json +80 -0
  38. package/icons/membersync/index.js +9 -9
  39. package/icons/player/index.js +4 -4
  40. package/icons/reaction/index.js +4 -4
  41. package/icons/registry.d.ts +20 -0
  42. package/icons/registry.js +10 -0
  43. package/icons/system/index.d.ts +8 -0
  44. package/icons/system/index.js +65 -21
  45. package/package.json +5 -1
  46. package/skills/building-with-tui/SKILL.md +328 -0
  47. package/styles/all.css +1 -1
  48. package/styles/all.expanded.css +160 -269
  49. package/styles/all.expanded.unlayered.css +160 -269
  50. package/styles/all.unlayered.css +1 -1
  51. package/styles/components/color-picker.scss +16 -3
  52. package/styles/components/combobox.scss +33 -58
  53. package/styles/components/date-picker.scss +18 -10
  54. package/styles/components/dropdown.scss +12 -7
  55. package/styles/components/gradient-picker.scss +4 -4
  56. package/styles/components/multi-combobox.scss +17 -37
  57. package/styles/components/multi-select.scss +14 -50
  58. package/styles/components/pager.scss +155 -17
  59. package/styles/components/progress.scss +1 -1
  60. package/styles/components/radio.scss +37 -0
  61. package/styles/components/search-select.scss +16 -38
  62. package/styles/components/segmented-control.scss +1 -1
  63. package/styles/components/select.scss +22 -51
  64. package/styles/components/sidebar.scss +8 -3
  65. package/styles/components/slider.scss +1 -1
  66. package/styles/components/table.scss +3 -1
  67. package/styles/components/tabs.scss +1 -1
  68. package/styles/components/text-input.scss +79 -21
  69. package/styles/core.css +1 -1
  70. package/styles/core.unlayered.css +1 -1
  71. package/styles/system/_constants.scss +7 -1
  72. package/styles/system/_tokens.scss +2 -2
  73. package/tui-manifest.json +144 -6
  74. package/utils/compose-refs.d.ts +29 -3
  75. package/utils/compose-refs.js +51 -12
@@ -16,6 +16,18 @@ import { defaultPagerLabels } from './types.js';
16
16
  //
17
17
  // =============================================================================
18
18
  const DEFAULT_MAX_SLOTS = 7;
19
+ /**
20
+ * Glyphs for `navStyle="icon"`. First/last are double chevrons — the
21
+ * conventional "jump to the end" affordance, and distinguishable from the
22
+ * single-chevron prev/next at a glance, which `arrow-left`/`arrow-right`
23
+ * would not have been.
24
+ */
25
+ const NAV_ICONS = {
26
+ first: 'system/chevron-left-double',
27
+ prev: 'system/chevron-left',
28
+ next: 'system/chevron-right',
29
+ last: 'system/chevron-right-double',
30
+ };
19
31
  /**
20
32
  * Build a stable-width list of page tokens (numbers + ellipses).
21
33
  *
@@ -85,8 +97,13 @@ function buildNumberTokens(total, current, maxSlots = DEFAULT_MAX_SLOTS) {
85
97
  }
86
98
  return materialize();
87
99
  }
88
- function buildItems(total, current, mode, maxNumbers) {
100
+ function buildItems(total, current, mode, maxNumbers, showFirstLast) {
89
101
  const items = [];
102
+ // Outside prev/next, not inside: the reading order is
103
+ // « ‹ 1 2 3 › » in every pager that has them.
104
+ if (showFirstLast) {
105
+ items.push({ kind: 'first', disabled: current <= 1, page: 1 });
106
+ }
90
107
  items.push({
91
108
  kind: 'prev',
92
109
  disabled: current <= 1,
@@ -117,21 +134,29 @@ function buildItems(total, current, mode, maxNumbers) {
117
134
  disabled: current >= total,
118
135
  page: Math.min(total, current + 1),
119
136
  });
137
+ if (showFirstLast) {
138
+ items.push({ kind: 'last', disabled: current >= total, page: total });
139
+ }
120
140
  return items;
121
141
  }
122
142
  // -----------------------------------------------------------------------------
123
143
  // Component
124
144
  // -----------------------------------------------------------------------------
125
- export function Pager({ currentPage, totalPages, onPageChange, pageSize, pageSizeOptions, onPageSizeChange, size = 'sm', mode = 'smart', maxNumbers = DEFAULT_MAX_SLOTS, navStyle = 'text', hidden = false, className, labels: labelsProp, }) {
145
+ export function Pager({ currentPage, totalPages, onPageChange, pageSize, pageSizeOptions, onPageSizeChange, size = 'sm', mode = 'smart', maxNumbers = DEFAULT_MAX_SLOTS, navStyle = 'text', variant = 'flush', showInfo = true, showFirstLast = false, showJump = false, hidden = false, className, labels: labelsProp, }) {
126
146
  // Size class follows the shared convention: default emits nothing, sm/lg
127
147
  // emit `is-size-*`. (Pager's own default is sm, so a stock Pager still gets
128
148
  // the class.)
129
149
  const sizeClass = size !== 'md' ? `is-size-${size}` : undefined;
150
+ // Prev/next are outline segments in flush — they complete the connected group
151
+ // — but ghost affordances in detached, where they sit outside it. Applies to
152
+ // both nav styles: `icon` becomes a bare chevron, `text` becomes ghost text
153
+ // rather than a bordered box.
154
+ const navVariant = variant === 'detached' ? 'ghost' : 'outline';
130
155
  const labels = React.useMemo(() => ({ ...defaultPagerLabels, ...labelsProp }), [labelsProp]);
131
156
  // Normalise inputs
132
157
  const total = Math.max(1, totalPages);
133
158
  const current = Math.min(total, Math.max(1, currentPage));
134
- const items = React.useMemo(() => buildItems(total, current, mode, maxNumbers), [total, current, mode, maxNumbers]);
159
+ const items = React.useMemo(() => buildItems(total, current, mode, maxNumbers, showFirstLast), [total, current, mode, maxNumbers, showFirstLast]);
135
160
  // Live-region text: page changes are announced politely. Empty until the
136
161
  // first user-driven change so mount announces nothing.
137
162
  const [announcement, setAnnouncement] = React.useState('');
@@ -139,25 +164,73 @@ export function Pager({ currentPage, totalPages, onPageChange, pageSize, pageSiz
139
164
  setAnnouncement(labels.pageStatus(page, total));
140
165
  onPageChange(page);
141
166
  }, [onPageChange, labels, total]);
167
+ // Jump field. Its value is transient input, not a mirror of `currentPage` —
168
+ // it clears on commit so it can never sit there disagreeing with the page
169
+ // the user subsequently reached by other means. "Page X of Y" is what
170
+ // displays state.
171
+ const [jumpValue, setJumpValue] = React.useState('');
172
+ const jumpInputId = `${React.useId()}-jump`;
173
+ const commitJump = React.useCallback(() => {
174
+ const raw = jumpValue.trim();
175
+ // Empty field: no-op. Nothing to navigate to and nothing worth announcing.
176
+ if (!raw)
177
+ return;
178
+ // `Number`, not `parseInt`: a number input accepts exponent notation, and
179
+ // parseInt reads "1e5" as 1 — so a jump to page 100000 would silently
180
+ // become a jump to page 1 instead of clamping to the last page like every
181
+ // other out-of-range entry. Trunc handles "1.5" the same way parseInt did.
182
+ const parsed = Math.trunc(Number(raw));
183
+ if (!Number.isFinite(parsed))
184
+ return;
185
+ // Clamp rather than reject — typing 99 into a 10-page pager is a request
186
+ // for the last page. The status region announces where it actually landed,
187
+ // so the correction is audible instead of silent.
188
+ const page = Math.min(total, Math.max(1, parsed));
189
+ setJumpValue('');
190
+ go(page);
191
+ }, [jumpValue, total, go]);
142
192
  if (hidden)
143
193
  return null;
144
194
  const showPageSizeSelector = pageSizeOptions && pageSizeOptions.length > 0 && onPageSizeChange;
145
- return (_jsxs("div", { className: cx('tui-pager', className), children: [_jsx("span", { role: "status", "aria-atomic": "true", className: "tui-visually-hidden", children: announcement }), _jsx("nav", { className: "tui-pager__nav", "aria-label": labels.navigation, children: items.map((it, i) => {
195
+ return (_jsxs("div", { className: cx('tui-pager', `is-variant-${variant}`, className), children: [_jsx("span", { role: "status", "aria-atomic": "true", className: "tui-visually-hidden", children: announcement }), _jsx("nav", { className: "tui-pager__nav", "aria-label": labels.navigation, children: items.map((it, i) => {
146
196
  if (it.kind === 'ellipsis') {
147
197
  return (_jsx("span", { className: cx('tui-pager__ellipsis', sizeClass), "aria-hidden": true, children: "..." }, `e${i}`));
148
198
  }
149
- if (it.kind === 'prev' || it.kind === 'next') {
150
- const isPrev = it.kind === 'prev';
151
- const label = isPrev ? labels.previous : labels.next;
199
+ if (it.kind !== 'page') {
200
+ // All four nav kinds render identically apart from their glyph and
201
+ // their pair of strings — the accessible name and, for `text`, the
202
+ // shorter visible label WCAG 2.5.3 requires it to contain.
203
+ const label = {
204
+ first: labels.first,
205
+ prev: labels.previous,
206
+ next: labels.next,
207
+ last: labels.last,
208
+ }[it.kind];
209
+ const text = {
210
+ first: labels.firstText,
211
+ prev: labels.previousText,
212
+ next: labels.nextText,
213
+ last: labels.lastText,
214
+ }[it.kind];
152
215
  if (navStyle === 'icon') {
153
- return (_jsx(IconButton, { icon: isPrev ? 'system/chevron-left' : 'system/chevron-right', label: label, showTooltip: true, size: size, theme: "secondary", variant: "outline", disabled: it.disabled, onClick: () => go(it.page), className: "tui-pager__item" }, it.kind));
216
+ 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));
154
217
  }
155
- return (_jsx(Button, { size: size, theme: "secondary", variant: "outline", disabled: it.disabled, onClick: () => go(it.page), "aria-label": label, className: "tui-pager__item", children: isPrev ? labels.previousText : labels.nextText }, it.kind));
218
+ 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));
156
219
  }
157
220
  // Page number
158
221
  if (it.kind === 'page') {
159
222
  return (_jsx(Button, { size: size, theme: it.current ? 'primary' : 'secondary', variant: it.current ? 'solid' : 'outline', "aria-current": it.current ? 'page' : undefined, "aria-label": labels.page(it.page), onClick: () => go(it.page), className: "tui-pager__item", children: it.page }, it.page));
160
223
  }
161
224
  return null;
162
- }) }), _jsxs("div", { className: "tui-pager__info", children: [_jsx("span", { children: labels.pageStatus(current, total) }), showPageSizeSelector && (_jsxs("label", { className: "tui-pager__page-size-label", children: [_jsx("span", { className: "tui-visually-hidden", children: labels.itemsPerPage }), _jsx("select", { className: cx('tui-input', sizeClass), value: pageSize, onChange: (e) => onPageSizeChange(Number(e.target.value)), children: pageSizeOptions.map((s) => (_jsx("option", { value: s, children: labels.perPage(s) }, s))) })] }))] })] }));
225
+ }) }), showInfo && (_jsxs("div", { className: "tui-pager__info", children: [_jsx("span", { children: labels.pageStatus(current, total) }), showPageSizeSelector && (_jsxs("label", { className: "tui-pager__page-size-label", children: [_jsx("span", { className: "tui-visually-hidden", children: labels.itemsPerPage }), _jsx("select", { className: cx('tui-input', sizeClass), value: pageSize, onChange: (e) => onPageSizeChange(Number(e.target.value)), children: pageSizeOptions.map((s) => (_jsx("option", { value: s, children: labels.perPage(s) }, s))) })] }))] })), showJump && (_jsxs("div", { className: "tui-pager__jump", children: [_jsx("label", { className: "tui-pager__jump-label", htmlFor: jumpInputId, children: labels.jumpLabel }), _jsx("input", { id: jumpInputId, type: "number", inputMode: "numeric", min: 1, max: total, value: jumpValue, onChange: (e) => setJumpValue(e.target.value), onKeyDown: (e) => {
226
+ if (e.key !== 'Enter')
227
+ return;
228
+ // preventDefault matters despite there being no <form> here: a
229
+ // Pager rendered inside a consumer's form would otherwise submit
230
+ // it on Enter. The commit path is hand-wired precisely because a
231
+ // nested <form> is invalid HTML and the Pager cannot know whether
232
+ // it has been dropped into one.
233
+ e.preventDefault();
234
+ commitJump();
235
+ }, className: cx('tui-input', 'tui-pager__jump-input', sizeClass) }), _jsx(Button, { size: size, theme: "secondary", variant: "outline", onClick: commitJump, className: "tui-pager__jump-submit", children: labels.jumpText })] }))] }));
163
236
  }
@@ -1,4 +1,4 @@
1
1
  export { Pager } from './Pager';
2
- export type { PagerProps, PagerMode } from './Pager';
2
+ export type { PagerProps, PagerMode, PagerVariant } from './Pager';
3
3
  export { defaultPagerLabels } from './types';
4
4
  export type { PagerLabels } from './types';
@@ -13,6 +13,14 @@ export type PagerLabels = {
13
13
  * @default "Next page"
14
14
  */
15
15
  next?: string;
16
+ /** Accessible name for the first-page button (`showFirstLast`).
17
+ * @default "First page"
18
+ */
19
+ first?: string;
20
+ /** Accessible name for the last-page button (`showFirstLast`).
21
+ * @default "Last page"
22
+ */
23
+ last?: string;
16
24
  /** VISIBLE text on the previous button (text nav style). Must be contained
17
25
  * in `previous` (the accessible name) to satisfy WCAG 2.5.3 Label in Name.
18
26
  * @default "Prev"
@@ -22,11 +30,27 @@ export type PagerLabels = {
22
30
  * @default "Next"
23
31
  */
24
32
  nextText?: string;
33
+ /** VISIBLE text on the first-page button (text nav style). Same WCAG 2.5.3
34
+ * containment rule: must appear inside `first`.
35
+ * @default "First"
36
+ */
37
+ firstText?: string;
38
+ /** Visible text on the last-page button — must appear inside `last`.
39
+ * @default "Last"
40
+ */
41
+ lastText?: string;
25
42
  /** Label for individual page buttons.
26
43
  * @default (n) => `Page ${n}`
27
44
  */
28
45
  page?: (n: number) => string;
29
46
  /** aria-label for the nav landmark.
47
+ *
48
+ * IMPORTANT: override this when a page renders more than one Pager — the
49
+ * classic case being one above and one below a long table. Every Pager is a
50
+ * `<nav>` landmark, and two sharing the default name are indistinguishable to
51
+ * a screen reader navigating by landmark (axe: `landmark-unique`). TUI cannot
52
+ * pick the distinguishing name for you; only the consumer knows whether it is
53
+ * "top"/"bottom", "results"/"filters", or something else.
30
54
  * @default "Pagination"
31
55
  */
32
56
  navigation?: string;
@@ -42,5 +66,20 @@ export type PagerLabels = {
42
66
  * @default (n) => `${n} / page`
43
67
  */
44
68
  perPage?: (n: number) => string;
69
+ /** Visible label on the go-to-page field (`showJump`).
70
+ * @default "Go to page"
71
+ */
72
+ jumpLabel?: string;
73
+ /** Text on the go-to-page submit button.
74
+ *
75
+ * This is the button's whole accessible name — it carries no `aria-label`, on
76
+ * purpose. Giving it a fuller name ("Go to page") would duplicate the field's
77
+ * label verbatim, and two controls a Tab apart answering to the same name are
78
+ * ambiguous for both screen-reader and voice-control users. Short and
79
+ * distinct beats descriptive and colliding; the adjacent label supplies the
80
+ * context.
81
+ * @default "Go"
82
+ */
83
+ jumpText?: string;
45
84
  };
46
85
  export declare const defaultPagerLabels: Required<PagerLabels>;
@@ -4,11 +4,17 @@
4
4
  export const defaultPagerLabels = {
5
5
  previous: 'Previous page',
6
6
  next: 'Next page',
7
+ first: 'First page',
8
+ last: 'Last page',
7
9
  previousText: 'Prev',
8
10
  nextText: 'Next',
11
+ firstText: 'First',
12
+ lastText: 'Last',
9
13
  page: (n) => `Page ${n}`,
10
14
  navigation: 'Pagination',
11
15
  pageStatus: (current, total) => `Page ${current} of ${total}`,
12
16
  itemsPerPage: 'Items per page',
13
17
  perPage: (n) => `${n} / page`,
18
+ jumpLabel: 'Go to page',
19
+ jumpText: 'Go',
14
20
  };
@@ -3,6 +3,7 @@ import React, { useCallback, useEffect, useId, useMemo, useRef, useState, cloneE
3
3
  import { useFloating, offset, flip, shift, size, autoUpdate, FloatingPortal, useDismiss, useInteractions, 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 { PopoverContext, usePopoverContext } from './PopoverContext.js';
7
8
  import { toPlacement } from './types.js';
8
9
  // =============================================================================
@@ -69,7 +70,7 @@ function PopoverTriggerComponent({ asChild = false, children }) {
69
70
  const setRefs = useCallback((node) => {
70
71
  triggerRef.current = node;
71
72
  if (asChild && isValidElement(children)) {
72
- const childRef = children.ref;
73
+ const childRef = getElementRef(children);
73
74
  if (typeof childRef === 'function') {
74
75
  childRef(node);
75
76
  }
@@ -1,5 +1,5 @@
1
1
  import { type SearchSelectProps, type SearchSelectTriggerProps, type SearchSelectContentProps, type SearchSelectOptionProps } from './types';
2
- declare function SearchSelectRoot({ value: controlledValue, defaultValue, onValueChange, open: controlledOpen, defaultOpen, onOpenChange, inputValue: controlledInputValue, onInputChange, filter, disabled, placeholder, size, anchorRef, restoreFocusRef, id: triggerIdProp, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'aria-required': ariaRequired, labels: labelsProp, children, }: SearchSelectProps): import("react/jsx-runtime").JSX.Element;
2
+ declare function SearchSelectRoot({ value: controlledValue, defaultValue, onValueChange, open: controlledOpen, defaultOpen, onOpenChange, inputValue: controlledInputValue, onInputChange, filter, disabled, placeholder, size, anchorRef, restoreFocusRef, id: triggerIdProp, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, labels: labelsProp, children, }: SearchSelectProps): import("react/jsx-runtime").JSX.Element;
3
3
  declare namespace SearchSelectRoot {
4
4
  var displayName: string;
5
5
  }
@@ -14,7 +14,7 @@ const defaultFilter = (textValue, query) => textValue.toLowerCase().includes(que
14
14
  // =============================================================================
15
15
  // SearchSelect Root
16
16
  // =============================================================================
17
- function SearchSelectRoot({ value: controlledValue, defaultValue, onValueChange, open: controlledOpen, defaultOpen, onOpenChange, inputValue: controlledInputValue, onInputChange, filter = defaultFilter, disabled = false, placeholder = '', size = 'md', anchorRef, restoreFocusRef, id: triggerIdProp, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'aria-required': ariaRequired, labels: labelsProp, children, }) {
17
+ function SearchSelectRoot({ value: controlledValue, defaultValue, onValueChange, open: controlledOpen, defaultOpen, onOpenChange, inputValue: controlledInputValue, onInputChange, filter = defaultFilter, disabled = false, placeholder = '', size = 'md', anchorRef, restoreFocusRef, id: triggerIdProp, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, labels: labelsProp, children, }) {
18
18
  const labels = { ...defaultSearchSelectLabels, ...labelsProp };
19
19
  // Controlled/uncontrolled value — lock decision at mount time (see the
20
20
  // controlled→uncontrolled gotcha in CLAUDE.md)
@@ -210,7 +210,6 @@ function SearchSelectRoot({ value: controlledValue, defaultValue, onValueChange,
210
210
  ariaLabelledBy,
211
211
  ariaDescribedBy,
212
212
  ariaInvalid,
213
- ariaRequired,
214
213
  setOpen,
215
214
  selectValue,
216
215
  setInputValue,
@@ -254,7 +253,6 @@ function SearchSelectRoot({ value: controlledValue, defaultValue, onValueChange,
254
253
  ariaLabelledBy,
255
254
  ariaDescribedBy,
256
255
  ariaInvalid,
257
- ariaRequired,
258
256
  setOpen,
259
257
  selectValue,
260
258
  setInputValue,
@@ -287,7 +285,7 @@ SearchSelectRoot.displayName = 'SearchSelect';
287
285
  // SearchSelect.Trigger
288
286
  // =============================================================================
289
287
  function SearchSelectTriggerComponent({ className, children, onClick: onClickProp, onKeyDown: onKeyDownProp, onPointerDown: onPointerDownProp, ...rest }) {
290
- const { disabled, placeholder, size, triggerId, panelId, ariaLabel, ariaLabelledBy, ariaDescribedBy, ariaInvalid, ariaRequired, setOpen, labelFor, refs, triggerElRef, open, value, } = useSearchSelectContext();
288
+ const { disabled, placeholder, size, triggerId, panelId, ariaLabel, ariaLabelledBy, ariaDescribedBy, ariaInvalid, setOpen, labelFor, refs, triggerElRef, open, value, } = useSearchSelectContext();
291
289
  const hasValue = value !== undefined;
292
290
  const valueId = `${triggerId}-value`;
293
291
  // The trigger is the POSITION reference (the panel anchors to it); the
@@ -325,7 +323,7 @@ function SearchSelectTriggerComponent({ className, children, onClick: onClickPro
325
323
  return;
326
324
  pointerDownFix(e);
327
325
  }, [onPointerDownProp, pointerDownFix]);
328
- return (_jsxs("button", { ...rest, ref: handleRef, type: "button", id: triggerId, className: cx('tui-search-select__trigger', size !== 'md' && `is-size-${size}`, className), disabled: disabled, "aria-haspopup": "dialog", "aria-expanded": open, "aria-controls": open ? panelId : undefined, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy ? `${ariaLabelledBy} ${valueId}` : undefined, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-required": ariaRequired, "data-state": open ? 'open' : 'closed', onClick: handleClick, onKeyDown: handleKeyDown, onPointerDown: handlePointerDown, children: [_jsx("span", { id: valueId, className: "tui-search-select__value", children: children ??
326
+ return (_jsxs("button", { ...rest, ref: handleRef, type: "button", id: triggerId, className: cx('tui-input-group', 'tui-search-select__trigger', size !== 'md' && `is-size-${size}`, className), disabled: disabled, "aria-haspopup": "dialog", "aria-expanded": open, "aria-controls": open ? panelId : undefined, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy ? `${ariaLabelledBy} ${valueId}` : undefined, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "data-state": open ? 'open' : 'closed', onClick: handleClick, onKeyDown: handleKeyDown, onPointerDown: handlePointerDown, children: [_jsx("span", { id: valueId, className: "tui-search-select__value", children: children ??
329
327
  (hasValue ? (labelFor(value)) : (_jsx("span", { className: "tui-search-select__placeholder", children: placeholder }))) }), _jsx(Icon, { name: "system/chevron-down", className: "tui-search-select__icon" })] }));
330
328
  }
331
329
  SearchSelectTriggerComponent.displayName = 'SearchSelect.Trigger';
@@ -64,7 +64,6 @@ export type SearchSelectProps = {
64
64
  'aria-labelledby'?: string;
65
65
  'aria-describedby'?: string;
66
66
  'aria-invalid'?: boolean | 'true' | 'false';
67
- 'aria-required'?: boolean | 'true' | 'false';
68
67
  labels?: SearchSelectLabels;
69
68
  children: ReactNode;
70
69
  };
@@ -107,7 +106,6 @@ export type SearchSelectContextValue = {
107
106
  ariaLabelledBy?: string;
108
107
  ariaDescribedBy?: string;
109
108
  ariaInvalid?: boolean | 'true' | 'false';
110
- ariaRequired?: boolean | 'true' | 'false';
111
109
  setOpen: (open: boolean) => void;
112
110
  selectValue: (value: OptionValue, textValue: string) => void;
113
111
  setInputValue: (value: string) => void;
@@ -1,5 +1,5 @@
1
1
  import { type SelectProps, type SelectTriggerProps, type SelectContentProps, type SelectOptionProps } from './types';
2
- declare function SelectRoot({ id: triggerIdProp, value: controlledValue, defaultValue, onValueChange, open: controlledOpen, defaultOpen, onOpenChange, disabled, placeholder, size, side, align, sideOffset, clearable, clearLabel, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, children, }: SelectProps): import("react/jsx-runtime").JSX.Element;
2
+ declare function SelectRoot({ id: triggerIdProp, value: controlledValue, defaultValue, onValueChange, open: controlledOpen, defaultOpen, onOpenChange, disabled, placeholder, size, side, align, sideOffset, clearable, clearLabel, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'aria-required': ariaRequired, children, }: SelectProps): import("react/jsx-runtime").JSX.Element;
3
3
  declare namespace SelectRoot {
4
4
  var displayName: string;
5
5
  }
@@ -4,6 +4,7 @@ import { FloatingPortal } from '@floating-ui/react';
4
4
  import { cx } from '../../utils/cx.js';
5
5
  import { toKey } from '../../utils/value-key.js';
6
6
  import { getPortalRootFor } from '../../utils/portal.js';
7
+ import { composeRefs, getElementRef } from '../../utils/compose-refs.js';
7
8
  import { useOptionRegistry, useOptionRegistration, useListboxIds, useListboxFloating, useListboxNavigation, useListboxBlurGuard, useTriggerPointerDownFix, useFocusTriggerOnOpen, useActiveOptionScroll, optionIdForIndex, createListboxGroupComponents, } from '../../utils/listbox/index.js';
8
9
  import { Icon } from '../Icon/index.js';
9
10
  import { SelectContext, SelectContentContext, useSelectContext, useSelectContentContext, } from './SelectContext.js';
@@ -11,7 +12,7 @@ import { toPlacement, } from './types.js';
11
12
  // =============================================================================
12
13
  // Select Root
13
14
  // =============================================================================
14
- function SelectRoot({ id: triggerIdProp, value: controlledValue, defaultValue, onValueChange, open: controlledOpen, defaultOpen, onOpenChange, disabled = false, placeholder = '', size = 'md', side = 'bottom', align = 'start', sideOffset = 4, clearable = false, clearLabel = 'Clear selection', 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, children, }) {
15
+ function SelectRoot({ id: triggerIdProp, value: controlledValue, defaultValue, onValueChange, open: controlledOpen, defaultOpen, onOpenChange, disabled = false, placeholder = '', size = 'md', side = 'bottom', align = 'start', sideOffset = 4, clearable = false, clearLabel = 'Clear selection', 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'aria-required': ariaRequired, children, }) {
15
16
  // Controlled/uncontrolled value — lock decision at mount time to prevent
16
17
  // switching modes when controlled value is cleared to undefined
17
18
  const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
@@ -160,6 +161,8 @@ function SelectRoot({ id: triggerIdProp, value: controlledValue, defaultValue, o
160
161
  ariaLabel,
161
162
  ariaLabelledBy,
162
163
  ariaDescribedBy,
164
+ ariaInvalid,
165
+ ariaRequired,
163
166
  // Callbacks
164
167
  setOpen,
165
168
  setValue,
@@ -194,6 +197,8 @@ function SelectRoot({ id: triggerIdProp, value: controlledValue, defaultValue, o
194
197
  ariaLabel,
195
198
  ariaLabelledBy,
196
199
  ariaDescribedBy,
200
+ ariaInvalid,
201
+ ariaRequired,
197
202
  setOpen,
198
203
  setValue,
199
204
  registerOption,
@@ -220,7 +225,7 @@ SelectRoot.displayName = 'Select';
220
225
  // Select.Trigger
221
226
  // =============================================================================
222
227
  function SelectTriggerComponent({ asChild = false, className, children, }) {
223
- const { open, setOpen, disabled, placeholder, clearable, clearLabel, size, triggerId, listboxId, ariaLabel, ariaLabelledBy, ariaDescribedBy, displayText, setValue, refs, getReferenceProps, activeIndex, handleSelect, justClearedRef, } = useSelectContext();
228
+ const { open, setOpen, disabled, placeholder, clearable, clearLabel, size, triggerId, listboxId, ariaLabel, ariaLabelledBy, ariaDescribedBy, ariaInvalid, ariaRequired, displayText, setValue, refs, getReferenceProps, activeIndex, handleSelect, justClearedRef, } = useSelectContext();
224
229
  const sizeClass = size !== 'md' ? `is-size-${size}` : undefined;
225
230
  const hasValue = displayText !== undefined;
226
231
  // Ensure trigger has focus when dropdown opens (Safari doesn't focus buttons on click)
@@ -265,11 +270,28 @@ function SelectTriggerComponent({ asChild = false, className, children, }) {
265
270
  onBlur: handleBlur,
266
271
  onPointerDown: handleTriggerPointerDown,
267
272
  });
273
+ // asChild: compose the child's own ref with Floating UI's reference setter.
274
+ // Without this the child's ref is silently discarded — a consumer passing
275
+ // <Select.Trigger asChild><MyButton ref={myRef}/></Select.Trigger> never gets
276
+ // a node, with no error to explain why.
277
+ //
278
+ // Computed unconditionally and memoised, not inside the asChild branch below:
279
+ // hooks cannot be conditional, and an inline composeRefs would hand React a
280
+ // new callback on every render, detaching and re-attaching the reference each
281
+ // time. Floating UI's own setReference is stable, so that churn would be a
282
+ // real regression for a popup that re-renders per keystroke.
283
+ const childRef = asChild && isValidElement(children) ? getElementRef(children) : undefined;
284
+ const composedReferenceRef = React.useMemo(() => composeRefs(refs.setReference, childRef), [refs.setReference, childRef]);
268
285
  const triggerProps = {
269
286
  id: triggerId,
270
287
  'aria-label': ariaLabel,
271
288
  'aria-labelledby': ariaLabelledBy,
272
289
  'aria-describedby': ariaDescribedBy,
290
+ // Both land on the trigger, which also carries `tui-input-group` — the
291
+ // shared primitive keys its danger border off [aria-invalid="true"] on
292
+ // that same element. Putting them on an inner node fails silently.
293
+ 'aria-invalid': ariaInvalid,
294
+ 'aria-required': ariaRequired,
273
295
  'aria-keyshortcuts': clearable && hasValue ? 'Delete' : undefined,
274
296
  'data-state': open ? 'open' : 'closed',
275
297
  ...floatingProps,
@@ -301,17 +323,19 @@ function SelectTriggerComponent({ asChild = false, className, children, }) {
301
323
  ...childProps,
302
324
  // Re-assert must-have props that child cannot override
303
325
  id: triggerId,
304
- ref: refs.setReference,
326
+ ref: composedReferenceRef,
305
327
  'aria-haspopup': floatingProps['aria-haspopup'],
306
328
  'aria-expanded': floatingProps['aria-expanded'],
307
329
  'aria-controls': open ? floatingProps['aria-controls'] : undefined,
308
330
  'aria-activedescendant': floatingProps['aria-activedescendant'],
309
331
  'aria-describedby': ariaDescribedBy,
332
+ 'aria-invalid': ariaInvalid,
333
+ 'aria-required': ariaRequired,
310
334
  // asChild: use aria-disabled + data-disabled since element may not support native disabled
311
335
  'aria-disabled': disabled || undefined,
312
336
  'data-state': open ? 'open' : 'closed',
313
337
  'data-disabled': disabled || undefined,
314
- className: cx(childProps.className, 'tui-select__trigger', sizeClass, className),
338
+ className: cx(childProps.className, 'tui-input-group', 'tui-select__trigger', sizeClass, className),
315
339
  // Composed handlers override both spreads
316
340
  onClick: composeHandler(triggerProps.onClick, childProps.onClick),
317
341
  onKeyDown: composeHandler(triggerProps.onKeyDown, childProps.onKeyDown),
@@ -324,7 +348,7 @@ function SelectTriggerComponent({ asChild = false, className, children, }) {
324
348
  // Wrap in a relative container so the clear button can be a sibling of the
325
349
  // trigger <button> — nesting <button> inside <button> is invalid HTML and
326
350
  // causes browsers to eject the inner button via the adoption agency algorithm.
327
- return (_jsxs("div", { className: cx('tui-select__trigger-wrap', showClear && 'has-clear'), children: [_jsxs("button", { ref: refs.setReference, type: "button", className: cx('tui-select__trigger', sizeClass, className), disabled: disabled, ...triggerProps, children: [_jsx("span", { className: "tui-select__value", children: displayText ?? _jsx("span", { className: "tui-select__placeholder", children: placeholder }) }), _jsx(Icon, { name: "system/chevron-down", className: "tui-select__icon", "aria-hidden": "true" })] }), showClear && (_jsx("button", { type: "button", className: "tui-select__clear", onClick: handleClear, "aria-label": clearLabel, tabIndex: -1, children: _jsx(Icon, { name: "system/close" }) }))] }));
351
+ return (_jsxs("div", { className: cx('tui-select__trigger-wrap', showClear && 'has-clear'), children: [_jsxs("button", { ref: refs.setReference, type: "button", className: cx('tui-input-group', 'tui-select__trigger', sizeClass, className), disabled: disabled, ...triggerProps, children: [_jsx("span", { className: "tui-select__value", children: displayText ?? _jsx("span", { className: "tui-select__placeholder", children: placeholder }) }), _jsx(Icon, { name: "system/chevron-down", className: "tui-select__icon", "aria-hidden": "true" })] }), showClear && (_jsx("button", { type: "button", className: "tui-select__clear", onClick: handleClear, "aria-label": clearLabel, tabIndex: -1, children: _jsx(Icon, { name: "system/close" }) }))] }));
328
352
  }
329
353
  SelectTriggerComponent.displayName = 'Select.Trigger';
330
354
  // =============================================================================
@@ -87,6 +87,17 @@ export type SelectProps = {
87
87
  * ID of element(s) that describe this select.
88
88
  */
89
89
  'aria-describedby'?: string;
90
+ /**
91
+ * Marks the control invalid. Lands on the trigger, which also wears
92
+ * `tui-input-group` — that is what lights the danger border.
93
+ * Injected automatically by `Field.Control` when the Field has an error.
94
+ */
95
+ 'aria-invalid'?: boolean | 'true' | 'false';
96
+ /**
97
+ * Marks the control required. Injected automatically by `Field.Control`
98
+ * when the Field is required.
99
+ */
100
+ 'aria-required'?: boolean | 'true' | 'false';
90
101
  /**
91
102
  * Optional trigger ID override.
92
103
  * Useful for Field integration via htmlFor.
@@ -177,6 +188,8 @@ export type SelectContextValue = {
177
188
  ariaLabel?: string;
178
189
  ariaLabelledBy?: string;
179
190
  ariaDescribedBy?: string;
191
+ ariaInvalid?: boolean | 'true' | 'false';
192
+ ariaRequired?: boolean | 'true' | 'false';
180
193
  setOpen: (open: boolean) => void;
181
194
  setValue: (value: OptionValue | undefined, textValue?: string) => void;
182
195
  registerOption: (option: RegisteredOption) => void;
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import type { ColumnDef, SortingState, Table as TanTable, RowSelectionState, Updater } from '@tanstack/react-table';
2
+ import type { ColumnDef, SortingState, Table as TanTable, Row as TanRow, RowSelectionState, Updater } from '@tanstack/react-table';
3
3
  import type { DataTableLabels } from './types';
4
4
  type RowId = string | number;
5
5
  type BulkSelectionRenderArgs<T> = {
@@ -9,23 +9,69 @@ type BulkSelectionRenderArgs<T> = {
9
9
  selectedCount?: number;
10
10
  };
11
11
  export type DataTableProps<T> = {
12
+ /** Row data. Memoize it, or pass `autoResetPageIndex={false}` — see below. */
12
13
  data: T[];
14
+ /** TanStack column definitions. The selection column is injected, not declared. */
13
15
  columns: ColumnDef<T, unknown>[];
14
16
  className?: string;
15
17
  'aria-label'?: string;
16
18
  'aria-labelledby'?: string;
19
+ /** Initial sort state. Sorting stays internal — this only seeds it. */
17
20
  defaultSorting?: SortingState;
21
+ /** Replaces the body with a loading row while true. */
18
22
  loading?: boolean;
23
+ /** Shown in place of rows while `loading`. */
19
24
  loadingMessage?: React.ReactNode;
25
+ /** Shown in place of rows when `data` is empty. */
20
26
  emptyMessage?: React.ReactNode;
21
27
  /** Override hardcoded English strings for i18n. Unset keys use English defaults. */
22
28
  labels?: DataTableLabels;
29
+ /**
30
+ * Extra props for each body `<tr>` — the escape hatch for row-level
31
+ * interaction: keyboard cursors, row click shortcuts, `data-*` hooks,
32
+ * context menus. Consumer `className` is merged after the built-in row
33
+ * classes; `data-selected` and the `is-selected` class always reflect
34
+ * actual selection state and cannot be overridden. `role`/`aria-*` are NOT
35
+ * guarded — overriding `role` on a `<tr>` removes it from the table's
36
+ * accessibility tree, so only do that as part of a deliberate pattern
37
+ * (e.g. rows in a `role="grid"` table keep `role="row"`). Loading/empty
38
+ * placeholder rows are not affected.
39
+ */
40
+ getRowProps?: (row: TanRow<T>) => Omit<React.ComponentProps<'tr'>, 'key' | 'children' | 'dangerouslySetInnerHTML'>;
23
41
  renderPagination?: (table: TanTable<T>) => React.ReactNode;
24
42
  paginationMode?: 'simple' | 'ends' | 'full' | 'smart';
25
43
  paginationMaxNumbers?: number;
26
44
  paginationNavStyle?: 'text' | 'icon';
27
45
  pageSizeOptions?: number[];
28
46
  initialPageSize?: number;
47
+ /**
48
+ * Controlled page index (0-based, matching TanStack). When set, the parent
49
+ * owns paging: the built-in pager requests changes via `onPageIndexChange`,
50
+ * but the page only moves when this prop updates. Page size stays internal
51
+ * either way. Controlled/uncontrolled is locked at mount.
52
+ */
53
+ pageIndex?: number;
54
+ /**
55
+ * Fires with the requested 0-based page index whenever anything asks for a
56
+ * page change — pager clicks, page-size changes (TanStack re-anchors to
57
+ * keep the top row visible), the auto page-0 reset (see
58
+ * `autoResetPageIndex`), or an out-of-range controlled `pageIndex` being
59
+ * clamped into range. Fires in both controlled and uncontrolled modes.
60
+ * Note: 0-based, unlike Pager's 1-based `onPageChange` (the built-in
61
+ * pager converts).
62
+ */
63
+ onPageIndexChange?: (pageIndex: number) => void;
64
+ /**
65
+ * TanStack's automatic page-0 reset when sorting or data identity change.
66
+ * Defaults to `true` when `pageIndex` is uncontrolled, `false` when
67
+ * controlled — a controlled parent owns the index, and the auto-reset
68
+ * would race it back to 0 on every re-render that recreates `data`
69
+ * (parent re-renders on page change → new array identity → reset).
70
+ * Uncontrolled consumers who `setState` inside `onPageIndexChange` while
71
+ * passing a derived (unmemoized) `data` array hit the same loop: pass
72
+ * `false` here or memoize `data`.
73
+ */
74
+ autoResetPageIndex?: boolean;
29
75
  enableRowSelection?: boolean;
30
76
  getRowId?: (row: T, index: number) => string | number;
31
77
  getRowLabelForSelection?: (row: T, index: number) => string;
@@ -33,6 +79,6 @@ export type DataTableProps<T> = {
33
79
  onRowSelectionChange?: (updater: Updater<RowSelectionState>) => void;
34
80
  onSelectionChange?: (selectedRows: T[], selectedIds: (string | number)[]) => void;
35
81
  renderBulkBar?: (args: BulkSelectionRenderArgs<T>) => React.ReactNode;
36
- };
37
- export declare function DataTable<T>({ data, columns, className, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, defaultSorting, loading, loadingMessage, emptyMessage, labels: labelsProp, renderPagination, paginationMode, paginationMaxNumbers, paginationNavStyle, pageSizeOptions, initialPageSize, enableRowSelection, getRowId, getRowLabelForSelection, onSelectionChange, renderBulkBar, rowSelection, onRowSelectionChange, }: DataTableProps<T>): import("react/jsx-runtime").JSX.Element;
82
+ } & Omit<React.TableHTMLAttributes<HTMLTableElement>, 'className' | 'id' | 'children'>;
83
+ export declare function DataTable<T>({ data, columns, className, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, defaultSorting, loading, loadingMessage, emptyMessage, labels: labelsProp, getRowProps, renderPagination, paginationMode, paginationMaxNumbers, paginationNavStyle, pageSizeOptions, initialPageSize, pageIndex: pageIndexProp, onPageIndexChange, autoResetPageIndex, enableRowSelection, getRowId, getRowLabelForSelection, onSelectionChange, renderBulkBar, rowSelection, onRowSelectionChange, ...rest }: DataTableProps<T>): import("react/jsx-runtime").JSX.Element;
38
84
  export {};