playbook_ui 15.5.0.pre.alpha.PLAY2581aggressivevalidation12650 → 15.5.0.pre.alpha.PLAY2581aggressivevalidation12651

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: e03ff921e93222ee43918cb8f7587728ec77eecf9d7bf901103e955fa387d9d3
4
- data.tar.gz: 124557cd8f737ad7999cf59787eb9183e52f3ebcd4853bad2241b7e4d1982aa0
3
+ metadata.gz: 7a11fd5c7d50218344f06ff233740c4b4fbd7821f77ae252ae36cb6b0a72891b
4
+ data.tar.gz: 34b091afe5eeb712931507289e02ea6f9fbc0476d6700340a3ce7f22d97a86ca
5
5
  SHA512:
6
- metadata.gz: 2a97fa52358423064cf1c1564ea623fc2087debacc08bf9e282c59ea274b41c8725f9ea37b3dc414d35227bf7d17dc621e2850def822925047564deb6181edf0
7
- data.tar.gz: '0195e845746b7ab77e555c006a506a951ca7347ce65668b12d67401387363c1031b641f156cda4ba2332bfd11b9b46d3dfbe772d3d42c01f58f3930650870f88'
6
+ metadata.gz: 98b2841f9f591ad23e05c8fc418e518672c6820abd5d338e4d7144f4b3900c91005ff00f1c7829a6e474428a5fe83224a5a3b6ef1c7bd527aad2cf9fddf8d95a
7
+ data.tar.gz: bee8426f2ca6a22dbd355427ec5d5f34fee41ce12752a0ecf78d14663f1be35b68fce6e0316ef4b2340632e011203302daac490c56a1eb177e92fdf3354893f9
@@ -110,7 +110,13 @@ 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
- const [inputValue, setInputValue] = useState(value)
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))
114
120
  const [error, setError] = useState(props.error || "")
115
121
  const [dropDownIsOpen, setDropDownIsOpen] = useState(false)
116
122
  const [selectedData, setSelectedData] = useState()
@@ -119,6 +125,15 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
119
125
  const [formSubmitted, setFormSubmitted] = useState(false)
120
126
  const [hasStartedValidating, setHasStartedValidating] = useState(false)
121
127
 
128
+ // Sync value prop when it changes (e.g., from react-hook-form)
129
+ 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])
136
+
122
137
  // Only sync initial error from props, not continuous updates
123
138
  // Once validation starts, internal validation takes over
124
139
  useEffect(() => {
@@ -147,6 +162,10 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
147
162
  // Show internal errors only after blur (hasBlurred) or on form submission (formSubmitted)
148
163
  const shouldShowInternalError = (hasBlurred || formSubmitted) && error
149
164
  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 || "") : ""
150
169
 
151
170
  useEffect(() => {
152
171
  const hasError = (error ?? '').length > 0
@@ -493,12 +512,12 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
493
512
  dark,
494
513
  "data-phone-number": JSON.stringify(selectedData),
495
514
  disabled,
496
- error: hasTyped ? error : props.error || displayError,
515
+ error: displayError || propError,
497
516
  type: 'tel',
498
517
  id,
499
518
  label,
500
519
  name,
501
- onBlur: (e: React.FocusEvent<HTMLInputElement>) => {
520
+ onBlur: () => {
502
521
  setHasBlurred(true)
503
522
  validateErrors()
504
523
  },