@terreno/ui 57.19.2 → 57.20.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 (295) hide show
  1. package/.ai/guidelines/core.md +1 -1
  2. package/CHANGELOG.md +393 -0
  3. package/dist/Accordion.d.ts.map +1 -1
  4. package/dist/Accordion.js +3 -3
  5. package/dist/Accordion.js.map +1 -1
  6. package/dist/Avatar.d.ts.map +1 -1
  7. package/dist/Avatar.js +3 -1
  8. package/dist/Avatar.js.map +1 -1
  9. package/dist/Box.d.ts.map +1 -1
  10. package/dist/Box.js +38 -2
  11. package/dist/Box.js.map +1 -1
  12. package/dist/Card.js +2 -2
  13. package/dist/Card.js.map +1 -1
  14. package/dist/Common.d.ts +120 -7
  15. package/dist/Common.d.ts.map +1 -1
  16. package/dist/Common.js.map +1 -1
  17. package/dist/ConsentFormScreen.d.ts +1 -1
  18. package/dist/ConsentFormScreen.d.ts.map +1 -1
  19. package/dist/ConsentFormScreen.js +13 -4
  20. package/dist/ConsentFormScreen.js.map +1 -1
  21. package/dist/DateTimeField.d.ts.map +1 -1
  22. package/dist/DateTimeField.js +5 -3
  23. package/dist/DateTimeField.js.map +1 -1
  24. package/dist/Field.d.ts.map +1 -1
  25. package/dist/Field.js +2 -0
  26. package/dist/Field.js.map +1 -1
  27. package/dist/FormContainer.d.ts +68 -0
  28. package/dist/FormContainer.d.ts.map +1 -0
  29. package/dist/FormContainer.js +79 -0
  30. package/dist/FormContainer.js.map +1 -0
  31. package/dist/GPTChat.d.ts.map +1 -1
  32. package/dist/GPTChat.js +2 -1
  33. package/dist/GPTChat.js.map +1 -1
  34. package/dist/Heading.d.ts +1 -1
  35. package/dist/Heading.d.ts.map +1 -1
  36. package/dist/Heading.js +5 -2
  37. package/dist/Heading.js.map +1 -1
  38. package/dist/Icon.d.ts +4 -0
  39. package/dist/Icon.d.ts.map +1 -1
  40. package/dist/Icon.js +43 -2
  41. package/dist/Icon.js.map +1 -1
  42. package/dist/LabeledCheckBox.d.ts +22 -0
  43. package/dist/LabeledCheckBox.d.ts.map +1 -0
  44. package/dist/LabeledCheckBox.js +30 -0
  45. package/dist/LabeledCheckBox.js.map +1 -0
  46. package/dist/ListDetailLayout.d.ts +36 -0
  47. package/dist/ListDetailLayout.d.ts.map +1 -0
  48. package/dist/ListDetailLayout.js +153 -0
  49. package/dist/ListDetailLayout.js.map +1 -0
  50. package/dist/MarkdownEditor.d.ts.map +1 -1
  51. package/dist/MarkdownEditor.js +2 -1
  52. package/dist/MarkdownEditor.js.map +1 -1
  53. package/dist/MediaQuery.d.ts +1 -1
  54. package/dist/MediaQuery.d.ts.map +1 -1
  55. package/dist/MediaQuery.js +1 -1
  56. package/dist/MediaQuery.js.map +1 -1
  57. package/dist/OtpField.d.ts +60 -0
  58. package/dist/OtpField.d.ts.map +1 -0
  59. package/dist/OtpField.js +154 -0
  60. package/dist/OtpField.js.map +1 -0
  61. package/dist/ProvisionalConsentSigner.d.ts +21 -0
  62. package/dist/ProvisionalConsentSigner.d.ts.map +1 -0
  63. package/dist/ProvisionalConsentSigner.js +199 -0
  64. package/dist/ProvisionalConsentSigner.js.map +1 -0
  65. package/dist/ResponsiveBreakpoint.d.ts +5 -0
  66. package/dist/ResponsiveBreakpoint.d.ts.map +1 -1
  67. package/dist/ResponsiveBreakpoint.js +7 -0
  68. package/dist/ResponsiveBreakpoint.js.map +1 -1
  69. package/dist/SocialLoginButton.d.ts +10 -0
  70. package/dist/SocialLoginButton.d.ts.map +1 -1
  71. package/dist/SocialLoginButton.js +26 -8
  72. package/dist/SocialLoginButton.js.map +1 -1
  73. package/dist/SplitPage.d.ts +11 -0
  74. package/dist/SplitPage.d.ts.map +1 -1
  75. package/dist/SplitPage.js +11 -5
  76. package/dist/SplitPage.js.map +1 -1
  77. package/dist/SplitPage.native.d.ts.map +1 -1
  78. package/dist/SplitPage.native.js +3 -1
  79. package/dist/SplitPage.native.js.map +1 -1
  80. package/dist/SyncStatusBanner.d.ts +7 -1
  81. package/dist/SyncStatusBanner.d.ts.map +1 -1
  82. package/dist/SyncStatusBanner.js +20 -4
  83. package/dist/SyncStatusBanner.js.map +1 -1
  84. package/dist/TextField.d.ts.map +1 -1
  85. package/dist/TextField.js +44 -10
  86. package/dist/TextField.js.map +1 -1
  87. package/dist/fieldElements/FieldError.d.ts.map +1 -1
  88. package/dist/fieldElements/FieldError.js +1 -1
  89. package/dist/fieldElements/FieldError.js.map +1 -1
  90. package/dist/index.d.ts +19 -3
  91. package/dist/index.d.ts.map +1 -1
  92. package/dist/index.js +14 -1
  93. package/dist/index.js.map +1 -1
  94. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +3 -0
  95. package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
  96. package/dist/lazyBoundaries/heavyOptionalExports.js +2 -0
  97. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
  98. package/dist/login/LastUsedBadge.d.ts +14 -0
  99. package/dist/login/LastUsedBadge.d.ts.map +1 -0
  100. package/dist/login/LastUsedBadge.js +23 -0
  101. package/dist/login/LastUsedBadge.js.map +1 -0
  102. package/dist/login/LoginAccountCard.d.ts +38 -0
  103. package/dist/login/LoginAccountCard.d.ts.map +1 -0
  104. package/dist/login/LoginAccountCard.js +72 -0
  105. package/dist/login/LoginAccountCard.js.map +1 -0
  106. package/dist/login/LoginAccountList.d.ts +33 -0
  107. package/dist/login/LoginAccountList.d.ts.map +1 -0
  108. package/dist/login/LoginAccountList.js +30 -0
  109. package/dist/login/LoginAccountList.js.map +1 -0
  110. package/dist/login/LoginScreen.d.ts +4 -4
  111. package/dist/login/LoginScreen.d.ts.map +1 -1
  112. package/dist/login/LoginScreen.js +294 -13
  113. package/dist/login/LoginScreen.js.map +1 -1
  114. package/dist/login/OutlinePill.d.ts +28 -0
  115. package/dist/login/OutlinePill.d.ts.map +1 -0
  116. package/dist/login/OutlinePill.js +48 -0
  117. package/dist/login/OutlinePill.js.map +1 -0
  118. package/dist/login/TwoFactorChallengeScreen.d.ts +26 -0
  119. package/dist/login/TwoFactorChallengeScreen.d.ts.map +1 -0
  120. package/dist/login/TwoFactorChallengeScreen.js +139 -0
  121. package/dist/login/TwoFactorChallengeScreen.js.map +1 -0
  122. package/dist/login/loginMethods.d.ts +27 -0
  123. package/dist/login/loginMethods.d.ts.map +1 -0
  124. package/dist/login/loginMethods.js +37 -0
  125. package/dist/login/loginMethods.js.map +1 -0
  126. package/dist/login/loginTypes.d.ts +202 -5
  127. package/dist/login/loginTypes.d.ts.map +1 -1
  128. package/dist/pdfHtmlTemplate.d.ts +17 -0
  129. package/dist/pdfHtmlTemplate.d.ts.map +1 -1
  130. package/dist/pdfHtmlTemplate.js +78 -0
  131. package/dist/pdfHtmlTemplate.js.map +1 -1
  132. package/dist/security/AccountSecurityScreen.d.ts +10 -0
  133. package/dist/security/AccountSecurityScreen.d.ts.map +1 -0
  134. package/dist/security/AccountSecurityScreen.js +50 -0
  135. package/dist/security/AccountSecurityScreen.js.map +1 -0
  136. package/dist/security/LinkedAccountsCard.d.ts +32 -0
  137. package/dist/security/LinkedAccountsCard.d.ts.map +1 -0
  138. package/dist/security/LinkedAccountsCard.js +145 -0
  139. package/dist/security/LinkedAccountsCard.js.map +1 -0
  140. package/dist/security/PasskeysCard.d.ts +39 -0
  141. package/dist/security/PasskeysCard.d.ts.map +1 -0
  142. package/dist/security/PasskeysCard.js +168 -0
  143. package/dist/security/PasskeysCard.js.map +1 -0
  144. package/dist/security/PasswordCard.d.ts +32 -0
  145. package/dist/security/PasswordCard.d.ts.map +1 -0
  146. package/dist/security/PasswordCard.js +198 -0
  147. package/dist/security/PasswordCard.js.map +1 -0
  148. package/dist/security/SessionsCard.d.ts +39 -0
  149. package/dist/security/SessionsCard.d.ts.map +1 -0
  150. package/dist/security/SessionsCard.js +168 -0
  151. package/dist/security/SessionsCard.js.map +1 -0
  152. package/dist/security/TwoFactorSettingsCard.d.ts +55 -0
  153. package/dist/security/TwoFactorSettingsCard.d.ts.map +1 -0
  154. package/dist/security/TwoFactorSettingsCard.js +458 -0
  155. package/dist/security/TwoFactorSettingsCard.js.map +1 -0
  156. package/dist/security/securityMethods.d.ts +40 -0
  157. package/dist/security/securityMethods.d.ts.map +1 -0
  158. package/dist/security/securityMethods.js +66 -0
  159. package/dist/security/securityMethods.js.map +1 -0
  160. package/dist/security/securityTypes.d.ts +467 -0
  161. package/dist/security/securityTypes.d.ts.map +1 -0
  162. package/dist/security/securityTypes.js +2 -0
  163. package/dist/security/securityTypes.js.map +1 -0
  164. package/dist/security/userAgent.d.ts +26 -0
  165. package/dist/security/userAgent.d.ts.map +1 -0
  166. package/dist/security/userAgent.js +80 -0
  167. package/dist/security/userAgent.js.map +1 -0
  168. package/dist/signUp/OAuthButtons.d.ts +28 -5
  169. package/dist/signUp/OAuthButtons.d.ts.map +1 -1
  170. package/dist/signUp/OAuthButtons.js +44 -5
  171. package/dist/signUp/OAuthButtons.js.map +1 -1
  172. package/dist/signUp/SignUpScreen.d.ts.map +1 -1
  173. package/dist/signUp/SignUpScreen.js +50 -5
  174. package/dist/signUp/SignUpScreen.js.map +1 -1
  175. package/dist/signUp/signUpTypes.d.ts +21 -1
  176. package/dist/signUp/signUpTypes.d.ts.map +1 -1
  177. package/dist/useConsentForms.d.ts +9 -0
  178. package/dist/useConsentForms.d.ts.map +1 -1
  179. package/dist/useConsentForms.js +18 -0
  180. package/dist/useConsentForms.js.map +1 -1
  181. package/dist/useProvisionalConsent.d.ts +124 -0
  182. package/dist/useProvisionalConsent.d.ts.map +1 -0
  183. package/dist/useProvisionalConsent.js +79 -0
  184. package/dist/useProvisionalConsent.js.map +1 -0
  185. package/package.json +3 -2
  186. package/src/Accordion.test.tsx +5 -0
  187. package/src/Accordion.tsx +3 -8
  188. package/src/AreaChart.test.tsx +15 -0
  189. package/src/Avatar.test.tsx +8 -0
  190. package/src/Avatar.tsx +2 -0
  191. package/src/BarChart.test.tsx +15 -0
  192. package/src/Box.test.tsx +61 -1
  193. package/src/Box.tsx +44 -2
  194. package/src/Card.tsx +2 -2
  195. package/src/Common.ts +134 -7
  196. package/src/ConsentFormScreen.test.tsx +84 -0
  197. package/src/ConsentFormScreen.tsx +28 -4
  198. package/src/DateTimeField.tsx +5 -3
  199. package/src/DonutChart.test.tsx +15 -0
  200. package/src/Field.tsx +2 -0
  201. package/src/FilePickerButton.test.tsx +35 -0
  202. package/src/FormContainer.test.tsx +242 -0
  203. package/src/FormContainer.tsx +177 -0
  204. package/src/GPTChat.test.tsx +16 -0
  205. package/src/GPTChat.tsx +8 -2
  206. package/src/Heading.test.tsx +14 -0
  207. package/src/Heading.tsx +6 -1
  208. package/src/Icon.test.tsx +52 -1
  209. package/src/Icon.tsx +92 -3
  210. package/src/IconButton.test.tsx +85 -0
  211. package/src/LabeledCheckBox.test.tsx +45 -0
  212. package/src/LabeledCheckBox.tsx +89 -0
  213. package/src/ListDetailLayout.tsx +247 -0
  214. package/src/MarkdownEditor.tsx +2 -1
  215. package/src/MediaQuery.ts +1 -0
  216. package/src/OtpField.test.tsx +280 -0
  217. package/src/OtpField.tsx +307 -0
  218. package/src/ProvisionalConsentSigner.test.tsx +625 -0
  219. package/src/ProvisionalConsentSigner.tsx +423 -0
  220. package/src/ResponsiveBreakpoint.test.tsx +7 -0
  221. package/src/ResponsiveBreakpoint.tsx +14 -0
  222. package/src/RootImportRegression.test.tsx +3 -0
  223. package/src/SocialLoginButton.test.tsx +14 -0
  224. package/src/SocialLoginButton.tsx +51 -7
  225. package/src/SplitPage.native.tsx +3 -1
  226. package/src/SplitPage.tsx +11 -5
  227. package/src/SyncStatusBanner.test.tsx +61 -4
  228. package/src/SyncStatusBanner.tsx +29 -3
  229. package/src/TextField.test.tsx +150 -0
  230. package/src/TextField.tsx +66 -8
  231. package/src/__snapshots__/AddressField.test.tsx.snap +12 -0
  232. package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +15 -0
  233. package/src/__snapshots__/Avatar.test.tsx.snap +1 -0
  234. package/src/__snapshots__/CustomSelectField.test.tsx.snap +3 -0
  235. package/src/__snapshots__/EmailField.test.tsx.snap +6 -0
  236. package/src/__snapshots__/Field.test.tsx.snap +37 -0
  237. package/src/__snapshots__/HeightField.test.tsx.snap +2 -0
  238. package/src/__snapshots__/MobileAddressAutoComplete.test.tsx.snap +3 -0
  239. package/src/__snapshots__/NumberField.test.tsx.snap +3 -0
  240. package/src/__snapshots__/PhoneNumberField.test.tsx.snap +12 -0
  241. package/src/__snapshots__/Slider.test.tsx.snap +1 -0
  242. package/src/__snapshots__/SocialLoginButton.test.tsx.snap +43 -22
  243. package/src/__snapshots__/TapToEdit.test.tsx.snap +3 -0
  244. package/src/__snapshots__/TextArea.test.tsx.snap +17 -1
  245. package/src/__snapshots__/TextField.test.tsx.snap +19 -2
  246. package/src/__snapshots__/TypedSignatureField.test.tsx.snap +3 -0
  247. package/src/__snapshots__/UnifiedAddressAutoComplete.test.tsx.snap +18 -0
  248. package/src/__snapshots__/WebAddressAutocomplete.test.tsx.snap +12 -0
  249. package/src/bunSetup.ts +13 -1
  250. package/src/fieldElements/FieldError.tsx +1 -0
  251. package/src/fieldElements/__snapshots__/FieldError.test.tsx.snap +2 -0
  252. package/src/index.tsx +42 -1
  253. package/src/isolated/ListDetailLayout.isolated.tsx +634 -0
  254. package/src/lazyBoundaries/heavyOptionalExports.tsx +7 -0
  255. package/src/login/LastUsedBadge.tsx +40 -0
  256. package/src/login/LoginAccountCard.tsx +205 -0
  257. package/src/login/LoginAccountList.tsx +115 -0
  258. package/src/login/LoginScreen.test.tsx +837 -1
  259. package/src/login/LoginScreen.tsx +674 -91
  260. package/src/login/OutlinePill.tsx +110 -0
  261. package/src/login/TwoFactorChallengeScreen.test.tsx +376 -0
  262. package/src/login/TwoFactorChallengeScreen.tsx +307 -0
  263. package/src/login/__snapshots__/LoginScreen.test.tsx.snap +1454 -334
  264. package/src/login/loginMethods.test.ts +53 -0
  265. package/src/login/loginMethods.ts +60 -0
  266. package/src/login/loginTypes.ts +208 -5
  267. package/src/pdfHtmlTemplate.test.ts +243 -4
  268. package/src/pdfHtmlTemplate.ts +93 -0
  269. package/src/security/AccountSecurityScreen.test.tsx +262 -0
  270. package/src/security/AccountSecurityScreen.tsx +156 -0
  271. package/src/security/LinkedAccountsCard.test.tsx +371 -0
  272. package/src/security/LinkedAccountsCard.tsx +297 -0
  273. package/src/security/PasskeysCard.test.tsx +378 -0
  274. package/src/security/PasskeysCard.tsx +371 -0
  275. package/src/security/PasswordCard.test.tsx +445 -0
  276. package/src/security/PasswordCard.tsx +342 -0
  277. package/src/security/SessionsCard.test.tsx +349 -0
  278. package/src/security/SessionsCard.tsx +362 -0
  279. package/src/security/TwoFactorSettingsCard.test.tsx +700 -0
  280. package/src/security/TwoFactorSettingsCard.tsx +872 -0
  281. package/src/security/securityMethods.test.ts +101 -0
  282. package/src/security/securityMethods.ts +104 -0
  283. package/src/security/securityTypes.ts +480 -0
  284. package/src/security/userAgent.test.ts +119 -0
  285. package/src/security/userAgent.ts +102 -0
  286. package/src/signUp/OAuthButtons.test.tsx +27 -0
  287. package/src/signUp/OAuthButtons.tsx +153 -19
  288. package/src/signUp/SignUpScreen.test.tsx +170 -1
  289. package/src/signUp/SignUpScreen.tsx +87 -25
  290. package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +22 -11
  291. package/src/signUp/signUpTypes.ts +23 -1
  292. package/src/useConsentForms.test.ts +37 -1
  293. package/src/useConsentForms.ts +25 -0
  294. package/src/useProvisionalConsent.test.ts +256 -0
  295. package/src/useProvisionalConsent.ts +218 -0
package/src/Field.tsx CHANGED
@@ -90,6 +90,8 @@ export const Field: FC<FieldProps> = ({type, ...rest}) => {
90
90
  }
91
91
  }
92
92
 
93
+ // Defaults only: a password field that sets a new password passes autoComplete="new-password",
94
+ // which the spread below applies.
93
95
  return (
94
96
  <TextField
95
97
  autoComplete={autoComplete}
@@ -271,4 +271,39 @@ describe("FilePickerButton", () => {
271
271
  globals.FileReader = originalFileReader;
272
272
  }
273
273
  });
274
+
275
+ it("resolves an empty selection when the browser file dialog is cancelled", async () => {
276
+ const listeners: Record<string, () => void> = {};
277
+ const input = {
278
+ accept: "",
279
+ addEventListener: (event: string, handler: () => void): void => {
280
+ listeners[event] = handler;
281
+ },
282
+ click: mock(() => {}),
283
+ files: [],
284
+ multiple: false,
285
+ remove: mock(() => {}),
286
+ style: {display: ""},
287
+ type: "",
288
+ };
289
+ const globals = globalThis as unknown as Record<string, unknown>;
290
+ const originalDocument = globals.document;
291
+ const originalOS = Platform.OS;
292
+ const {files, getByText} = openModal();
293
+ globals.document = {
294
+ body: {appendChild: mock(() => {})},
295
+ createElement: (): typeof input => input,
296
+ };
297
+ Platform.OS = "web";
298
+ try {
299
+ fireEvent.press(getByText("Document"));
300
+ listeners.cancel?.();
301
+ expect(input.remove).toHaveBeenCalledTimes(1);
302
+ expect(files).toHaveLength(0);
303
+ expect(getDocumentAsync).not.toHaveBeenCalled();
304
+ } finally {
305
+ Platform.OS = originalOS;
306
+ globals.document = originalDocument;
307
+ }
308
+ });
274
309
  });
@@ -0,0 +1,242 @@
1
+ import {afterEach, beforeEach, describe, expect, it, mock, spyOn} from "bun:test";
2
+ import {act, fireEvent, render} from "@testing-library/react-native";
3
+ import {createRef} from "react";
4
+ import {Platform, Text} from "react-native";
5
+
6
+ import {FormContainer, type FormContainerHandle} from "./FormContainer";
7
+ import {ThemeProvider} from "./Theme";
8
+ import {renderWithTheme} from "./test-utils";
9
+
10
+ const setOS = (os: string): string => {
11
+ const original = Platform.OS;
12
+ Object.defineProperty(Platform, "OS", {configurable: true, value: os});
13
+ return original;
14
+ };
15
+
16
+ describe("FormContainer", () => {
17
+ describe("native", () => {
18
+ it("renders its children in a Box, with no form element", () => {
19
+ const {getByTestId, getByText, UNSAFE_queryAllByType} = renderWithTheme(
20
+ <FormContainer gap={2} testID="sign-in-form">
21
+ <Text>Child</Text>
22
+ </FormContainer>
23
+ );
24
+ expect(getByTestId("sign-in-form")).toBeTruthy();
25
+ expect(getByText("Child")).toBeTruthy();
26
+ expect(UNSAFE_queryAllByType("form" as never)).toHaveLength(0);
27
+ });
28
+
29
+ it("renders no hidden username input", () => {
30
+ const {UNSAFE_queryAllByType} = renderWithTheme(
31
+ <FormContainer username="ada@example.com">
32
+ <Text>Child</Text>
33
+ </FormContainer>
34
+ );
35
+ expect(UNSAFE_queryAllByType("input" as never)).toHaveLength(0);
36
+ });
37
+
38
+ it("calls onSubmit when requestSubmit is called", async () => {
39
+ const onSubmit = mock(() => {});
40
+ const ref = createRef<FormContainerHandle>();
41
+ renderWithTheme(
42
+ <FormContainer onSubmit={onSubmit} ref={ref} testID="sign-in-form">
43
+ <Text>Child</Text>
44
+ </FormContainer>
45
+ );
46
+ await act(async () => {
47
+ await ref.current?.requestSubmit();
48
+ });
49
+ expect(onSubmit).toHaveBeenCalledTimes(1);
50
+ });
51
+
52
+ it("does nothing on requestSubmit without onSubmit", async () => {
53
+ const ref = createRef<FormContainerHandle>();
54
+ renderWithTheme(
55
+ <FormContainer ref={ref}>
56
+ <Text>Child</Text>
57
+ </FormContainer>
58
+ );
59
+ await expect(ref.current?.requestSubmit()).resolves.toBeUndefined();
60
+ });
61
+ });
62
+
63
+ describe("web", () => {
64
+ let originalOS: string;
65
+
66
+ beforeEach(() => {
67
+ originalOS = setOS("web");
68
+ });
69
+
70
+ afterEach(() => {
71
+ setOS(originalOS);
72
+ });
73
+
74
+ it("renders a real form that skips browser validation and does not take part in layout", () => {
75
+ const {UNSAFE_getByType, getByText} = renderWithTheme(
76
+ <FormContainer accessibilityLabel="Sign in" gap={4} testID="sign-in-form">
77
+ <Text>Child</Text>
78
+ </FormContainer>
79
+ );
80
+ const form = UNSAFE_getByType("form" as never);
81
+ expect(form.props.noValidate).toBe(true);
82
+ expect(form.props["data-testid"]).toBe("sign-in-form");
83
+ expect(form.props["aria-label"]).toBe("Sign in");
84
+ expect(form.props.style).toEqual({display: "contents"});
85
+ expect(getByText("Child")).toBeTruthy();
86
+ });
87
+
88
+ it("adds a hidden username input so password managers know whose password changes", () => {
89
+ const {UNSAFE_getByType} = renderWithTheme(
90
+ <FormContainer testID="password-form" username="ada@example.com">
91
+ <Text>Child</Text>
92
+ </FormContainer>
93
+ );
94
+ const input = UNSAFE_getByType("input" as never);
95
+ expect(input.props.autoComplete).toBe("username");
96
+ expect(input.props.value).toBe("ada@example.com");
97
+ expect(input.props.hidden).toBe(true);
98
+ expect(input.props.readOnly).toBe(true);
99
+ expect(input.props.tabIndex).toBe(-1);
100
+ expect(input.props["data-testid"]).toBe("password-form-username");
101
+ });
102
+
103
+ it("leaves out the hidden username input without a username", () => {
104
+ const {UNSAFE_queryAllByType} = renderWithTheme(
105
+ <FormContainer>
106
+ <Text>Child</Text>
107
+ </FormContainer>
108
+ );
109
+ expect(UNSAFE_queryAllByType("input" as never)).toHaveLength(0);
110
+ });
111
+
112
+ it("prevents the page reload and calls onSubmit on a submit event", () => {
113
+ const onSubmit = mock(() => {});
114
+ const preventDefault = mock(() => {});
115
+ const {UNSAFE_getByType} = renderWithTheme(
116
+ <FormContainer onSubmit={onSubmit}>
117
+ <Text>Child</Text>
118
+ </FormContainer>
119
+ );
120
+ fireEvent(UNSAFE_getByType("form" as never), "submit", {preventDefault});
121
+ expect(preventDefault).toHaveBeenCalledTimes(1);
122
+ expect(onSubmit).toHaveBeenCalledTimes(1);
123
+ });
124
+
125
+ it("prevents the page reload even without onSubmit", () => {
126
+ const preventDefault = mock(() => {});
127
+ const {UNSAFE_getByType} = renderWithTheme(
128
+ <FormContainer>
129
+ <Text>Child</Text>
130
+ </FormContainer>
131
+ );
132
+ fireEvent(UNSAFE_getByType("form" as never), "submit", {preventDefault});
133
+ expect(preventDefault).toHaveBeenCalledTimes(1);
134
+ });
135
+
136
+ it("routes requestSubmit through the form element so password managers see a submit", async () => {
137
+ const onSubmit = mock(() => {});
138
+ const requestSubmit = mock(() => {});
139
+ const ref = createRef<FormContainerHandle>();
140
+ render(
141
+ <FormContainer onSubmit={onSubmit} ref={ref}>
142
+ <Text>Child</Text>
143
+ </FormContainer>,
144
+ {
145
+ createNodeMock: (element) => (element.type === "form" ? {requestSubmit} : null),
146
+ wrapper: ThemeProvider,
147
+ }
148
+ );
149
+ await act(async () => {
150
+ await ref.current?.requestSubmit();
151
+ });
152
+ expect(requestSubmit).toHaveBeenCalledTimes(1);
153
+ // The browser fires the submit event, which calls onSubmit; requestSubmit does not.
154
+ expect(onSubmit).not.toHaveBeenCalled();
155
+ });
156
+
157
+ it("resolves requestSubmit after the browser-run onSubmit settles", async () => {
158
+ let resolveSubmit: () => void = () => {};
159
+ const onSubmit = mock(
160
+ () =>
161
+ new Promise<void>((resolve) => {
162
+ resolveSubmit = resolve;
163
+ })
164
+ );
165
+ const ref = createRef<FormContainerHandle>();
166
+ const {UNSAFE_getByType} = render(
167
+ <FormContainer onSubmit={onSubmit} ref={ref}>
168
+ <Text>Child</Text>
169
+ </FormContainer>,
170
+ {
171
+ createNodeMock: (element) =>
172
+ element.type === "form"
173
+ ? {
174
+ requestSubmit: (): void => {
175
+ fireEvent(UNSAFE_getByType("form" as never), "submit", {
176
+ preventDefault: () => {},
177
+ });
178
+ },
179
+ }
180
+ : null,
181
+ wrapper: ThemeProvider,
182
+ }
183
+ );
184
+ let isSettled = false;
185
+ const pending = ref.current?.requestSubmit().then(() => {
186
+ isSettled = true;
187
+ });
188
+ await Promise.resolve();
189
+ expect(onSubmit).toHaveBeenCalledTimes(1);
190
+ expect(isSettled).toBe(false);
191
+ resolveSubmit();
192
+ await pending;
193
+ expect(isSettled).toBe(true);
194
+ });
195
+
196
+ it("warns instead of leaving a rejection unhandled on a browser-started submit", async () => {
197
+ const warn = spyOn(console, "warn").mockImplementation(() => {});
198
+ const {UNSAFE_getByType} = renderWithTheme(
199
+ <FormContainer onSubmit={() => Promise.reject(new Error("nope"))}>
200
+ <Text>Child</Text>
201
+ </FormContainer>
202
+ );
203
+ fireEvent(UNSAFE_getByType("form" as never), "submit", {preventDefault: () => {}});
204
+ await new Promise((resolve) => setTimeout(resolve, 0));
205
+ expect(warn).toHaveBeenCalledWith("FormContainer: onSubmit rejected", expect.any(Error));
206
+ warn.mockRestore();
207
+ });
208
+
209
+ it("renders a nested FormContainer as a Box, since HTML forms cannot nest", async () => {
210
+ const onInnerSubmit = mock(() => {});
211
+ const innerRef = createRef<FormContainerHandle>();
212
+ const {UNSAFE_queryAllByType, getByTestId} = renderWithTheme(
213
+ <FormContainer testID="outer">
214
+ <FormContainer onSubmit={onInnerSubmit} ref={innerRef} testID="inner">
215
+ <Text>Child</Text>
216
+ </FormContainer>
217
+ </FormContainer>
218
+ );
219
+ expect(UNSAFE_queryAllByType("form" as never)).toHaveLength(1);
220
+ expect(getByTestId("inner")).toBeTruthy();
221
+ await act(async () => {
222
+ await innerRef.current?.requestSubmit();
223
+ });
224
+ expect(onInnerSubmit).toHaveBeenCalledTimes(1);
225
+ });
226
+
227
+ it("calls onSubmit directly when the browser has no requestSubmit", async () => {
228
+ const onSubmit = mock(() => {});
229
+ const ref = createRef<FormContainerHandle>();
230
+ render(
231
+ <FormContainer onSubmit={onSubmit} ref={ref}>
232
+ <Text>Child</Text>
233
+ </FormContainer>,
234
+ {createNodeMock: () => ({}), wrapper: ThemeProvider}
235
+ );
236
+ await act(async () => {
237
+ await ref.current?.requestSubmit();
238
+ });
239
+ expect(onSubmit).toHaveBeenCalledTimes(1);
240
+ });
241
+ });
242
+ });
@@ -0,0 +1,177 @@
1
+ import type {FC, Ref} from "react";
2
+ import {createContext, useCallback, useContext, useImperativeHandle, useRef} from "react";
3
+ import {Platform} from "react-native";
4
+
5
+ import {Box} from "./Box";
6
+ import type {BoxPropsBase} from "./Common";
7
+
8
+ /**
9
+ * Imperative handle for {@link FormContainer}, passed through its `ref` prop.
10
+ */
11
+ export interface FormContainerHandle {
12
+ /**
13
+ * Submits the form. On web it calls the form element's `requestSubmit()`, so the browser fires a
14
+ * real submit event (password managers watch for it to offer "Save password") and the form's
15
+ * submit handler calls `onSubmit`. On native, and in browsers without `requestSubmit`, it calls
16
+ * `onSubmit` directly. Resolves when `onSubmit` settles, so a button awaiting it shows its
17
+ * loading state.
18
+ */
19
+ requestSubmit: () => Promise<void>;
20
+ }
21
+
22
+ /**
23
+ * Props for {@link FormContainer}. Layout props are the same as {@link Box}'s.
24
+ */
25
+ export interface FormContainerProps
26
+ extends Omit<BoxPropsBase, "onClick" | "onHoverStart" | "onHoverEnd" | "scroll"> {
27
+ /**
28
+ * Called when the form is submitted: from `ref.requestSubmit()`, or on web when the browser
29
+ * submits the form. The browser's page reload is always prevented.
30
+ */
31
+ onSubmit?: () => void | Promise<void>;
32
+ /** Names the form for screen readers (on web the form then becomes a "form" landmark). */
33
+ accessibilityLabel?: string;
34
+ /**
35
+ * The signed-in user's username or email, for forms without a username field such as a change
36
+ * password form. On web it goes in a hidden `autocomplete="username"` input, so password managers
37
+ * update that account's saved password. Ignored on native.
38
+ */
39
+ username?: string;
40
+ /** Receives {@link FormContainerHandle}, to submit the form from a field's Enter key or a button. */
41
+ ref?: Ref<FormContainerHandle>;
42
+ }
43
+
44
+ /** True inside a FormContainer's <form>; HTML does not allow a form inside another form. */
45
+ const InsideFormContext = createContext(false);
46
+
47
+ /** The DOM form element's submit method; absent in Safari before 16. */
48
+ interface WebFormElement {
49
+ requestSubmit?: () => void;
50
+ }
51
+
52
+ /**
53
+ * Groups a form's fields. On web it renders a real `<form>` around them, so browsers and password
54
+ * managers can pair a username with its password, autofill saved credentials, and offer to save
55
+ * new ones (Chrome warns "Password field is not contained in a form" without it). The form uses
56
+ * `display: contents`, so the children lay out exactly as in the inner {@link Box}, which takes all
57
+ * of Box's layout props. On native it renders just the Box.
58
+ *
59
+ * The form sets `noValidate` and always prevents the browser's page reload. Fields keep their own
60
+ * Enter handling: `TextField` calls `onEnter` and stops the browser's implicit submission, so call
61
+ * `ref.requestSubmit()` from the last field's `onEnter` and from the submit button. A FormContainer
62
+ * inside another one renders a Box (HTML forms cannot nest); its `requestSubmit` calls its own
63
+ * `onSubmit`.
64
+ *
65
+ * @example
66
+ * ```tsx
67
+ * const formRef = useRef<FormContainerHandle>(null);
68
+ *
69
+ * <FormContainer gap={4} onSubmit={signIn} ref={formRef}>
70
+ * <TextField autoComplete="username" onChange={setEmail} title="Email" type="email" value={email} />
71
+ * <TextField
72
+ * autoComplete="current-password"
73
+ * onChange={setPassword}
74
+ * onEnter={() => formRef.current?.requestSubmit()}
75
+ * title="Password"
76
+ * type="password"
77
+ * value={password}
78
+ * />
79
+ * <Button onClick={() => formRef.current?.requestSubmit()} text="Log In" />
80
+ * </FormContainer>
81
+ * ```
82
+ */
83
+ export const FormContainer: FC<FormContainerProps> = ({
84
+ onSubmit,
85
+ accessibilityLabel,
86
+ username,
87
+ ref,
88
+ testID,
89
+ children,
90
+ ...boxProps
91
+ }) => {
92
+ const isInsideForm = useContext(InsideFormContext);
93
+ const formElementRef = useRef<WebFormElement | null>(null);
94
+ // A ref keeps requestSubmit stable while still calling the latest onSubmit.
95
+ const onSubmitRef = useRef(onSubmit);
96
+ onSubmitRef.current = onSubmit;
97
+
98
+ // The browser runs the submit handler inside requestSubmit(); this carries its result back out.
99
+ const pendingSubmitRef = useRef<Promise<void> | undefined>(undefined);
100
+
101
+ const handleFormSubmit = useCallback((event: {preventDefault: () => void}): void => {
102
+ event.preventDefault();
103
+ const result = Promise.resolve(onSubmitRef.current?.());
104
+ pendingSubmitRef.current = result;
105
+ // A submit the browser starts on its own has no caller to report a rejection to.
106
+ result.catch((error: unknown) => {
107
+ console.warn("FormContainer: onSubmit rejected", error);
108
+ });
109
+ }, []);
110
+
111
+ useImperativeHandle(
112
+ ref,
113
+ (): FormContainerHandle => ({
114
+ requestSubmit: async (): Promise<void> => {
115
+ const form = formElementRef.current;
116
+ if (Platform.OS === "web" && typeof form?.requestSubmit === "function") {
117
+ pendingSubmitRef.current = undefined;
118
+ form.requestSubmit();
119
+ await pendingSubmitRef.current;
120
+ return;
121
+ }
122
+ await onSubmitRef.current?.();
123
+ },
124
+ }),
125
+ []
126
+ );
127
+
128
+ if (Platform.OS !== "web") {
129
+ return (
130
+ <Box {...boxProps} testID={testID}>
131
+ {children}
132
+ </Box>
133
+ );
134
+ }
135
+
136
+ const usernameInput = Boolean(username) && (
137
+ <input
138
+ aria-hidden
139
+ autoComplete="username"
140
+ data-testid={testID ? `${testID}-username` : undefined}
141
+ hidden
142
+ name="username"
143
+ readOnly
144
+ tabIndex={-1}
145
+ type="text"
146
+ value={username}
147
+ />
148
+ );
149
+
150
+ // Nested in another FormContainer, the outer <form> already groups these fields.
151
+ if (isInsideForm) {
152
+ return (
153
+ <Box {...boxProps} testID={testID}>
154
+ {usernameInput}
155
+ {children}
156
+ </Box>
157
+ );
158
+ }
159
+
160
+ return (
161
+ <form
162
+ aria-label={accessibilityLabel}
163
+ data-testid={testID}
164
+ noValidate
165
+ onSubmit={handleFormSubmit}
166
+ ref={(element: WebFormElement | null): void => {
167
+ formElementRef.current = element;
168
+ }}
169
+ style={{display: "contents"}}
170
+ >
171
+ {usernameInput}
172
+ <InsideFormContext.Provider value>
173
+ <Box {...boxProps}>{children}</Box>
174
+ </InsideFormContext.Provider>
175
+ </form>
176
+ );
177
+ };
@@ -254,6 +254,22 @@ describe("GPTChat", () => {
254
254
  assert.deepEqual(onGeminiApiKeyChange.mock.calls, [["new-key"]]);
255
255
  });
256
256
 
257
+ it("saves the Gemini API key on Enter and labels the key field", async () => {
258
+ const onGeminiApiKeyChange = mock((_key: string) => {});
259
+ const {getByTestId} = renderChat({onGeminiApiKeyChange});
260
+
261
+ await press(getByTestId("gpt-api-key-button"));
262
+ const input = getByTestId("gpt-api-key-input");
263
+ assert.equal(input.props["aria-label"], "Gemini API key");
264
+ assert.equal(input.props.autoComplete, "off");
265
+ fireEvent.changeText(input, "new-key");
266
+ await act(async () => {
267
+ fireEvent(getByTestId("gpt-api-key-input"), "submitEditing");
268
+ });
269
+
270
+ assert.deepEqual(onGeminiApiKeyChange.mock.calls, [["new-key"]]);
271
+ });
272
+
257
273
  it("dismisses the API key modal without saving", async () => {
258
274
  const onGeminiApiKeyChange = mock((_key: string) => {});
259
275
  const {getByTestId, getByText} = renderChat({onGeminiApiKeyChange});
package/src/GPTChat.tsx CHANGED
@@ -31,6 +31,7 @@ import {DropdownMenuItem} from "./DropdownMenuItem";
31
31
  import {DropdownPanel} from "./DropdownPanel";
32
32
  import type {SelectedFile} from "./FilePickerButton";
33
33
  import {FilePickerButton} from "./FilePickerButton";
34
+ import {FormContainer} from "./FormContainer";
34
35
  import {Heading} from "./Heading";
35
36
  import {Icon} from "./Icon";
36
37
  import {IconButton} from "./IconButton";
@@ -1383,15 +1384,20 @@ const ApiKeyModal = ({
1383
1384
  title="Gemini API Key"
1384
1385
  visible={isVisible}
1385
1386
  >
1386
- <Box padding={2}>
1387
+ {/* A form keeps the browser from warning about a password field outside one. */}
1388
+ <FormContainer onSubmit={handleSaveApiKey} padding={2}>
1387
1389
  <TextField
1390
+ accessibilityLabel="Gemini API key"
1391
+ autoComplete="off"
1388
1392
  onChange={setApiKeyDraft}
1393
+ onEnter={handleSaveApiKey}
1389
1394
  placeholder="Enter Gemini API key..."
1395
+ returnKeyType="done"
1390
1396
  testID="gpt-api-key-input"
1391
1397
  type="password"
1392
1398
  value={apiKeyDraft}
1393
1399
  />
1394
- </Box>
1400
+ </FormContainer>
1395
1401
  </Modal>
1396
1402
  );
1397
1403
  };
@@ -63,4 +63,18 @@ describe("Heading", () => {
63
63
  const {getByTestId} = renderWithTheme(<Heading testID="test-heading">Test</Heading>);
64
64
  expect(getByTestId("test-heading")).toBeTruthy();
65
65
  });
66
+
67
+ it("is plain text without a level", () => {
68
+ const {getByText} = renderWithTheme(<Heading>Plain</Heading>);
69
+ const heading = getByText("Plain");
70
+ expect(heading.props.role).toBeUndefined();
71
+ expect(heading.props["aria-level"]).toBeUndefined();
72
+ });
73
+
74
+ it("exposes a heading role and level when level is set", () => {
75
+ const {getByRole} = renderWithTheme(<Heading level={2}>Section</Heading>);
76
+ const heading = getByRole("heading", {name: "Section"});
77
+ expect(heading.props.role).toBe("heading");
78
+ expect(heading.props["aria-level"]).toBe(2);
79
+ });
66
80
  });
package/src/Heading.tsx CHANGED
@@ -27,6 +27,7 @@ const HeadingComponent = ({
27
27
  align,
28
28
  children,
29
29
  color = "primary",
30
+ level,
30
31
  size,
31
32
  testID,
32
33
  }: HeadingProps): React.ReactElement => {
@@ -47,9 +48,13 @@ const HeadingComponent = ({
47
48
  }
48
49
  style.color = theme.text[color];
49
50
 
51
+ // react-native-web turns role="heading" plus aria-level into <h1>-<h6>; native maps the role
52
+ // to the header accessibility role. RN's TextProps don't declare aria-level, hence the spread.
53
+ const headingProps = level === undefined ? {} : {"aria-level": level, role: "heading" as const};
54
+
50
55
  const lines = 0;
51
56
  return (
52
- <NativeText numberOfLines={lines} style={style} testID={testID}>
57
+ <NativeText numberOfLines={lines} style={style} testID={testID} {...headingProps}>
53
58
  {children}
54
59
  </NativeText>
55
60
  );
package/src/Icon.test.tsx CHANGED
@@ -1,6 +1,7 @@
1
1
  import {describe, expect, it} from "bun:test";
2
+ import {Platform} from "react-native";
2
3
 
3
- import {Icon} from "./Icon";
4
+ import {Icon, iconPlaceholderCommitsForTests, resetIconStaticHydrationForTests} from "./Icon";
4
5
  import {renderWithIcons, renderWithTheme, TEST_CUSTOM_ICON_TEST_ID} from "./test-utils";
5
6
 
6
7
  describe("Icon", () => {
@@ -80,4 +81,54 @@ describe("Icon", () => {
80
81
  expect(queryByTestId("my-icon")).not.toBeNull();
81
82
  });
82
83
  });
84
+
85
+ it("paints the sized placeholder only on the first static hydration commit", () => {
86
+ const originalOS = Platform.OS;
87
+ const globalHydrate = globalThis as {__EXPO_ROUTER_HYDRATE__?: boolean; document?: object};
88
+ const previousHydrate = globalHydrate.__EXPO_ROUTER_HYDRATE__;
89
+ const previousDocument = globalHydrate.document;
90
+ Platform.OS = "web";
91
+ globalHydrate.document = previousDocument ?? {};
92
+ globalHydrate.__EXPO_ROUTER_HYDRATE__ = true;
93
+ resetIconStaticHydrationForTests();
94
+ try {
95
+ renderWithTheme(<Icon iconName="check" testID="during-hydrate" />);
96
+ const firstPassCommits = iconPlaceholderCommitsForTests();
97
+ expect(firstPassCommits).toBeGreaterThan(0);
98
+
99
+ renderWithTheme(<Icon iconName="check" testID="after-hydrate" />);
100
+ expect(iconPlaceholderCommitsForTests()).toBe(firstPassCommits);
101
+
102
+ resetIconStaticHydrationForTests();
103
+ globalHydrate.__EXPO_ROUTER_HYDRATE__ = false;
104
+ renderWithTheme(<Icon iconName="check" testID="client-web" />);
105
+ expect(iconPlaceholderCommitsForTests()).toBe(0);
106
+ } finally {
107
+ Platform.OS = originalOS;
108
+ if (previousHydrate === undefined) {
109
+ delete globalHydrate.__EXPO_ROUTER_HYDRATE__;
110
+ } else {
111
+ globalHydrate.__EXPO_ROUTER_HYDRATE__ = previousHydrate;
112
+ }
113
+ if (previousDocument === undefined) {
114
+ delete globalHydrate.document;
115
+ } else {
116
+ globalHydrate.document = previousDocument;
117
+ }
118
+ resetIconStaticHydrationForTests();
119
+ }
120
+ });
121
+
122
+ it("paints Font Awesome on the first native commit", () => {
123
+ const originalOS = Platform.OS;
124
+ Platform.OS = "ios";
125
+ resetIconStaticHydrationForTests();
126
+ try {
127
+ renderWithTheme(<Icon iconName="check" testID="native-glyph" />);
128
+ expect(iconPlaceholderCommitsForTests()).toBe(0);
129
+ } finally {
130
+ Platform.OS = originalOS;
131
+ resetIconStaticHydrationForTests();
132
+ }
133
+ });
83
134
  });