@matekit/react 0.0.0-stage → 0.1.0

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 (268) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +56 -0
  4. package/README.md +115 -2
  5. package/dist/atoms/Divider/Divider.d.ts +49 -0
  6. package/dist/atoms/Divider/Divider.js +29 -0
  7. package/dist/atoms/FocusRing/FocusRing.d.ts +16 -0
  8. package/dist/atoms/FocusRing/FocusRing.js +16 -0
  9. package/dist/atoms/Group/Group.d.ts +38 -0
  10. package/dist/atoms/Group/Group.js +34 -0
  11. package/dist/atoms/Icon/Icon.d.ts +23 -0
  12. package/dist/atoms/Icon/Icon.js +19 -0
  13. package/dist/atoms/Interactive/Interactive.d.ts +98 -0
  14. package/dist/atoms/Interactive/Interactive.js +87 -0
  15. package/dist/atoms/Ripple/Ripple.d.ts +14 -0
  16. package/dist/atoms/Ripple/Ripple.js +63 -0
  17. package/dist/atoms/Shape/Shape.d.ts +24 -0
  18. package/dist/atoms/Shape/Shape.js +19 -0
  19. package/dist/atoms/Shape/shapes.d.ts +8 -0
  20. package/dist/atoms/Shape/shapes.js +40 -0
  21. package/dist/atoms/Stack/Stack.d.ts +58 -0
  22. package/dist/atoms/Stack/Stack.js +33 -0
  23. package/dist/atoms/StateLayer/StateLayer.d.ts +17 -0
  24. package/dist/atoms/StateLayer/StateLayer.js +17 -0
  25. package/dist/atoms/index.d.ts +10 -0
  26. package/dist/atoms/index.js +10 -0
  27. package/dist/fonts/roboto-flex/OFL.txt +93 -0
  28. package/dist/fonts/roboto-flex/roboto-flex-cyrillic-ext.woff2 +0 -0
  29. package/dist/fonts/roboto-flex/roboto-flex-cyrillic.woff2 +0 -0
  30. package/dist/fonts/roboto-flex/roboto-flex-greek.woff2 +0 -0
  31. package/dist/fonts/roboto-flex/roboto-flex-latin-ext.woff2 +0 -0
  32. package/dist/fonts/roboto-flex/roboto-flex-latin.woff2 +0 -0
  33. package/dist/fonts/roboto-flex/roboto-flex-vietnamese.woff2 +0 -0
  34. package/dist/icons/icons.d.ts +89 -0
  35. package/dist/icons/icons.js +186 -0
  36. package/dist/icons/index.d.ts +1 -0
  37. package/dist/icons/index.js +3 -0
  38. package/dist/index.d.ts +8 -0
  39. package/dist/index.js +12 -0
  40. package/dist/internal/accessible-name.d.ts +17 -0
  41. package/dist/internal/accessible-name.js +33 -0
  42. package/dist/internal/anchor-position.d.ts +99 -0
  43. package/dist/internal/anchor-position.js +159 -0
  44. package/dist/internal/anchored-drag.d.ts +25 -0
  45. package/dist/internal/anchored-drag.js +106 -0
  46. package/dist/internal/dev.d.ts +2 -0
  47. package/dist/internal/dev.js +18 -0
  48. package/dist/internal/diagnostics.d.ts +46 -0
  49. package/dist/internal/diagnostics.js +125 -0
  50. package/dist/internal/group-label.d.ts +22 -0
  51. package/dist/internal/group-label.js +50 -0
  52. package/dist/internal/interactive.d.ts +28 -0
  53. package/dist/internal/interactive.js +18 -0
  54. package/dist/internal/layout-element.d.ts +21 -0
  55. package/dist/internal/layout-element.js +33 -0
  56. package/dist/internal/merge-refs.d.ts +13 -0
  57. package/dist/internal/merge-refs.js +35 -0
  58. package/dist/internal/modal-dialog.d.ts +63 -0
  59. package/dist/internal/modal-dialog.js +267 -0
  60. package/dist/internal/navigation-count.d.ts +38 -0
  61. package/dist/internal/navigation-count.js +60 -0
  62. package/dist/internal/navigation-item.d.ts +14 -0
  63. package/dist/internal/navigation-item.js +17 -0
  64. package/dist/internal/nearest-scroller.d.ts +4 -0
  65. package/dist/internal/nearest-scroller.js +17 -0
  66. package/dist/internal/open-state.d.ts +15 -0
  67. package/dist/internal/open-state.js +42 -0
  68. package/dist/internal/roving-focus.d.ts +41 -0
  69. package/dist/internal/roving-focus.js +126 -0
  70. package/dist/internal/settle-animations.d.ts +33 -0
  71. package/dist/internal/settle-animations.js +48 -0
  72. package/dist/internal/time-period.d.ts +10 -0
  73. package/dist/internal/time-period.js +26 -0
  74. package/dist/internal/time.d.ts +23 -0
  75. package/dist/internal/time.js +69 -0
  76. package/dist/internal/typeahead.d.ts +17 -0
  77. package/dist/internal/typeahead.js +35 -0
  78. package/dist/molecules/Badge/Badge.d.ts +25 -0
  79. package/dist/molecules/Badge/Badge.js +16 -0
  80. package/dist/molecules/Button/Button.d.ts +48 -0
  81. package/dist/molecules/Button/Button.js +34 -0
  82. package/dist/molecules/Card/Card.d.ts +159 -0
  83. package/dist/molecules/Card/Card.js +119 -0
  84. package/dist/molecules/Checkbox/Checkbox.d.ts +26 -0
  85. package/dist/molecules/Checkbox/Checkbox.js +40 -0
  86. package/dist/molecules/Chip/AssistChip.d.ts +23 -0
  87. package/dist/molecules/Chip/AssistChip.js +22 -0
  88. package/dist/molecules/Chip/ChipGroup.d.ts +85 -0
  89. package/dist/molecules/Chip/ChipGroup.js +92 -0
  90. package/dist/molecules/Chip/FilterChip.d.ts +33 -0
  91. package/dist/molecules/Chip/FilterChip.js +30 -0
  92. package/dist/molecules/Chip/InputChip.d.ts +60 -0
  93. package/dist/molecules/Chip/InputChip.js +107 -0
  94. package/dist/molecules/Chip/SuggestionChip.d.ts +24 -0
  95. package/dist/molecules/Chip/SuggestionChip.js +17 -0
  96. package/dist/molecules/Chip/chip-content.d.ts +39 -0
  97. package/dist/molecules/Chip/chip-content.js +95 -0
  98. package/dist/molecules/Chip/chip-element.d.ts +14 -0
  99. package/dist/molecules/Chip/chip-element.js +14 -0
  100. package/dist/molecules/Chip/strings.d.ts +8 -0
  101. package/dist/molecules/Chip/strings.js +5 -0
  102. package/dist/molecules/Fab/Fab.d.ts +78 -0
  103. package/dist/molecules/Fab/Fab.js +52 -0
  104. package/dist/molecules/IconButton/IconButton.d.ts +59 -0
  105. package/dist/molecules/IconButton/IconButton.js +36 -0
  106. package/dist/molecules/LoadingIndicator/LoadingIndicator.d.ts +38 -0
  107. package/dist/molecules/LoadingIndicator/LoadingIndicator.js +25 -0
  108. package/dist/molecules/LoadingIndicator/determinate.d.ts +3 -0
  109. package/dist/molecules/LoadingIndicator/determinate.js +47 -0
  110. package/dist/molecules/LoadingIndicator/loading-indicator-data.d.ts +21 -0
  111. package/dist/molecules/LoadingIndicator/loading-indicator-data.js +72 -0
  112. package/dist/molecules/ProgressIndicator/CircularProgressIndicator.d.ts +35 -0
  113. package/dist/molecules/ProgressIndicator/CircularProgressIndicator.js +30 -0
  114. package/dist/molecules/ProgressIndicator/LinearProgressIndicator.d.ts +43 -0
  115. package/dist/molecules/ProgressIndicator/LinearProgressIndicator.js +28 -0
  116. package/dist/molecules/ProgressIndicator/circular-wavy-data.d.ts +5 -0
  117. package/dist/molecules/ProgressIndicator/circular-wavy-data.js +19 -0
  118. package/dist/molecules/ProgressIndicator/progress.d.ts +24 -0
  119. package/dist/molecules/ProgressIndicator/progress.js +60 -0
  120. package/dist/molecules/RadioButton/RadioButton.d.ts +27 -0
  121. package/dist/molecules/RadioButton/RadioButton.js +70 -0
  122. package/dist/molecules/RadioButton/RadioGroup.d.ts +73 -0
  123. package/dist/molecules/RadioButton/RadioGroup.js +82 -0
  124. package/dist/molecules/ScrollField/ScrollField.d.ts +61 -0
  125. package/dist/molecules/ScrollField/ScrollField.js +352 -0
  126. package/dist/molecules/Slider/RangeSlider.d.ts +60 -0
  127. package/dist/molecules/Slider/RangeSlider.js +169 -0
  128. package/dist/molecules/Slider/Slider.d.ts +54 -0
  129. package/dist/molecules/Slider/Slider.js +71 -0
  130. package/dist/molecules/Slider/slider-shared.d.ts +26 -0
  131. package/dist/molecules/Slider/slider-shared.js +98 -0
  132. package/dist/molecules/Switch/Switch.d.ts +22 -0
  133. package/dist/molecules/Switch/Switch.js +20 -0
  134. package/dist/molecules/TextField/TextField.d.ts +83 -0
  135. package/dist/molecules/TextField/TextField.js +146 -0
  136. package/dist/molecules/TextField/TextFieldSlots.d.ts +22 -0
  137. package/dist/molecules/TextField/TextFieldSlots.js +24 -0
  138. package/dist/molecules/TimeInput/TimeInput.d.ts +108 -0
  139. package/dist/molecules/TimeInput/TimeInput.js +347 -0
  140. package/dist/molecules/TimeInput/strings.d.ts +13 -0
  141. package/dist/molecules/TimeInput/strings.js +10 -0
  142. package/dist/molecules/TimeScroll/TimeScroll.d.ts +106 -0
  143. package/dist/molecules/TimeScroll/TimeScroll.js +213 -0
  144. package/dist/molecules/TimeScroll/strings.d.ts +13 -0
  145. package/dist/molecules/TimeScroll/strings.js +12 -0
  146. package/dist/molecules/index.d.ts +27 -0
  147. package/dist/molecules/index.js +25 -0
  148. package/dist/organisms/BottomSheet/BottomSheet.d.ts +128 -0
  149. package/dist/organisms/BottomSheet/BottomSheet.js +432 -0
  150. package/dist/organisms/BottomSheet/BottomSheetSlots.d.ts +17 -0
  151. package/dist/organisms/BottomSheet/BottomSheetSlots.js +16 -0
  152. package/dist/organisms/BottomSheet/StandardBottomSheet.d.ts +37 -0
  153. package/dist/organisms/BottomSheet/StandardBottomSheet.js +206 -0
  154. package/dist/organisms/BottomSheet/bottom-sheet-context.d.ts +31 -0
  155. package/dist/organisms/BottomSheet/bottom-sheet-context.js +12 -0
  156. package/dist/organisms/BottomSheet/sheet-drag.d.ts +1 -0
  157. package/dist/organisms/BottomSheet/sheet-drag.js +4 -0
  158. package/dist/organisms/BottomSheet/strings.d.ts +9 -0
  159. package/dist/organisms/BottomSheet/strings.js +8 -0
  160. package/dist/organisms/ButtonGroup/ButtonGroup.d.ts +97 -0
  161. package/dist/organisms/ButtonGroup/ButtonGroup.js +242 -0
  162. package/dist/organisms/ButtonGroup/ButtonGroupItem.d.ts +36 -0
  163. package/dist/organisms/ButtonGroup/ButtonGroupItem.js +47 -0
  164. package/dist/organisms/Dialog/Dialog.d.ts +186 -0
  165. package/dist/organisms/Dialog/Dialog.js +193 -0
  166. package/dist/organisms/Dialog/DialogSlots.d.ts +60 -0
  167. package/dist/organisms/Dialog/DialogSlots.js +54 -0
  168. package/dist/organisms/Dialog/strings.d.ts +5 -0
  169. package/dist/organisms/Dialog/strings.js +5 -0
  170. package/dist/organisms/FabMenu/FabMenu.d.ts +104 -0
  171. package/dist/organisms/FabMenu/FabMenu.js +142 -0
  172. package/dist/organisms/FabMenu/strings.d.ts +9 -0
  173. package/dist/organisms/FabMenu/strings.js +5 -0
  174. package/dist/organisms/List/List.d.ts +190 -0
  175. package/dist/organisms/List/List.js +148 -0
  176. package/dist/organisms/Menu/Menu.d.ts +313 -0
  177. package/dist/organisms/Menu/Menu.js +865 -0
  178. package/dist/organisms/Menu/MenuSlots.d.ts +35 -0
  179. package/dist/organisms/Menu/MenuSlots.js +36 -0
  180. package/dist/organisms/NavigationBar/NavigationBar.d.ts +96 -0
  181. package/dist/organisms/NavigationBar/NavigationBar.js +77 -0
  182. package/dist/organisms/NavigationRail/ModalNavigationRail.d.ts +105 -0
  183. package/dist/organisms/NavigationRail/ModalNavigationRail.js +272 -0
  184. package/dist/organisms/NavigationRail/NavigationRail.d.ts +148 -0
  185. package/dist/organisms/NavigationRail/NavigationRail.js +114 -0
  186. package/dist/organisms/NavigationRail/NavigationRailSection.d.ts +54 -0
  187. package/dist/organisms/NavigationRail/NavigationRailSection.js +96 -0
  188. package/dist/organisms/NavigationRail/strings.d.ts +7 -0
  189. package/dist/organisms/NavigationRail/strings.js +7 -0
  190. package/dist/organisms/NavigationSuite/NavigationSuite.d.ts +109 -0
  191. package/dist/organisms/NavigationSuite/NavigationSuite.js +86 -0
  192. package/dist/organisms/PaneScaffold/PaneScaffold.d.ts +106 -0
  193. package/dist/organisms/PaneScaffold/PaneScaffold.js +120 -0
  194. package/dist/organisms/Search/Search.d.ts +207 -0
  195. package/dist/organisms/Search/Search.js +754 -0
  196. package/dist/organisms/Search/SearchSlots.d.ts +16 -0
  197. package/dist/organisms/Search/SearchSlots.js +17 -0
  198. package/dist/organisms/Search/strings.d.ts +21 -0
  199. package/dist/organisms/Search/strings.js +12 -0
  200. package/dist/organisms/Select/Select.d.ts +186 -0
  201. package/dist/organisms/Select/Select.js +597 -0
  202. package/dist/organisms/Select/SelectSlots.d.ts +12 -0
  203. package/dist/organisms/Select/SelectSlots.js +12 -0
  204. package/dist/organisms/SideSheet/SideSheet.d.ts +88 -0
  205. package/dist/organisms/SideSheet/SideSheet.js +109 -0
  206. package/dist/organisms/SideSheet/SideSheetSlots.d.ts +35 -0
  207. package/dist/organisms/SideSheet/SideSheetSlots.js +37 -0
  208. package/dist/organisms/SideSheet/strings.d.ts +7 -0
  209. package/dist/organisms/SideSheet/strings.js +6 -0
  210. package/dist/organisms/Snackbar/Snackbar.d.ts +46 -0
  211. package/dist/organisms/Snackbar/Snackbar.js +36 -0
  212. package/dist/organisms/Snackbar/SnackbarHost.d.ts +57 -0
  213. package/dist/organisms/Snackbar/SnackbarHost.js +221 -0
  214. package/dist/organisms/Snackbar/snackbar-queue.d.ts +81 -0
  215. package/dist/organisms/Snackbar/snackbar-queue.js +114 -0
  216. package/dist/organisms/Snackbar/strings.d.ts +8 -0
  217. package/dist/organisms/Snackbar/strings.js +5 -0
  218. package/dist/organisms/SplitButton/SplitButton.d.ts +73 -0
  219. package/dist/organisms/SplitButton/SplitButton.js +77 -0
  220. package/dist/organisms/SplitButton/strings.d.ts +9 -0
  221. package/dist/organisms/SplitButton/strings.js +5 -0
  222. package/dist/organisms/Tabs/TabLink.d.ts +27 -0
  223. package/dist/organisms/Tabs/TabLink.js +25 -0
  224. package/dist/organisms/Tabs/TabNav.d.ts +19 -0
  225. package/dist/organisms/Tabs/TabNav.js +55 -0
  226. package/dist/organisms/Tabs/Tabs.d.ts +147 -0
  227. package/dist/organisms/Tabs/Tabs.js +223 -0
  228. package/dist/organisms/Tabs/tab-content.d.ts +23 -0
  229. package/dist/organisms/Tabs/tab-content.js +105 -0
  230. package/dist/organisms/Tabs/tab-fit.d.ts +4 -0
  231. package/dist/organisms/Tabs/tab-fit.js +65 -0
  232. package/dist/organisms/Tabs/tab-motion.d.ts +2 -0
  233. package/dist/organisms/Tabs/tab-motion.js +68 -0
  234. package/dist/organisms/TimePickerDialog/TimePickerDialog.d.ts +26 -0
  235. package/dist/organisms/TimePickerDialog/TimePickerDialog.js +34 -0
  236. package/dist/organisms/Toolbar/Toolbar.d.ts +75 -0
  237. package/dist/organisms/Toolbar/Toolbar.js +84 -0
  238. package/dist/organisms/Toolbar/ToolbarLayout.d.ts +44 -0
  239. package/dist/organisms/Toolbar/ToolbarLayout.js +90 -0
  240. package/dist/organisms/Toolbar/ToolbarScroll.d.ts +8 -0
  241. package/dist/organisms/Toolbar/ToolbarScroll.js +222 -0
  242. package/dist/organisms/Tooltip/RichTooltip.d.ts +73 -0
  243. package/dist/organisms/Tooltip/RichTooltip.js +250 -0
  244. package/dist/organisms/Tooltip/Tooltip.d.ts +52 -0
  245. package/dist/organisms/Tooltip/Tooltip.js +99 -0
  246. package/dist/organisms/Tooltip/tooltip-behavior.d.ts +43 -0
  247. package/dist/organisms/Tooltip/tooltip-behavior.js +307 -0
  248. package/dist/organisms/TopAppBar/TopAppBar.d.ts +107 -0
  249. package/dist/organisms/TopAppBar/TopAppBar.js +78 -0
  250. package/dist/organisms/TopAppBar/TopAppBarScroll.d.ts +7 -0
  251. package/dist/organisms/TopAppBar/TopAppBarScroll.js +155 -0
  252. package/dist/organisms/index.d.ts +36 -0
  253. package/dist/organisms/index.js +36 -0
  254. package/dist/palettes/blue.css +275 -0
  255. package/dist/palettes/green.css +275 -0
  256. package/dist/palettes/index.css +823 -0
  257. package/dist/palettes/orange.css +275 -0
  258. package/dist/shapes.css +115 -0
  259. package/dist/strings/index.d.ts +35 -0
  260. package/dist/strings/index.js +39 -0
  261. package/dist/styles-no-fonts.css +11991 -0
  262. package/dist/styles.css +12089 -0
  263. package/dist/stylesheet.d.ts +2 -0
  264. package/dist/tokens/breakpoints.d.ts +33 -0
  265. package/dist/tokens/breakpoints.js +31 -0
  266. package/dist/tokens/space.d.ts +26 -0
  267. package/dist/tokens/space.js +26 -0
  268. package/package.json +110 -3
@@ -0,0 +1,597 @@
1
+ 'use client';
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // Organismo interactivo (ADR-0003, ADR-0036): la caja del TextField con el patrón "select-only
4
+ // combobox" de WAI-ARIA APG y la lista con el aspecto del Menu. Necesita estado (valor, abierto,
5
+ // opción activa), efectos (popover, clic afuera, reinicio del formulario) y contexto (las partes leen
6
+ // el valor, la activa y los ids), así que todo el módulo es cliente; SelectLeading, sin nada de eso,
7
+ // es universal (SelectSlots.tsx).
8
+ //
9
+ // - Partes como el TextField (decidido con el autor el 2026-11-29): SelectLabel, SelectLeading,
10
+ // SelectSupporting y la lista SelectContent con SelectOption y SelectGroup (y su SelectGroupLabel,
11
+ // sobre la base común con MenuGroupLabel de src/internal/group-label.tsx), todas hijas de Select
12
+ // y ubicadas por clase en la grilla de la caja. La lista (un popover en la capa superior) queda
13
+ // dentro de la caja en el DOM: los clics que suben desde ella se ignoran y el hover de la caja la
14
+ // excluye (text-field.css, `[popover]`).
15
+ // - El foco se queda en el combobox (un <div tabindex="0">) también con la lista abierta: la opción
16
+ // activa es aria-activedescendant, como en Search (ADR-0026) y en el ejemplo de APG. Por eso la
17
+ // lista no es un MenuContent (que mueve el foco a sus elementos con role="menu"): reutiliza su CSS
18
+ // (.mk-menu, .mk-menu-item) y su posicionamiento (src/internal/anchor-position.ts).
19
+ // - La caja usa las clases del TextField y sus ganchos para un control que no es un <input>
20
+ // (.mk-text-field-control, data-populated, data-disabled en text-field.css).
21
+ // - El texto del valor sale de los hijos en el render (SelectContent → SelectOption y SelectGroup,
22
+ // con `textValue` o un texto simple), así el HTML del servidor ya lo muestra; si no se puede (una
23
+ // opción envuelta en un componente propio, contenido con elementos sin `textValue`), se lee del DOM
24
+ // después de montar y se avisa en desarrollo (MK_OPTION_TEXT_UNRESOLVED).
25
+ // - Formulario: un <select> nativo oculto (aria-hidden, fuera del orden de Tab) bajo la caja lleva
26
+ // `name`, `required`, `disabled` y `form`; da FormData, la validación nativa (:invalid,
27
+ // checkValidity, el globo del navegador) y el reinicio. Elegido con una sonda en los tres motores
28
+ // (CLAUDE.md, "Motores", 2026-11-29): un <input type="hidden"> no participa de la validación.
29
+ import { Children, createContext, Fragment, isValidElement, use, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, } from 'react';
30
+ import { FocusRing } from '../../atoms/FocusRing/FocusRing.js';
31
+ import { Ripple } from '../../atoms/Ripple/Ripple.js';
32
+ import { StateLayer } from '../../atoms/StateLayer/StateLayer.js';
33
+ import { ArrowDropDownIcon } from '../../icons/icons.js';
34
+ import { hasAccessibleName } from '../../internal/accessible-name.js';
35
+ import { followAnchor, placeNextTo, supportsAnchorPositioning } from '../../internal/anchor-position.js';
36
+ import { isDevelopment } from '../../internal/dev.js';
37
+ import { mkWarn, partOutsideParent } from '../../internal/diagnostics.js';
38
+ import { mergeRefs } from '../../internal/merge-refs.js';
39
+ import { useOpenState } from '../../internal/open-state.js';
40
+ import { settleAnimations } from '../../internal/settle-animations.js';
41
+ import { createTypeahead, typeaheadActive, typeaheadMatch } from '../../internal/typeahead.js';
42
+ import { GroupLabel, useGroupLabel } from '../../internal/group-label.js';
43
+ const SelectContext = createContext(null);
44
+ function useSelect(part) {
45
+ const ctx = use(SelectContext);
46
+ if (!ctx)
47
+ throw partOutsideParent(part, 'Select');
48
+ return ctx;
49
+ }
50
+ const cx = (base, extra) => (extra ? `${base} ${extra}` : base);
51
+ const OPTION_SELECTOR = '[role="option"]';
52
+ // Saltos de Re Pág y Av Pág (APG).
53
+ const PAGE_STEP = 10;
54
+ // Opciones habilitadas, en el orden del DOM (así valen los grupos).
55
+ function enabledOptions(listbox) {
56
+ if (!listbox)
57
+ return [];
58
+ return [...listbox.querySelectorAll(`${OPTION_SELECTOR}:not([aria-disabled="true"])`)];
59
+ }
60
+ // Texto de una opción en el DOM: el que busca la búsqueda por letra (y el respaldo del campo).
61
+ const optionText = (option) => option.dataset['textValue'] ?? option.textContent?.trim() ?? '';
62
+ // Texto simple de unos hijos (textos y números, también en un arreglo); `undefined` si hay elementos.
63
+ function plainText(children) {
64
+ let text = '';
65
+ let plain = true;
66
+ Children.forEach(children, (child) => {
67
+ if (typeof child === 'string' || typeof child === 'number')
68
+ text += String(child);
69
+ else if (child != null && typeof child !== 'boolean')
70
+ plain = false;
71
+ });
72
+ return plain ? text.trim() : undefined;
73
+ }
74
+ // Recorre los hijos de Select (y los de SelectContent y SelectGroup, a través de fragmentos) sin
75
+ // renderizar: así la etiqueta, la ayuda y el texto del valor ya están en el HTML del servidor. Un
76
+ // componente propio que envuelve una parte no se ve; para eso están el registro de las partes y la
77
+ // lectura del DOM (ver arriba).
78
+ function scanChildren(children, value, ids, scan) {
79
+ Children.forEach(children, (child) => {
80
+ if (!isValidElement(child))
81
+ return;
82
+ const { type, props } = child;
83
+ if (type === Fragment || type === SelectContent || type === SelectGroup) {
84
+ scanChildren(props.children, value, ids, scan);
85
+ }
86
+ else if (type === SelectLabel) {
87
+ scan.labelId = props.id ?? ids.label;
88
+ }
89
+ else if (type === SelectSupporting) {
90
+ scan.supportingId = props.id ?? ids.supporting;
91
+ }
92
+ else if (type === SelectOption && value !== '' && props.value === value && scan.text === undefined) {
93
+ scan.text = props.textValue ?? plainText(props.children);
94
+ }
95
+ });
96
+ }
97
+ /**
98
+ * Material 3 select (the "exposed dropdown menu"), built by composition like `TextField`: the text
99
+ * field box (filled or outlined, floating label, supporting text, error) that opens a list of
100
+ * options, with the WAI-ARIA APG "select-only combobox" pattern. It submits with `name` in a
101
+ * `<form>`, and `required` takes part in native validation. The parts are direct children, placed
102
+ * by class (their order does not matter):
103
+ *
104
+ * ```tsx
105
+ * <Select variant="outlined" name="subject" required value={v} onValueChange={setV} error={!!err}>
106
+ * <SelectLabel>Subject</SelectLabel>
107
+ * <SelectContent>
108
+ * <SelectOption value="general">General question</SelectOption>
109
+ * <SelectGroup>
110
+ * <SelectGroupLabel>Sales</SelectGroupLabel>
111
+ * <SelectOption value="billing">Billing</SelectOption>
112
+ * </SelectGroup>
113
+ * </SelectContent>
114
+ * <SelectSupporting>{err ?? 'We answer within 48 hours'}</SelectSupporting>
115
+ * </Select>
116
+ * ```
117
+ *
118
+ * - **Keyboard:** on the closed field, Arrow Down, Arrow Up, Enter, Space and Alt+Arrow Down open
119
+ * the list on the chosen option (or the first); Home and End open it on the first or last; a
120
+ * letter opens it on the next option starting with it. Open, the arrows move without wrapping,
121
+ * Home, End, Page Up and Page Down jump, letters search, Enter, Space and Alt+Arrow Up choose and
122
+ * close, Escape closes without changing, and Tab chooses the active option and moves on (APG).
123
+ * Focus never leaves the field: the active option is `aria-activedescendant`.
124
+ * - **Pointer:** a click on the field opens or closes the list; a click on an option chooses it; a
125
+ * click outside closes it.
126
+ * - The list is as wide as the field, below it (above if there is no room) and scrolls when long.
127
+ * - Native props, `id` and `ref` go to the combobox element; `className` and `style` to the field
128
+ * box. Default width 280 px, like `TextField`.
129
+ * - The field shows the chosen option's text already in the server HTML when the option is a
130
+ * `SelectOption` written inside `SelectContent` (or a `SelectGroup`) with plain-text children or
131
+ * `textValue`.
132
+ */
133
+ export function Select({ variant = 'filled', placeholder, value: controlledValue, defaultValue = '', onValueChange, open, defaultOpen, onOpenChange, error = false, disabled = false, required = false, name, form, onInvalid, inputRef, className, style, children, ref, onKeyDown, onBlur, ...props }) {
134
+ const id = useId();
135
+ const comboboxId = props.id ?? `${id}combobox`;
136
+ const defaultLabelId = `${id}label`;
137
+ const defaultSupportingId = `${id}supporting`;
138
+ const listboxId = `${id}listbox`;
139
+ // anchor-name tiene que ser un <dashed-ident>: sin los caracteres que pone useId.
140
+ const anchorName = `--mk-select-${id.replace(/[^a-zA-Z0-9_-]/g, '')}`;
141
+ const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
142
+ const controlled = controlledValue !== undefined;
143
+ const value = controlled ? controlledValue : uncontrolledValue;
144
+ const { isOpen, setOpen } = useOpenState({ open, defaultOpen, onOpenChange });
145
+ const expanded = isOpen && !disabled;
146
+ const [activeId, setActiveId] = useState(null);
147
+ // Las partes del campo y el texto del valor, desde los hijos (también en el servidor). Las partes
148
+ // además registran su id al montar, para las que vienen dentro de un componente propio.
149
+ const scan = { labelId: null, supportingId: null, text: undefined };
150
+ scanChildren(children, value, { label: defaultLabelId, supporting: defaultSupportingId }, scan);
151
+ const [registeredLabelId, setLabelId] = useState(null);
152
+ const [registeredSupportingId, setSupportingId] = useState(null);
153
+ const labelId = registeredLabelId ?? scan.labelId;
154
+ const supportingId = registeredSupportingId ?? scan.supportingId;
155
+ const fieldRef = useRef(null);
156
+ const boxRef = useRef(null);
157
+ const comboboxRef = useRef(null);
158
+ const listboxRef = useRef(null);
159
+ const nativeRef = useRef(null);
160
+ const setComboboxRef = useMemo(() => mergeRefs(comboboxRef, ref), [ref]);
161
+ const setNativeRef = useMemo(() => mergeRefs(nativeRef, inputRef), [inputRef]);
162
+ const typeahead = useRef(createTypeahead());
163
+ // La opción que se activa al abrir: la elegida o la primera (o la que pidió la tecla).
164
+ const openTarget = useRef('selected');
165
+ // Respaldo del texto: si el render no lo pudo sacar de los hijos, se lee de la opción en el DOM (las
166
+ // opciones están siempre montadas en la lista oculta) y se sigue con un MutationObserver.
167
+ const resolved = value === '' || scan.text !== undefined;
168
+ const [domText, setDomText] = useState('');
169
+ const warnedText = useRef({});
170
+ useLayoutEffect(() => {
171
+ const listbox = listboxRef.current;
172
+ if (resolved || !listbox)
173
+ return;
174
+ const update = () => {
175
+ const option = [...listbox.querySelectorAll(OPTION_SELECTOR)].find((o) => o.dataset['value'] === value);
176
+ setDomText(option ? optionText(option) : '');
177
+ if (option && isDevelopment()) {
178
+ mkWarn('MK_OPTION_TEXT_UNRESOLVED', {
179
+ component: 'Select',
180
+ problem: "the chosen option's text could not be read from its props, so the server HTML shows an empty field until hydration",
181
+ fix: 'give the SelectOption plain-text children or a textValue, and write it directly inside SelectContent or a SelectGroup',
182
+ }, { value }, { once: warnedText.current });
183
+ }
184
+ };
185
+ update();
186
+ const observer = new MutationObserver(update);
187
+ observer.observe(listbox, {
188
+ childList: true,
189
+ subtree: true,
190
+ characterData: true,
191
+ attributeFilter: ['data-value', 'data-text-value'],
192
+ });
193
+ return () => observer.disconnect();
194
+ }, [resolved, value]);
195
+ const display = value === '' ? '' : (scan.text ?? domText);
196
+ const commit = useCallback((next, event) => {
197
+ if (next === value)
198
+ return;
199
+ if (!controlled)
200
+ setUncontrolledValue(next);
201
+ onValueChange?.(next, event);
202
+ }, [value, controlled, onValueChange]);
203
+ const choose = useCallback((option, event) => {
204
+ if (option.getAttribute('aria-disabled') === 'true')
205
+ return;
206
+ commit(option.dataset['value'] ?? '', event);
207
+ setOpen(false, 'select');
208
+ }, [commit, setOpen]);
209
+ // Al abrir, la activa según el pedido. Se resuelve en el DOM porque las opciones son hijos libres.
210
+ const applyOpenTarget = useCallback(() => {
211
+ const options = enabledOptions(listboxRef.current);
212
+ const target = openTarget.current;
213
+ openTarget.current = 'selected';
214
+ let option;
215
+ if (target instanceof HTMLElement)
216
+ option = target;
217
+ else if (target === 'last')
218
+ option = options.at(-1);
219
+ else if (target === 'first')
220
+ option = options[0];
221
+ else
222
+ option = options.find((o) => o.dataset['value'] === value && value !== '') ?? options[0];
223
+ setActiveId(option?.id ?? null);
224
+ }, [value]);
225
+ const requestOpen = (target) => {
226
+ openTarget.current = target;
227
+ if (expanded)
228
+ applyOpenTarget();
229
+ else
230
+ setOpen(true, 'trigger');
231
+ };
232
+ // Mostrar y ocultar la lista (popover manual, como el Menu), con la salida animada.
233
+ const closing = useRef(null);
234
+ const place = useCallback(() => {
235
+ const listbox = listboxRef.current;
236
+ const box = boxRef.current;
237
+ if (!listbox || !box)
238
+ return;
239
+ // Sin anchor positioning, el ancho también se escribe (con él, lo da el CSS estirado).
240
+ if (!supportsAnchorPositioning())
241
+ listbox.style.inlineSize = `${box.getBoundingClientRect().width}px`;
242
+ placeNextTo(listbox, box);
243
+ }, []);
244
+ useLayoutEffect(() => {
245
+ const listbox = listboxRef.current;
246
+ if (!listbox)
247
+ return;
248
+ if (expanded) {
249
+ closing.current = null;
250
+ listbox.removeAttribute('data-closing');
251
+ if (!listbox.matches(':popover-open')) {
252
+ listbox.showPopover();
253
+ place();
254
+ }
255
+ applyOpenTarget();
256
+ return;
257
+ }
258
+ setActiveId(null);
259
+ if (!listbox.matches(':popover-open') || closing.current)
260
+ return;
261
+ const token = {};
262
+ closing.current = token;
263
+ listbox.setAttribute('data-closing', '');
264
+ void settleAnimations(listbox, () => closing.current === token).then(() => {
265
+ if (closing.current !== token)
266
+ return;
267
+ closing.current = null;
268
+ listbox.removeAttribute('data-closing');
269
+ if (listbox.matches(':popover-open'))
270
+ listbox.hidePopover();
271
+ });
272
+ // Sin applyOpenTarget en las dependencias: cambia con el valor, y elegir con la lista abierta no
273
+ // tiene que volver a mover la activa.
274
+ }, [expanded, place]);
275
+ useLayoutEffect(() => () => {
276
+ closing.current = null;
277
+ }, []);
278
+ // Abierta: un clic afuera de la caja (que contiene la lista) la cierra (el foco queda donde lo puso
279
+ // el clic); sin anchor positioning, seguir a la caja al desplazarse la página.
280
+ useEffect(() => {
281
+ if (!expanded)
282
+ return;
283
+ const onPointerDown = (e) => {
284
+ const target = e.target;
285
+ if (!target || fieldRef.current?.contains(target))
286
+ return;
287
+ setOpen(false, 'outside');
288
+ };
289
+ document.addEventListener('pointerdown', onPointerDown, true);
290
+ const unfollow = followAnchor(place);
291
+ return () => {
292
+ document.removeEventListener('pointerdown', onPointerDown, true);
293
+ unfollow();
294
+ };
295
+ }, [expanded, setOpen, place]);
296
+ // La activa a la vista dentro de la lista, sin desplazar la página (scrollIntoView movería
297
+ // también los contenedores de afuera).
298
+ useLayoutEffect(() => {
299
+ const listbox = listboxRef.current;
300
+ const option = activeId ? document.getElementById(activeId) : null;
301
+ if (!listbox || !option || !listbox.contains(option))
302
+ return;
303
+ const top = option.offsetTop;
304
+ const bottom = top + option.offsetHeight;
305
+ if (top < listbox.scrollTop)
306
+ listbox.scrollTop = top;
307
+ else if (bottom > listbox.scrollTop + listbox.clientHeight)
308
+ listbox.scrollTop = bottom - listbox.clientHeight;
309
+ }, [activeId]);
310
+ // form.reset(): el evento llega antes del reinicio, así que se espera a que el navegador termine.
311
+ // Sin controlar, vuelve a `defaultValue`; controlado, el valor es de la app (como un <input>
312
+ // controlado de React). En los dos casos el <select> oculto vuelve a mostrar el valor del campo.
313
+ const latest = useRef({ controlled, defaultValue, value });
314
+ latest.current = { controlled, defaultValue, value };
315
+ useEffect(() => {
316
+ const owner = nativeRef.current?.form;
317
+ if (!owner)
318
+ return;
319
+ const onReset = () => {
320
+ setTimeout(() => {
321
+ const { controlled: isControlled, defaultValue: initial, value: current } = latest.current;
322
+ if (!isControlled)
323
+ setUncontrolledValue(initial);
324
+ const native = nativeRef.current;
325
+ if (native)
326
+ native.value = isControlled ? current : initial;
327
+ });
328
+ };
329
+ owner.addEventListener('reset', onReset);
330
+ return () => owner.removeEventListener('reset', onReset);
331
+ }, [form]);
332
+ // Sin nombre accesible (MK_FIELD_UNNAMED, ADR-0035): medido en el DOM un cuadro después de montar.
333
+ const warnedName = useRef({});
334
+ useEffect(() => {
335
+ if (!isDevelopment())
336
+ return;
337
+ const frame = requestAnimationFrame(() => {
338
+ const combobox = comboboxRef.current;
339
+ if (!combobox?.isConnected || hasAccessibleName(combobox))
340
+ return;
341
+ mkWarn('MK_FIELD_UNNAMED', {
342
+ component: 'Select',
343
+ problem: 'the field has no accessible name, so a screen reader announces only its role; a placeholder is not a label',
344
+ fix: 'add a <SelectLabel> to the Select (<SelectLabel>Subject</SelectLabel>), or pass aria-label or aria-labelledby to the <Select>',
345
+ }, undefined, { once: warnedName.current });
346
+ });
347
+ return () => cancelAnimationFrame(frame);
348
+ }, []);
349
+ const handleKeyDown = (e) => {
350
+ onKeyDown?.(e);
351
+ if (e.defaultPrevented || disabled || e.ctrlKey || e.metaKey)
352
+ return;
353
+ const listbox = listboxRef.current;
354
+ const options = enabledOptions(listbox);
355
+ const active = activeId ? document.getElementById(activeId) : null;
356
+ const index = active ? options.indexOf(active) : -1;
357
+ const moveTo = (i) => {
358
+ e.preventDefault();
359
+ const option = options[Math.max(0, Math.min(i, options.length - 1))];
360
+ if (option)
361
+ setActiveId(option.id);
362
+ };
363
+ if (!expanded) {
364
+ switch (e.key) {
365
+ case 'ArrowDown':
366
+ case 'ArrowUp':
367
+ case 'Enter':
368
+ case ' ':
369
+ e.preventDefault();
370
+ return requestOpen('selected');
371
+ case 'Home':
372
+ e.preventDefault();
373
+ return requestOpen('first');
374
+ case 'End':
375
+ e.preventDefault();
376
+ return requestOpen('last');
377
+ }
378
+ }
379
+ else {
380
+ switch (e.key) {
381
+ case 'ArrowDown':
382
+ return moveTo(index + 1);
383
+ case 'ArrowUp':
384
+ if (e.altKey) {
385
+ e.preventDefault();
386
+ if (active)
387
+ choose(active, e);
388
+ else
389
+ setOpen(false, 'select');
390
+ return;
391
+ }
392
+ return moveTo(index < 0 ? 0 : index - 1);
393
+ case 'Home':
394
+ return moveTo(0);
395
+ case 'End':
396
+ return moveTo(options.length - 1);
397
+ case 'PageDown':
398
+ return moveTo(index + PAGE_STEP);
399
+ case 'PageUp':
400
+ return moveTo(index - PAGE_STEP);
401
+ case 'Enter':
402
+ e.preventDefault();
403
+ if (active)
404
+ choose(active, e);
405
+ return;
406
+ case ' ':
407
+ // Un Espacio en medio de una búsqueda por letra es parte del texto ("New York").
408
+ if (typeaheadActive(typeahead.current))
409
+ break;
410
+ e.preventDefault();
411
+ if (active)
412
+ choose(active, e);
413
+ return;
414
+ case 'Escape':
415
+ // stopPropagation: dentro de un Dialog, Escape cierra solo la lista.
416
+ e.preventDefault();
417
+ e.stopPropagation();
418
+ setOpen(false, 'escape');
419
+ return;
420
+ case 'Tab':
421
+ // APG: Tab elige la activa, cierra y sigue al próximo enfocable (sin preventDefault).
422
+ if (active)
423
+ commit(active.dataset['value'] ?? '', e);
424
+ setOpen(false, 'tab');
425
+ return;
426
+ }
427
+ }
428
+ // Búsqueda por letra: abre la lista si hace falta (APG) y activa la opción que coincide.
429
+ if (e.altKey || e.key.length !== 1)
430
+ return;
431
+ if (e.key === ' ' && !typeaheadActive(typeahead.current))
432
+ return;
433
+ const match = typeaheadMatch(typeahead.current, e.key, options.map(optionText), index);
434
+ e.preventDefault();
435
+ const option = options[match];
436
+ if (!option)
437
+ return;
438
+ if (expanded)
439
+ setActiveId(option.id);
440
+ else
441
+ requestOpen(option);
442
+ };
443
+ const handleBlur = (e) => {
444
+ onBlur?.(e);
445
+ if (!expanded)
446
+ return;
447
+ const next = e.relatedTarget;
448
+ if (next && fieldRef.current?.contains(next))
449
+ return;
450
+ setOpen(false, 'focus-out');
451
+ };
452
+ // Un clic en la caja (también en la etiqueta, los iconos o el borde) abre o cierra, salvo en el
453
+ // texto de ayuda y en la lista (que está dentro de la caja en el árbol de React y en el DOM).
454
+ const handleFieldClick = (e) => {
455
+ if (disabled || e.button !== 0)
456
+ return;
457
+ if (e.target.closest('.mk-text-field-supporting, .mk-select-native, .mk-select-listbox'))
458
+ return;
459
+ comboboxRef.current?.focus();
460
+ if (expanded)
461
+ setOpen(false, 'trigger');
462
+ else
463
+ requestOpen('selected');
464
+ };
465
+ const ariaLabel = props['aria-label'];
466
+ const labelledBy = props['aria-labelledby'] ?? (labelId && !ariaLabel ? labelId : undefined);
467
+ const describedBy = [props['aria-describedby'], supportingId].filter(Boolean).join(' ') || undefined;
468
+ const ctx = useMemo(() => ({
469
+ variant,
470
+ value,
471
+ activeId,
472
+ setActiveId,
473
+ choose,
474
+ labelId: defaultLabelId,
475
+ supportingId: defaultSupportingId,
476
+ setLabelId,
477
+ setSupportingId,
478
+ listboxRef,
479
+ listboxId,
480
+ anchorName,
481
+ listName: labelledBy ? { 'aria-labelledby': labelledBy } : { 'aria-label': ariaLabel },
482
+ }), [variant, value, activeId, choose, defaultLabelId, defaultSupportingId, listboxId, anchorName, labelledBy, ariaLabel]);
483
+ const populated = display !== '';
484
+ return (_jsx(SelectContext, { value: ctx, children: _jsxs("div", { ref: fieldRef, className: cx('mk-text-field mk-select', className), style: style, "data-variant": variant, "data-error": error || undefined, "data-populated": populated || undefined, "data-disabled": disabled || undefined, "data-open": expanded || undefined, onClick: handleFieldClick, children: [_jsx("span", { ref: boxRef, className: "mk-text-field-container", "aria-hidden": "true", style: { anchorName }, children: _jsx(StateLayer, {}) }), _jsx("div", { ...props, ref: setComboboxRef, id: comboboxId, role: "combobox", tabIndex: disabled ? undefined : (props.tabIndex ?? 0), className: "mk-text-field-control mk-select-control", "aria-haspopup": "listbox", "aria-expanded": expanded, "aria-controls": listboxId, "aria-activedescendant": expanded && activeId ? activeId : undefined, "aria-labelledby": labelledBy, "aria-describedby": describedBy, "aria-required": required || undefined, "aria-invalid": error || undefined, "aria-disabled": disabled || undefined, onKeyDown: handleKeyDown, onBlur: handleBlur, children: populated ? (display) : placeholder != null ? (_jsx("span", { className: "mk-select-placeholder", children: placeholder })) : null }), _jsx("span", { className: "mk-text-field-trailing mk-select-arrow", "aria-hidden": "true", children: _jsx(ArrowDropDownIcon, {}) }), _jsxs("select", { ref: setNativeRef, className: "mk-select-native", "aria-hidden": "true", tabIndex: -1, name: name, form: form, required: required, disabled: disabled, value: value, onChange: () => { }, onInvalid: onInvalid,
485
+ // El navegador enfoca el control inválido al enviar: el foco pasa al combobox.
486
+ onFocus: () => comboboxRef.current?.focus(), children: [_jsx("option", { value: "" }), value !== '' && _jsx("option", { value: value, children: display })] }), children] }) }));
487
+ }
488
+ // Registra en el Select el id de una parte del campo (para las que vienen envueltas en otro componente).
489
+ function useRegisteredId(id, register) {
490
+ useLayoutEffect(() => {
491
+ register(id);
492
+ return () => register(null);
493
+ }, [id, register]);
494
+ }
495
+ /**
496
+ * The field's label, the same as `TextFieldLabel`: in place of the text at rest (Body Large), it
497
+ * floats up (Body Small) with focus or a value. It names the field and the list (`aria-labelledby`;
498
+ * not a `<label>`, since the combobox is not a labelable element).
499
+ *
500
+ * In the outlined field it also draws the border with a notch (a hidden `<fieldset>`/`<legend>`), so
501
+ * its content should be plain text.
502
+ */
503
+ export function SelectLabel({ id, className, children, ...props }) {
504
+ const ctx = useSelect('SelectLabel');
505
+ const ownId = id ?? ctx.labelId;
506
+ useRegisteredId(ownId, ctx.setLabelId);
507
+ return (_jsxs(_Fragment, { children: [_jsx("span", { ...props, id: ownId, className: cx('mk-text-field-label', className), children: children }), ctx.variant === 'outlined' && (_jsx("fieldset", { className: "mk-text-field-outline", "aria-hidden": "true", children: _jsx("legend", { className: "mk-text-field-notch", children: _jsx("span", { children: children }) }) }))] }));
508
+ }
509
+ /**
510
+ * Text below the field (Body Small), the same as `TextFieldSupporting`: the field's description
511
+ * (`aria-describedby`). With `error` on the `Select` it takes the error color: to show the error
512
+ * message, change its content.
513
+ */
514
+ export function SelectSupporting({ id, className, ...props }) {
515
+ const ctx = useSelect('SelectSupporting');
516
+ const ownId = id ?? ctx.supportingId;
517
+ useRegisteredId(ownId, ctx.setSupportingId);
518
+ return _jsx("div", { ...props, id: ownId, className: cx('mk-text-field-supporting', className) });
519
+ }
520
+ /**
521
+ * The list of options (`role="listbox"`), drawn as a Material 3 menu like `MenuContent`: a popover
522
+ * in the top layer, as wide as the field, below it (above if there is no room), scrolling when
523
+ * long. Named like the field. Always mounted, hidden while closed. Native props, `className`,
524
+ * `style` and `ref` go to the list.
525
+ */
526
+ export function SelectContent({ className, style, children, ref, onMouseDown, ...props }) {
527
+ const ctx = useSelect('SelectContent');
528
+ const { listboxRef } = ctx;
529
+ const setRef = useMemo(() => mergeRefs(listboxRef, ref), [listboxRef, ref]);
530
+ return (_jsx("div", { ...ctx.listName, ...props, ref: setRef, id: ctx.listboxId, role: "listbox", popover: "manual", className: cx('mk-menu mk-select-listbox', className), "data-color": "standard", style: { ...style, '--_anchor': ctx.anchorName }, onMouseDown: (e) => {
531
+ onMouseDown?.(e);
532
+ // Un clic en la lista no le saca el foco al combobox (APG).
533
+ if (e.button === 0)
534
+ e.preventDefault();
535
+ }, children: children }));
536
+ }
537
+ /**
538
+ * An option of a `Select` (`role="option"`), inside `SelectContent` or a `SelectGroup`, drawn as a
539
+ * Material 3 menu item: 48 px rows, Label Large, the chosen one in `tertiary-container`. It never
540
+ * takes focus: the keyboard marks the active option with `aria-activedescendant` and
541
+ * `aria-selected`.
542
+ *
543
+ * ```tsx
544
+ * <SelectOption value="ar">Argentina</SelectOption>
545
+ * ```
546
+ */
547
+ export function SelectOption({ value, textValue, disabled = false, className, children, id, onClick, onPointerMove, ...props }) {
548
+ const ctx = useSelect('SelectOption');
549
+ const generatedId = useId();
550
+ const optionId = id ?? `${generatedId}option`;
551
+ const active = ctx.activeId === optionId;
552
+ const selected = value === ctx.value;
553
+ return (_jsxs("div", { ...props, id: optionId, role: "option", "aria-selected": active, "aria-disabled": disabled || undefined, "data-value": value, "data-text-value": textValue, "data-selected": selected || undefined, "data-active": active || undefined, className: cx('mk-menu-item mk-select-option', className), onClick: (e) => {
554
+ onClick?.(e);
555
+ if (e.defaultPrevented)
556
+ return;
557
+ ctx.choose(e.currentTarget, e);
558
+ }, onPointerMove: (e) => {
559
+ onPointerMove?.(e);
560
+ // El puntero también mueve la activa, así no quedan dos resaltadas (como un <select>).
561
+ if (!disabled && e.pointerType === 'mouse' && !active)
562
+ ctx.setActiveId(optionId);
563
+ }, children: [_jsx(StateLayer, {}), _jsx(Ripple, {}), _jsx(FocusRing, {}), children] }));
564
+ }
565
+ const SelectGroupContext = createContext(null);
566
+ /**
567
+ * A group of options inside `SelectContent` (`role="group"`, named by its `SelectGroupLabel`). The
568
+ * keyboard moves through the options of all groups as one list.
569
+ *
570
+ * ```tsx
571
+ * <SelectGroup>
572
+ * <SelectGroupLabel>Fruit</SelectGroupLabel>
573
+ * <SelectOption value="apple">Apple</SelectOption>
574
+ * </SelectGroup>
575
+ * ```
576
+ */
577
+ export function SelectGroup({ className, ...props }) {
578
+ useSelect('SelectGroup');
579
+ const { registry, labelledBy } = useGroupLabel(props['aria-labelledby']);
580
+ return (_jsx(SelectGroupContext, { value: registry, children: _jsx("div", { ...props, role: "group", "aria-labelledby": labelledBy, className: cx('mk-select-group', className) }) }));
581
+ }
582
+ /**
583
+ * The heading of a `SelectGroup` (the kit's menu section label: 32 px, Label Large,
584
+ * `on-surface-variant`). It names the group (`aria-labelledby`), without passing ids. It is not an
585
+ * option: the arrows and the typeahead skip it.
586
+ *
587
+ * ```tsx
588
+ * <SelectGroup><SelectGroupLabel>Fruit</SelectGroupLabel>…</SelectGroup>
589
+ * ```
590
+ */
591
+ export function SelectGroupLabel({ className, ...props }) {
592
+ const registry = use(SelectGroupContext);
593
+ if (!registry)
594
+ throw partOutsideParent('SelectGroupLabel', 'SelectGroup');
595
+ // La base (src/internal/group-label.tsx), común con MenuGroupLabel: marcado, clase y registro del id.
596
+ return _jsx(GroupLabel, { ...props, registry: registry, className: cx('mk-select-group-label', className) });
597
+ }
@@ -0,0 +1,12 @@
1
+ import type { HTMLAttributes } from 'react';
2
+ export interface SelectLeadingProps extends HTMLAttributes<HTMLSpanElement> {
3
+ }
4
+ /**
5
+ * Leading icon of the field, the same as `TextFieldLeading`: a 48 × 48 area with the 24 px icon
6
+ * centred. Decorative (the field's name comes from `SelectLabel`); a click on it opens the list.
7
+ *
8
+ * ```tsx
9
+ * <SelectLeading><MailIcon /></SelectLeading>
10
+ * ```
11
+ */
12
+ export declare function SelectLeading({ className, ...props }: SelectLeadingProps): import("react").JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Leading icon of the field, the same as `TextFieldLeading`: a 48 × 48 area with the 24 px icon
4
+ * centred. Decorative (the field's name comes from `SelectLabel`); a click on it opens the list.
5
+ *
6
+ * ```tsx
7
+ * <SelectLeading><MailIcon /></SelectLeading>
8
+ * ```
9
+ */
10
+ export function SelectLeading({ className, ...props }) {
11
+ return _jsx("span", { ...props, className: className ? `mk-text-field-leading ${className}` : 'mk-text-field-leading' });
12
+ }