@workos-inc/widgets 1.20.2-next.1792700156145 → 1.20.2

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 (202) hide show
  1. package/CHANGELOG.md +4 -10
  2. package/dist/cjs/admin-portal-audit-log-streaming.client.cjs +2 -1
  3. package/dist/cjs/admin-portal-audit-log-streaming.client.cjs.map +1 -1
  4. package/dist/cjs/admin-portal-domain-verification.client.cjs +3 -2
  5. package/dist/cjs/admin-portal-domain-verification.client.cjs.map +1 -1
  6. package/dist/cjs/admin-portal-sso-connection.client.cjs +2 -1
  7. package/dist/cjs/admin-portal-sso-connection.client.cjs.map +1 -1
  8. package/dist/cjs/api/api-provider.cjs +23 -1
  9. package/dist/cjs/api/api-provider.cjs.map +1 -1
  10. package/dist/cjs/api/api-provider.d.cts.map +1 -1
  11. package/dist/cjs/api/claims.cjs.map +1 -1
  12. package/dist/cjs/api/claims.d.cts +2 -1
  13. package/dist/cjs/api/claims.d.cts.map +1 -1
  14. package/dist/cjs/api/client-graphql/client.cjs +3 -2
  15. package/dist/cjs/api/client-graphql/client.cjs.map +1 -1
  16. package/dist/cjs/api/client-graphql/hooks.cjs +3 -20
  17. package/dist/cjs/api/client-graphql/hooks.cjs.map +1 -1
  18. package/dist/cjs/api/client-graphql/hooks.d.cts +3 -12
  19. package/dist/cjs/api/client-graphql/hooks.d.cts.map +1 -1
  20. package/dist/cjs/api/client-graphql/query-keys.cjs +25 -0
  21. package/dist/cjs/api/client-graphql/query-keys.cjs.map +1 -0
  22. package/dist/cjs/api/client-graphql/query-keys.d.cts +16 -0
  23. package/dist/cjs/api/client-graphql/query-keys.d.cts.map +1 -0
  24. package/dist/cjs/components/copy-text.cjs +1 -1
  25. package/dist/cjs/components/copy-text.cjs.map +1 -1
  26. package/dist/cjs/components/form.cjs +9 -13
  27. package/dist/cjs/components/form.cjs.map +1 -1
  28. package/dist/cjs/components/form.d.cts.map +1 -1
  29. package/dist/cjs/components/otp-input.cjs +1 -0
  30. package/dist/cjs/components/otp-input.cjs.map +1 -1
  31. package/dist/cjs/directory-sync.client.cjs +2 -1
  32. package/dist/cjs/directory-sync.client.cjs.map +1 -1
  33. package/dist/cjs/lib/api/api-key.cjs +4 -3
  34. package/dist/cjs/lib/api/api-key.cjs.map +1 -1
  35. package/dist/cjs/lib/api/me.cjs +2 -1
  36. package/dist/cjs/lib/api/me.cjs.map +1 -1
  37. package/dist/cjs/lib/api/pipes.cjs +7 -6
  38. package/dist/cjs/lib/api/pipes.cjs.map +1 -1
  39. package/dist/cjs/lib/api/user-api-key.cjs +3 -2
  40. package/dist/cjs/lib/api/user-api-key.cjs.map +1 -1
  41. package/dist/cjs/lib/i18n/intl-context.cjs.map +1 -1
  42. package/dist/cjs/lib/i18n/intl-context.d.cts +1 -0
  43. package/dist/cjs/lib/i18n/intl-context.d.cts.map +1 -1
  44. package/dist/cjs/lib/i18n/use-translation.cjs +2 -2
  45. package/dist/cjs/lib/i18n/use-translation.cjs.map +1 -1
  46. package/dist/cjs/lib/use-composed-event-handlers.cjs +15 -0
  47. package/dist/cjs/lib/use-composed-event-handlers.cjs.map +1 -0
  48. package/dist/cjs/lib/use-composed-event-handlers.d.cts +6 -0
  49. package/dist/cjs/lib/use-composed-event-handlers.d.cts.map +1 -0
  50. package/dist/cjs/lib/use-debounce.cjs +124 -116
  51. package/dist/cjs/lib/use-debounce.cjs.map +1 -1
  52. package/dist/cjs/lib/use-debounce.d.cts +53 -48
  53. package/dist/cjs/lib/use-debounce.d.cts.map +1 -1
  54. package/dist/cjs/lib/use-widgets-invalidator.cjs +3 -3
  55. package/dist/cjs/lib/use-widgets-invalidator.cjs.map +1 -1
  56. package/dist/cjs/lib/use-widgets-invalidator.d.cts.map +1 -1
  57. package/dist/cjs/lib/utils.cjs +0 -7
  58. package/dist/cjs/lib/utils.cjs.map +1 -1
  59. package/dist/cjs/lib/utils.d.cts +0 -3
  60. package/dist/cjs/lib/utils.d.cts.map +1 -1
  61. package/dist/cjs/organization-switcher.client.cjs +2 -1
  62. package/dist/cjs/organization-switcher.client.cjs.map +1 -1
  63. package/dist/cjs/pipes-admin.client.cjs +2 -1
  64. package/dist/cjs/pipes-admin.client.cjs.map +1 -1
  65. package/dist/cjs/pipes.client.cjs +2 -1
  66. package/dist/cjs/pipes.client.cjs.map +1 -1
  67. package/dist/cjs/user-security.client.cjs +2 -1
  68. package/dist/cjs/user-security.client.cjs.map +1 -1
  69. package/dist/cjs/user-sessions.client.cjs +2 -1
  70. package/dist/cjs/user-sessions.client.cjs.map +1 -1
  71. package/dist/cjs/widgets/api-keys/api-keys-search.cjs +1 -1
  72. package/dist/cjs/widgets/api-keys/api-keys-search.cjs.map +1 -1
  73. package/dist/cjs/widgets/api-keys/user-api-keys-search.cjs +1 -1
  74. package/dist/cjs/widgets/api-keys/user-api-keys-search.cjs.map +1 -1
  75. package/dist/cjs/widgets/organization-switcher/organization-switcher.cjs +19 -5
  76. package/dist/cjs/widgets/organization-switcher/organization-switcher.cjs.map +1 -1
  77. package/dist/cjs/widgets/organization-switcher/organization-switcher.d.cts +2 -1
  78. package/dist/cjs/widgets/organization-switcher/organization-switcher.d.cts.map +1 -1
  79. package/dist/cjs/widgets/pipes/pipes.cjs +3 -2
  80. package/dist/cjs/widgets/pipes/pipes.cjs.map +1 -1
  81. package/dist/cjs/widgets/user-sessions/logout-all-sessions-dialog.cjs +2 -1
  82. package/dist/cjs/widgets/user-sessions/logout-all-sessions-dialog.cjs.map +1 -1
  83. package/dist/cjs/widgets/user-sessions/logout-dialog.cjs +2 -1
  84. package/dist/cjs/widgets/user-sessions/logout-dialog.cjs.map +1 -1
  85. package/dist/cjs/widgets/users-management/invite-user-dialog.cjs +5 -6
  86. package/dist/cjs/widgets/users-management/invite-user-dialog.cjs.map +1 -1
  87. package/dist/cjs/widgets/users-management/users-management-utils.cjs +4 -3
  88. package/dist/cjs/widgets/users-management/users-management-utils.cjs.map +1 -1
  89. package/dist/cjs/widgets/users-management/users-management.cjs.map +1 -1
  90. package/dist/cjs/widgets/users-management/users-search.cjs +1 -1
  91. package/dist/cjs/widgets/users-management/users-search.cjs.map +1 -1
  92. package/dist/esm/admin-portal-audit-log-streaming.client.js +2 -1
  93. package/dist/esm/admin-portal-audit-log-streaming.client.js.map +1 -1
  94. package/dist/esm/admin-portal-domain-verification.client.js +2 -1
  95. package/dist/esm/admin-portal-domain-verification.client.js.map +1 -1
  96. package/dist/esm/admin-portal-sso-connection.client.js +2 -1
  97. package/dist/esm/admin-portal-sso-connection.client.js.map +1 -1
  98. package/dist/esm/api/api-provider.d.ts.map +1 -1
  99. package/dist/esm/api/api-provider.js +23 -1
  100. package/dist/esm/api/api-provider.js.map +1 -1
  101. package/dist/esm/api/claims.d.ts +2 -1
  102. package/dist/esm/api/claims.d.ts.map +1 -1
  103. package/dist/esm/api/claims.js.map +1 -1
  104. package/dist/esm/api/client-graphql/client.js +3 -2
  105. package/dist/esm/api/client-graphql/client.js.map +1 -1
  106. package/dist/esm/api/client-graphql/hooks.d.ts +3 -12
  107. package/dist/esm/api/client-graphql/hooks.d.ts.map +1 -1
  108. package/dist/esm/api/client-graphql/hooks.js +1 -18
  109. package/dist/esm/api/client-graphql/hooks.js.map +1 -1
  110. package/dist/esm/api/client-graphql/query-keys.d.ts +16 -0
  111. package/dist/esm/api/client-graphql/query-keys.d.ts.map +1 -0
  112. package/dist/esm/api/client-graphql/query-keys.js +23 -0
  113. package/dist/esm/api/client-graphql/query-keys.js.map +1 -0
  114. package/dist/esm/components/copy-text.js +1 -1
  115. package/dist/esm/components/copy-text.js.map +1 -1
  116. package/dist/esm/components/form.d.ts.map +1 -1
  117. package/dist/esm/components/form.js +9 -13
  118. package/dist/esm/components/form.js.map +1 -1
  119. package/dist/esm/components/otp-input.js +1 -0
  120. package/dist/esm/components/otp-input.js.map +1 -1
  121. package/dist/esm/directory-sync.client.js +2 -1
  122. package/dist/esm/directory-sync.client.js.map +1 -1
  123. package/dist/esm/lib/api/api-key.js +2 -1
  124. package/dist/esm/lib/api/api-key.js.map +1 -1
  125. package/dist/esm/lib/api/me.js +2 -1
  126. package/dist/esm/lib/api/me.js.map +1 -1
  127. package/dist/esm/lib/api/pipes.js +2 -1
  128. package/dist/esm/lib/api/pipes.js.map +1 -1
  129. package/dist/esm/lib/api/user-api-key.js +2 -1
  130. package/dist/esm/lib/api/user-api-key.js.map +1 -1
  131. package/dist/esm/lib/i18n/intl-context.d.ts +1 -0
  132. package/dist/esm/lib/i18n/intl-context.d.ts.map +1 -1
  133. package/dist/esm/lib/i18n/intl-context.js.map +1 -1
  134. package/dist/esm/lib/i18n/use-translation.js +2 -2
  135. package/dist/esm/lib/i18n/use-translation.js.map +1 -1
  136. package/dist/esm/lib/use-composed-event-handlers.d.ts +6 -0
  137. package/dist/esm/lib/use-composed-event-handlers.d.ts.map +1 -0
  138. package/dist/esm/lib/use-composed-event-handlers.js +12 -0
  139. package/dist/esm/lib/use-composed-event-handlers.js.map +1 -0
  140. package/dist/esm/lib/use-debounce.d.ts +53 -48
  141. package/dist/esm/lib/use-debounce.d.ts.map +1 -1
  142. package/dist/esm/lib/use-debounce.js +124 -116
  143. package/dist/esm/lib/use-debounce.js.map +1 -1
  144. package/dist/esm/lib/use-widgets-invalidator.d.ts.map +1 -1
  145. package/dist/esm/lib/use-widgets-invalidator.js +2 -2
  146. package/dist/esm/lib/use-widgets-invalidator.js.map +1 -1
  147. package/dist/esm/lib/utils.d.ts +0 -3
  148. package/dist/esm/lib/utils.d.ts.map +1 -1
  149. package/dist/esm/lib/utils.js +1 -7
  150. package/dist/esm/lib/utils.js.map +1 -1
  151. package/dist/esm/organization-switcher.client.js +2 -1
  152. package/dist/esm/organization-switcher.client.js.map +1 -1
  153. package/dist/esm/pipes-admin.client.js +2 -1
  154. package/dist/esm/pipes-admin.client.js.map +1 -1
  155. package/dist/esm/pipes.client.js +2 -1
  156. package/dist/esm/pipes.client.js.map +1 -1
  157. package/dist/esm/user-security.client.js +2 -1
  158. package/dist/esm/user-security.client.js.map +1 -1
  159. package/dist/esm/user-sessions.client.js +2 -1
  160. package/dist/esm/user-sessions.client.js.map +1 -1
  161. package/dist/esm/widgets/api-keys/api-keys-search.js +1 -1
  162. package/dist/esm/widgets/api-keys/api-keys-search.js.map +1 -1
  163. package/dist/esm/widgets/api-keys/user-api-keys-search.js +1 -1
  164. package/dist/esm/widgets/api-keys/user-api-keys-search.js.map +1 -1
  165. package/dist/esm/widgets/organization-switcher/organization-switcher.d.ts +2 -1
  166. package/dist/esm/widgets/organization-switcher/organization-switcher.d.ts.map +1 -1
  167. package/dist/esm/widgets/organization-switcher/organization-switcher.js +19 -5
  168. package/dist/esm/widgets/organization-switcher/organization-switcher.js.map +1 -1
  169. package/dist/esm/widgets/pipes/pipes.js +2 -1
  170. package/dist/esm/widgets/pipes/pipes.js.map +1 -1
  171. package/dist/esm/widgets/user-sessions/logout-all-sessions-dialog.js +2 -1
  172. package/dist/esm/widgets/user-sessions/logout-all-sessions-dialog.js.map +1 -1
  173. package/dist/esm/widgets/user-sessions/logout-dialog.js +2 -1
  174. package/dist/esm/widgets/user-sessions/logout-dialog.js.map +1 -1
  175. package/dist/esm/widgets/users-management/invite-user-dialog.js +5 -6
  176. package/dist/esm/widgets/users-management/invite-user-dialog.js.map +1 -1
  177. package/dist/esm/widgets/users-management/users-management-utils.js +2 -1
  178. package/dist/esm/widgets/users-management/users-management-utils.js.map +1 -1
  179. package/dist/esm/widgets/users-management/users-management.js.map +1 -1
  180. package/dist/esm/widgets/users-management/users-search.js +1 -1
  181. package/dist/esm/widgets/users-management/users-search.js.map +1 -1
  182. package/package.json +1 -1
  183. package/src/api/api-provider.tsx +39 -1
  184. package/src/api/claims.ts +2 -1
  185. package/src/api/client-graphql/client.ts +8 -2
  186. package/src/api/client-graphql/hooks.ts +8 -27
  187. package/src/api/client-graphql/query-keys.ts +29 -0
  188. package/src/components/copy-text.tsx +1 -1
  189. package/src/components/form.tsx +33 -29
  190. package/src/components/otp-input.tsx +2 -0
  191. package/src/lib/i18n/intl-context.tsx +4 -0
  192. package/src/lib/i18n/use-translation.ts +1 -4
  193. package/src/lib/use-composed-event-handlers.ts +25 -0
  194. package/src/lib/use-debounce.ts +289 -237
  195. package/src/lib/use-widgets-invalidator.ts +0 -4
  196. package/src/lib/utils.ts +0 -12
  197. package/src/widgets/api-keys/api-keys-search.tsx +6 -3
  198. package/src/widgets/api-keys/user-api-keys-search.tsx +6 -3
  199. package/src/widgets/organization-switcher/organization-switcher.tsx +32 -8
  200. package/src/widgets/users-management/invite-user-dialog.tsx +9 -11
  201. package/src/widgets/users-management/users-management.tsx +1 -1
  202. package/src/widgets/users-management/users-search.tsx +6 -3
@@ -120,9 +120,15 @@ function createClientSdk(
120
120
  async (action, _operationName, operationType, _variables) => {
121
121
  const queryType: QueryType =
122
122
  operationType === "mutation" ? "mutation" : "query";
123
+ const queryData = queryClient.getQueryData<AuthTokenQueryData>(
124
+ authTokenQueryKey(widgetType),
125
+ );
126
+ // Read the cached token at request time: the rendered `authToken` may lag
127
+ // behind the cache until React re-renders after a token refetch.
128
+ const token = queryData?.authToken ?? authToken;
123
129
 
124
130
  try {
125
- return await action(buildHeaders(authToken, widgetType));
131
+ return await action(buildHeaders(token, widgetType));
126
132
  } catch (error) {
127
133
  let finalError: unknown = error;
128
134
  if (error instanceof ClientError && isAuthError(error)) {
@@ -135,7 +141,7 @@ function createClientSdk(
135
141
  });
136
142
  }
137
143
 
138
- if (freshToken && freshToken !== authToken) {
144
+ if (freshToken && freshToken !== token) {
139
145
  try {
140
146
  return await action(buildHeaders(freshToken, widgetType));
141
147
  } catch (retryError) {
@@ -1,6 +1,5 @@
1
1
  import { useMutation, useQuery } from "@tanstack/react-query";
2
2
  import type {
3
- QueryKey,
4
3
  UseMutationOptions,
5
4
  UseQueryOptions,
6
5
  } from "@tanstack/react-query";
@@ -8,32 +7,14 @@ import { useApiReady } from "../api-provider.js";
8
7
  import { useClientGraphql } from "./client.js";
9
8
  import type { Sdk } from "./generated.js";
10
9
 
11
- export type ClientGraphqlOperation = keyof Sdk;
12
-
13
- export type ClientGraphqlVariables<K extends ClientGraphqlOperation> =
14
- Parameters<Sdk[K]>[0];
15
-
16
- const CLIENT_GRAPHQL_KEY_PREFIX = "client-graphql";
17
-
18
- export function isClientGraphqlQueryKey(queryKey: QueryKey): boolean {
19
- return queryKey[0] === CLIENT_GRAPHQL_KEY_PREFIX;
20
- }
21
-
22
- /**
23
- * React Query key for a Client GraphQL operation. Omit `variables` to address
24
- * every cached page/variant of an operation, e.g. when invalidating after a
25
- * mutation:
26
- *
27
- * queryClient.invalidateQueries({ queryKey: clientGraphqlQueryKey("Sessions") });
28
- */
29
- export function clientGraphqlQueryKey<K extends ClientGraphqlOperation>(
30
- operation: K,
31
- variables?: ClientGraphqlVariables<K>,
32
- ): QueryKey {
33
- return variables === undefined
34
- ? [CLIENT_GRAPHQL_KEY_PREFIX, operation]
35
- : [CLIENT_GRAPHQL_KEY_PREFIX, operation, variables];
36
- }
10
+ export {
11
+ clientGraphqlQueryKey,
12
+ isClientGraphqlQueryKey,
13
+ } from "./query-keys.js";
14
+ export type {
15
+ ClientGraphqlOperation,
16
+ ClientGraphqlVariables,
17
+ } from "./query-keys.js";
37
18
 
38
19
  type ClientGraphqlQueryOptions<TResult, TData> = Omit<
39
20
  UseQueryOptions<TResult, Error, TData>,
@@ -0,0 +1,29 @@
1
+ import type { QueryKey } from "@tanstack/react-query";
2
+ import type { Sdk } from "./generated.js";
3
+
4
+ export type ClientGraphqlOperation = keyof Sdk;
5
+
6
+ export type ClientGraphqlVariables<K extends ClientGraphqlOperation> =
7
+ Parameters<Sdk[K]>[0];
8
+
9
+ const CLIENT_GRAPHQL_KEY_PREFIX = "client-graphql";
10
+
11
+ export function isClientGraphqlQueryKey(queryKey: QueryKey): boolean {
12
+ return queryKey[0] === CLIENT_GRAPHQL_KEY_PREFIX;
13
+ }
14
+
15
+ /**
16
+ * React Query key for a Client GraphQL operation. Omit `variables` to address
17
+ * every cached page/variant of an operation, e.g. when invalidating after a
18
+ * mutation:
19
+ *
20
+ * queryClient.invalidateQueries({ queryKey: clientGraphqlQueryKey("Sessions") });
21
+ */
22
+ export function clientGraphqlQueryKey<K extends ClientGraphqlOperation>(
23
+ operation: K,
24
+ variables?: ClientGraphqlVariables<K>,
25
+ ): QueryKey {
26
+ return variables === undefined
27
+ ? [CLIENT_GRAPHQL_KEY_PREFIX, operation]
28
+ : [CLIENT_GRAPHQL_KEY_PREFIX, operation, variables];
29
+ }
@@ -56,7 +56,7 @@ const CopyText: React.FC<CopyTextProps> = ({ value, label }) => {
56
56
  title={copyLabel}
57
57
  variant="ghost"
58
58
  size="1"
59
- aria-labelledby={copyLabel}
59
+ aria-label={copyLabel}
60
60
  className={namespaceClassName("copy-text__copy")}
61
61
  onClick={async (event) => {
62
62
  const button = event.currentTarget;
@@ -2,7 +2,7 @@
2
2
  import { Slot } from "@radix-ui/themes";
3
3
  import * as React from "react";
4
4
  import { useComposedRefs } from "../lib/compose-refs.js";
5
- import { composeEventHandlers } from "../lib/utils.js";
5
+ import { useComposedEventHandlers } from "../lib/use-composed-event-handlers.js";
6
6
 
7
7
  /* -------------------------------------------------------------------------------------------------
8
8
  * Form
@@ -195,12 +195,12 @@ const Form = /* @__PURE__ */ React.forwardRef<FormElement, FormProps>(
195
195
  <ValidationContext.Provider
196
196
  value={React.useMemo(
197
197
  () => ({
198
- getFieldValidity: getFieldValidity,
198
+ getFieldValidity,
199
199
  onFieldValidityChange: handleFieldValidityChange,
200
- getFieldCustomMatcherEntries: getFieldCustomMatcherEntries,
200
+ getFieldCustomMatcherEntries,
201
201
  onFieldCustomMatcherEntryAdd: handleFieldCustomMatcherAdd,
202
202
  onFieldCustomMatcherEntryRemove: handleFieldCustomMatcherRemove,
203
- getFieldCustomErrors: getFieldCustomErrors,
203
+ getFieldCustomErrors,
204
204
  onFieldCustomErrorsChange: handleFieldCustomErrorsChange,
205
205
  onFieldValiditionClear: handleFieldValiditionClear,
206
206
  }),
@@ -234,23 +234,29 @@ const Form = /* @__PURE__ */ React.forwardRef<FormElement, FormProps>(
234
234
  {...rootProps}
235
235
  ref={composedFormRef}
236
236
  // focus first invalid control when the form is submitted
237
- onInvalid={composeEventHandlers(props.onInvalid, (event) => {
238
- const firstInvalidControl = getFirstInvalidControl(
239
- event.currentTarget,
240
- );
241
- if (firstInvalidControl === event.target)
242
- firstInvalidControl.focus();
243
-
244
- // prevent default browser UI for form validation
245
- event.preventDefault();
246
- })}
237
+ onInvalid={useComposedEventHandlers(
238
+ props.onInvalid,
239
+ React.useCallback((event) => {
240
+ const firstInvalidControl = getFirstInvalidControl(
241
+ event.currentTarget,
242
+ );
243
+ if (firstInvalidControl === event.target)
244
+ firstInvalidControl.focus();
245
+
246
+ // prevent default browser UI for form validation
247
+ event.preventDefault();
248
+ }, []),
249
+ )}
247
250
  // clear server errors when the form is re-submitted
248
251
  onSubmit={(event) => {
249
252
  props.onSubmit?.(event);
250
253
  onClearServerErrors();
251
254
  }}
252
255
  // clear server errors when the form is reset
253
- onReset={composeEventHandlers(props.onReset, onClearServerErrors)}
256
+ onReset={useComposedEventHandlers(
257
+ props.onReset,
258
+ onClearServerErrors,
259
+ )}
254
260
  />
255
261
  </AriaDescriptionContext.Provider>
256
262
  </ValidationContext.Provider>
@@ -436,7 +442,8 @@ const FormControl = /* @__PURE__ */ React.forwardRef<
436
442
  onFieldValiditionClear,
437
443
  } = validationContext;
438
444
  const updateControlValidity = React.useCallback(
439
- async (control: FormControlElement) => {
445
+ async (event: { currentTarget: FormControlElement }) => {
446
+ const { currentTarget: control } = event;
440
447
  //------------------------------------------------------------------------------------------
441
448
  // 1. first, if we have built-in errors we stop here
442
449
 
@@ -515,9 +522,11 @@ const FormControl = /* @__PURE__ */ React.forwardRef<
515
522
  React.useEffect(() => {
516
523
  const control = ref.current;
517
524
  if (control) {
518
- // We only want validate on change (native `change` event, not React's `onChange`). This is primarily
519
- // a UX decision, we don't want to validate on every keystroke and React's `onChange` is the `input` event.
520
- const handleChange = () => updateControlValidity(control);
525
+ // We only want validate on change (native `change` event, not React's
526
+ // `onChange`). This is primarily a UX decision, we don't want to validate
527
+ // on every keystroke and React's `onChange` is the `input` event.
528
+ const handleChange = () =>
529
+ updateControlValidity({ currentTarget: control });
521
530
  control.addEventListener("change", handleChange);
522
531
  return () => control.removeEventListener("change", handleChange);
523
532
  }
@@ -577,16 +586,11 @@ const FormControl = /* @__PURE__ */ React.forwardRef<
577
586
  ref={composedRef}
578
587
  id={id}
579
588
  name={name}
580
- onInvalid={composeEventHandlers(props.onInvalid, (event) => {
581
- const control = event.currentTarget;
582
- updateControlValidity(control);
583
- })}
584
- // TODO: Debug; this might be a react compiler error
585
- // oxlint-disable-next-line react/refs
586
- onChange={composeEventHandlers(props.onChange, () => {
587
- // reset validity when user changes value
588
- resetControlValidity();
589
- })}
589
+ onInvalid={useComposedEventHandlers(
590
+ props.onInvalid,
591
+ updateControlValidity,
592
+ )}
593
+ onChange={useComposedEventHandlers(props.onChange, resetControlValidity)}
590
594
  />
591
595
  );
592
596
  });
@@ -243,6 +243,8 @@ const OtpInput = React.forwardRef<HTMLInputElement, OtpInputProps>(
243
243
  otpContext.onEnterPressed();
244
244
  }
245
245
  }}
246
+ // TODO(v2): remove; we're no longer using it
247
+ data-index={index}
246
248
  {...props}
247
249
  />
248
250
  </Form.Control>
@@ -16,6 +16,10 @@ type MessageValues = Record<string, string | React.ReactNode>;
16
16
  */
17
17
  interface IntlContextValue {
18
18
  locale: string;
19
+ formatMessage(
20
+ descriptor: MessageDescriptor,
21
+ values?: Record<string, string>,
22
+ ): string;
19
23
  formatMessage(
20
24
  descriptor: MessageDescriptor,
21
25
  values?: MessageValues,
@@ -24,10 +24,7 @@ export function useTranslation() {
24
24
 
25
25
  // If I18nProvider is present, use react-intl's formatMessage
26
26
  if (formatMessage) {
27
- // TODO: Do we really want to cast this to a string?
28
- return String(
29
- formatMessage({ id, defaultMessage, description }, values),
30
- );
27
+ return formatMessage({ id, defaultMessage, description }, values);
31
28
  }
32
29
 
33
30
  // If no I18nProvider is present, return defaultMessage with simple interpolation
@@ -0,0 +1,25 @@
1
+ import * as React from "react";
2
+
3
+ export function useComposedEventHandlers<
4
+ E extends { defaultPrevented: boolean },
5
+ >(
6
+ originalEventHandler?: (event: E) => void,
7
+ ourEventHandler?: (event: E) => void,
8
+ ): (event: E) => void;
9
+
10
+ export function useComposedEventHandlers<
11
+ E extends { defaultPrevented: boolean },
12
+ >(
13
+ originalEventHandler?: (event: E) => void,
14
+ ourEventHandler?: (event: E) => void,
15
+ ): (event: E) => void {
16
+ return React.useCallback(
17
+ (event: E) => {
18
+ originalEventHandler?.(event);
19
+ if (!event?.defaultPrevented) {
20
+ ourEventHandler?.(event);
21
+ }
22
+ },
23
+ [originalEventHandler, ourEventHandler],
24
+ );
25
+ }