playbook_ui 15.5.0.pre.alpha.PLAY2581aggressivevalidation12653 → 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: bd8b63915fa51f6daabd0a877e7bd6c0dbe337c900389228dd9434f5deeaa535
4
- data.tar.gz: 1ba2091df0504ec326221fd2660e9238e7220673385b159e0c207ad82fb28e35
3
+ metadata.gz: 8d7304b03db9bc4ab776ed9ce2604fe575e567e1422f9d5723bd21d5c70c7055
4
+ data.tar.gz: 13a59f20b961605878db38e672e12506f237cc84fc551f25362c6903cde1eb03
5
5
  SHA512:
6
- metadata.gz: 212923b88fdcc63bd98592cc373ff989b51f237d1d147b6fb5f083e15b521812e7a06d9f9ee54f2b1ccf16edf3160ee94e6b28f81a10caf5bcbcee59b731774d
7
- data.tar.gz: 8ee030cb7e451dae0bedec3d130b94ae4607ce49037f95c4901ce02a755eb054829734682c1d46c067cca2955da6272baa46c741cc1124b4be94b2fddb64859f
6
+ metadata.gz: 4598269558bc2d5ba6477f6960b79cf9ba382cccf3d3aff365593dd191eb02848f0c04ac01b5e387f5a002378cf60d009e764e94dafb49247457c8daa3576de0
7
+ data.tar.gz: 9b79bf1cd0d95cafee125db473de79c58063ef9520172531f6be7e91eba01248d6e0a41cfb49449ebcd2ed20f576764e20931704c86df2bb017d0a7e7d6c8884
@@ -112,19 +112,14 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
112
112
  const wrapperRef = useRef<HTMLDivElement | null>(null);
113
113
  const hasBlurredRef = useRef<boolean>(false);
114
114
  const formSubmittedRef = useRef<boolean>(false);
115
- // Handle value prop - it might be a string or an object with number property (from react-hook-form)
116
- const getValueString = (val: any): string => {
117
- if (typeof val === 'string') return val
118
- if (val?.number) return val.number
119
- return ""
120
- }
121
- const [inputValue, setInputValue] = useState(getValueString(value))
115
+ const [inputValue, setInputValue] = useState(value)
122
116
  const [error, setError] = useState(props.error || "")
123
117
  const [dropDownIsOpen, setDropDownIsOpen] = useState(false)
124
118
  const [selectedData, setSelectedData] = useState()
125
119
  const [hasTyped, setHasTyped] = useState(false)
126
120
  const [hasBlurred, setHasBlurred] = useState(false)
127
121
  const [formSubmitted, setFormSubmitted] = useState(false)
122
+ const [hasStartedValidating, setHasStartedValidating] = useState(false)
128
123
 
129
124
  // Keep refs in sync with state for use in event listeners
130
125
  useEffect(() => {
@@ -134,16 +129,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
134
129
  useEffect(() => {
135
130
  formSubmittedRef.current = formSubmitted
136
131
  }, [formSubmitted])
137
- const [hasStartedValidating, setHasStartedValidating] = useState(false)
138
-
139
- // Sync value prop when it changes (e.g., from react-hook-form)
140
- useEffect(() => {
141
- const newValue = getValueString(props.value)
142
- if (newValue !== inputValue) {
143
- setInputValue(newValue)
144
- }
145
- // eslint-disable-next-line react-hooks/exhaustive-deps
146
- }, [props.value])
147
132
 
148
133
  // Only sync initial error from props, not continuous updates
149
134
  // Once validation starts, internal validation takes over
@@ -173,10 +158,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
173
158
  // Show internal errors only after blur (hasBlurred) or on form submission (formSubmitted)
174
159
  const shouldShowInternalError = (hasBlurred || formSubmitted) && error
175
160
  const displayError = shouldShowInternalError ? error : ""
176
-
177
- // Only show error prop after blur (to prevent showing react-hook-form errors while typing)
178
- const shouldShowPropError = hasBlurred || formSubmitted
179
- const propError = shouldShowPropError ? (props.error || "") : ""
180
161
 
181
162
  useEffect(() => {
182
163
  const hasError = (error ?? '').length > 0
@@ -291,7 +272,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
291
272
  }
292
273
 
293
274
  // Only validate if field has been blurred or form has been submitted
294
- // Don't validate on change - only on blur or submission
295
275
  if (!hasBlurred && !formSubmitted) return
296
276
 
297
277
  // Run validation checks
@@ -306,7 +286,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
306
286
 
307
287
  // Add listener for form validation to track when validation should be shown
308
288
  useEffect(() => {
309
- const handleInvalid = (event: Event) => {
289
+ const handleInvalid = (event: Event) => {
310
290
  const target = event.target as HTMLInputElement
311
291
  const phoneNumberContainer = target.closest('.pb_phone_number_input')
312
292
 
@@ -444,12 +424,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
444
424
  setFormSubmitted(false)
445
425
  }
446
426
 
447
- // Clear error when user starts typing (before blur)
448
- // This prevents showing validation errors while typing
449
- if (!hasBlurredRef.current && error) {
450
- setError('')
451
- }
452
-
453
427
  let phoneNumberData
454
428
 
455
429
  // Handle formatAsYouType with input event
@@ -465,6 +439,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
465
439
 
466
440
  // Don't call isValid callback on change - only on blur or form submission
467
441
  // This prevents triggering validation while typing
442
+ // Use refs to get current values in case this is called from event listener
468
443
  if (hasBlurredRef.current || formSubmittedRef.current) {
469
444
  isValid(itiRef.current.isValidNumber())
470
445
  }
@@ -525,11 +500,6 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
525
500
  setInputValue(formattedValue)
526
501
  setHasTyped(true)
527
502
 
528
- // Clear error when user types (before blur) - use ref to get current value
529
- if (!hasBlurredRef.current) {
530
- setError('')
531
- }
532
-
533
503
  // Get phone number data with unformatted number
534
504
  const formattedPhoneNumberData = getCurrentSelectedData(telInputInit, formattedValue)
535
505
  const phoneNumberData = {...formattedPhoneNumberData, number: unformatNumber(formattedPhoneNumberData.number)}
@@ -538,6 +508,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
538
508
  onChange(phoneNumberData)
539
509
 
540
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)
541
512
  if (hasBlurredRef.current || formSubmittedRef.current) {
542
513
  isValid(telInputInit.isValidNumber())
543
514
  }
@@ -550,7 +521,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
550
521
  dark,
551
522
  "data-phone-number": JSON.stringify(selectedData),
552
523
  disabled,
553
- error: displayError || propError,
524
+ error: displayError || props.error || "",
554
525
  type: 'tel',
555
526
  id,
556
527
  label,