playbook_ui 15.5.0.pre.alpha.PLAY2581aggressivevalidation12652 → 15.5.0.pre.alpha.PLAY2581aggressivevalidation12654

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b033c3a47f35de6f8b7ffc146e271bb47b1deacd8907d26ce7a2b0d53f5cbb21
4
- data.tar.gz: 20e3e4fc5b7c06a0dca8af5bc6fec8896d4747ca44a6bb54fa20a19231414ba6
3
+ metadata.gz: 8d7304b03db9bc4ab776ed9ce2604fe575e567e1422f9d5723bd21d5c70c7055
4
+ data.tar.gz: 13a59f20b961605878db38e672e12506f237cc84fc551f25362c6903cde1eb03
5
5
  SHA512:
6
- metadata.gz: 0a6b71fd848f702853c207858e87c9871452ddc33c47302f3b2f088b89e3a60a43a444c4b38a063dee98417471972969e46ca6be3b0bad682f414c8e32d282bd
7
- data.tar.gz: 36223f09387c0edc8f0e101568abae69bb1554525e3cf0e616d7cd3086ddcf4bce8994f6bc118fc6b64ad7e11bd02162a438fa03daa6f6ea023913b007d18446
6
+ metadata.gz: 4598269558bc2d5ba6477f6960b79cf9ba382cccf3d3aff365593dd191eb02848f0c04ac01b5e387f5a002378cf60d009e764e94dafb49247457c8daa3576de0
7
+ data.tar.gz: 9b79bf1cd0d95cafee125db473de79c58063ef9520172531f6be7e91eba01248d6e0a41cfb49449ebcd2ed20f576764e20931704c86df2bb017d0a7e7d6c8884
@@ -110,13 +110,9 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
110
110
  const inputRef = useRef<HTMLInputElement | null>(null)
111
111
  const itiRef = useRef<any>(null);
112
112
  const wrapperRef = useRef<HTMLDivElement | null>(null);
113
- // Handle value prop - it might be a string or an object with number property (from react-hook-form)
114
- const getValueString = (val: any): string => {
115
- if (typeof val === 'string') return val
116
- if (val?.number) return val.number
117
- return ""
118
- }
119
- const [inputValue, setInputValue] = useState(getValueString(value))
113
+ const hasBlurredRef = useRef<boolean>(false);
114
+ const formSubmittedRef = useRef<boolean>(false);
115
+ const [inputValue, setInputValue] = useState(value)
120
116
  const [error, setError] = useState(props.error || "")
121
117
  const [dropDownIsOpen, setDropDownIsOpen] = useState(false)
122
118
  const [selectedData, setSelectedData] = useState()
@@ -124,15 +120,15 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
124
120
  const [hasBlurred, setHasBlurred] = useState(false)
125
121
  const [formSubmitted, setFormSubmitted] = useState(false)
126
122
  const [hasStartedValidating, setHasStartedValidating] = useState(false)
127
-
128
- // Sync value prop when it changes (e.g., from react-hook-form)
123
+
124
+ // Keep refs in sync with state for use in event listeners
129
125
  useEffect(() => {
130
- const newValue = getValueString(props.value)
131
- if (newValue !== inputValue) {
132
- setInputValue(newValue)
133
- }
134
- // eslint-disable-next-line react-hooks/exhaustive-deps
135
- }, [props.value])
126
+ hasBlurredRef.current = hasBlurred
127
+ }, [hasBlurred])
128
+
129
+ useEffect(() => {
130
+ formSubmittedRef.current = formSubmitted
131
+ }, [formSubmitted])
136
132
 
137
133
  // Only sync initial error from props, not continuous updates
138
134
  // Once validation starts, internal validation takes over
@@ -162,10 +158,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
162
158
  // Show internal errors only after blur (hasBlurred) or on form submission (formSubmitted)
163
159
  const shouldShowInternalError = (hasBlurred || formSubmitted) && error
164
160
  const displayError = shouldShowInternalError ? error : ""
165
-
166
- // Only show error prop after blur (to prevent showing react-hook-form errors while typing)
167
- const shouldShowPropError = hasBlurred || formSubmitted
168
- const propError = shouldShowPropError ? (props.error || "") : ""
169
161
 
170
162
  useEffect(() => {
171
163
  const hasError = (error ?? '').length > 0
@@ -280,7 +272,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
280
272
  }
281
273
 
282
274
  // Only validate if field has been blurred or form has been submitted
283
- // Don't validate on change - only on blur or submission
284
275
  if (!hasBlurred && !formSubmitted) return
285
276
 
286
277
  // Run validation checks
@@ -302,6 +293,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
302
293
  if (phoneNumberContainer && phoneNumberContainer === wrapperRef.current) {
303
294
  const invalidInputName = target.name || target.getAttribute('name')
304
295
  if (invalidInputName === name) {
296
+ formSubmittedRef.current = true
305
297
  setFormSubmitted(true)
306
298
  // Trigger validation when form is submitted
307
299
  validateErrors()
@@ -327,7 +319,9 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
327
319
  setInputValue("")
328
320
  setError("")
329
321
  setHasTyped(false)
322
+ hasBlurredRef.current = false
330
323
  setHasBlurred(false)
324
+ formSubmittedRef.current = false
331
325
  setFormSubmitted(false)
332
326
  setHasStartedValidating(false)
333
327
  // Only clear validation state if field was required
@@ -345,6 +339,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
345
339
 
346
340
  if (required && isEmpty) {
347
341
  setError('Missing phone number')
342
+ formSubmittedRef.current = true
348
343
  setFormSubmitted(true)
349
344
  return 'Missing phone number'
350
345
  }
@@ -401,6 +396,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
401
396
 
402
397
  // Set the error state so the validation attribute gets added
403
398
  setError(errorMessage)
399
+ formSubmittedRef.current = true
404
400
  setFormSubmitted(true)
405
401
  setHasTyped(true)
406
402
 
@@ -424,6 +420,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
424
420
 
425
421
  // Reset form submitted state when user types
426
422
  if (formSubmitted) {
423
+ formSubmittedRef.current = false
427
424
  setFormSubmitted(false)
428
425
  }
429
426
 
@@ -439,7 +436,13 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
439
436
 
440
437
  setSelectedData(phoneNumberData)
441
438
  onChange(phoneNumberData)
442
- isValid(itiRef.current.isValidNumber())
439
+
440
+ // Don't call isValid callback on change - only on blur or form submission
441
+ // This prevents triggering validation while typing
442
+ // Use refs to get current values in case this is called from event listener
443
+ if (hasBlurredRef.current || formSubmittedRef.current) {
444
+ isValid(itiRef.current.isValidNumber())
445
+ }
443
446
 
444
447
  // Don't validate on change - only validate on blur or form submission
445
448
  }
@@ -503,7 +506,12 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
503
506
 
504
507
  setSelectedData(phoneNumberData)
505
508
  onChange(phoneNumberData)
506
- isValid(telInputInit.isValidNumber())
509
+
510
+ // Don't call isValid callback on change - only on blur or form submission
511
+ // Use refs to check current blur state in the event listener (closure issue)
512
+ if (hasBlurredRef.current || formSubmittedRef.current) {
513
+ isValid(telInputInit.isValidNumber())
514
+ }
507
515
  })
508
516
  }
509
517
  }
@@ -513,12 +521,13 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
513
521
  dark,
514
522
  "data-phone-number": JSON.stringify(selectedData),
515
523
  disabled,
516
- error: displayError || propError,
524
+ error: displayError || props.error || "",
517
525
  type: 'tel',
518
526
  id,
519
527
  label,
520
528
  name,
521
529
  onBlur: () => {
530
+ hasBlurredRef.current = true
522
531
  setHasBlurred(true)
523
532
  validateErrors()
524
533
  },