playbook_ui 15.6.0.pre.rc.3 → 15.6.0.pre.rc.4

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: 1e9964f7e4d581df22bf766c0fa280f292929dc9ec0f1524a851edb43da19cf4
4
- data.tar.gz: a3cf957cb97905233cf0c80bd56bf495ac223a72e0fd221b03df3714a442cce0
3
+ metadata.gz: c34ed34894c77c65c7b4ab52a7b921200f1f96774c4512284549bee9f9b43763
4
+ data.tar.gz: faed7dd35f9e9c0cbc6702c305d8e6bb1a6b43f78c117931528ce1a4f47218d5
5
5
  SHA512:
6
- metadata.gz: '000728061dbe3c740f512461d4bf230592135fed6befd1899f65ae12036c08a231374f40d60c6d38efbb4e97760054a0d2bdc4a1909a44bcd6a38546bfd59619'
7
- data.tar.gz: b0697da248684965e7f9f327614cc0cfdac3429b3b724a923ac978790f51404fb26107073a8e10f9db3e3796afed5cbec237e36133e107d08ecbd7c920514078
6
+ metadata.gz: 78bc97c590826a13a8f89f58d8898360064b91f464f92d660a479a45c1654c2716661a56c68028d951e918410b2aa6dec8806158653493952a3c9818756f1583
7
+ data.tar.gz: 838f146d76432cffe68da3a90d32b044dd59bb74157b5bb28b0d00aa34a8a060cc81ec50d5ed04e79bf574abd96ebf2c3aec6cec1330ad36dc51f41d7f6d926b
@@ -102,16 +102,16 @@ const Background = (props: BackgroundProps): React.ReactElement => {
102
102
  useEffect(() => {
103
103
  const updateResponsiveProps = () => {
104
104
  setResponsiveProps({
105
- backgroundSize: getResponsiveValue(props.backgroundSize),
106
- backgroundPosition: getResponsiveValue(props.backgroundPosition),
107
- backgroundRepeat: getResponsiveValue(props.backgroundRepeat),
108
- backgroundColor: getResponsiveValue(props.backgroundColor),
109
- imageUrl: getResponsiveValue(props.imageUrl),
105
+ backgroundSize: getResponsiveValue(backgroundSize),
106
+ backgroundPosition: getResponsiveValue(backgroundPosition),
107
+ backgroundRepeat: getResponsiveValue(backgroundRepeat),
108
+ backgroundColor: getResponsiveValue(backgroundColor),
109
+ imageUrl: getResponsiveValue(imageUrl),
110
110
  });
111
111
  };
112
112
  window.addEventListener('resize', updateResponsiveProps);
113
113
  return () => window.removeEventListener('resize', updateResponsiveProps);
114
- }, [props]);
114
+ }, [backgroundSize, backgroundPosition, backgroundRepeat, backgroundColor, imageUrl]);
115
115
 
116
116
 
117
117
  // Extract currently applicable responsive values.
@@ -4,7 +4,6 @@ import Background from './_background'
4
4
 
5
5
  const props = {
6
6
  data: { testid: 'background' },
7
- backgroundColor: null,
8
7
  }
9
8
 
10
9
  it('Should be accessible', async () => {
@@ -42,3 +41,8 @@ test('applies correct overlay class when imageOverlay prop is provided', () => {
42
41
  const kit = renderKit(Background, props, { imageOverlay: 'opacity_6' });
43
42
  expect(kit).toHaveClass('imageoverlay_opacity_6');
44
43
  });
44
+
45
+ test('Sets backgroundColor to light as default when no backgroundColor prop is provided', () => {
46
+ const kit = renderKit(Background, props);
47
+ expect(kit).toHaveClass('pb_background_color_light');
48
+ });
@@ -1,3 +1,3 @@
1
- <%= pb_rails("background", props: { background_color: "light", padding: "xl" }) do %>
1
+ <%= pb_rails("background", props: { padding: "xl" }) do %>
2
2
 
3
3
  <% end %>
@@ -3,7 +3,6 @@ import Background from '../../pb_background/_background'
3
3
 
4
4
  const BackgroundLight = (props) => (
5
5
  <Background
6
- backgroundColor="light"
7
6
  padding="xl"
8
7
  {...props}
9
8
  />
@@ -0,0 +1 @@
1
+ By default, the Background kit sets background color to 'light' as seen here.
@@ -1,7 +1,7 @@
1
1
  examples:
2
2
 
3
3
  rails:
4
- - background_light: Light
4
+ - background_light: Default
5
5
  - background_white: White
6
6
  - background_gradient: Gradient
7
7
  - background_image: Image
@@ -11,7 +11,7 @@ examples:
11
11
  - background_size: Size
12
12
 
13
13
  react:
14
- - background_light: Light
14
+ - background_light: Default
15
15
  - background_white: White
16
16
  - background_gradient: Gradient
17
17
  - background_image: Image
@@ -143,30 +143,25 @@ export default class PbDialog extends PbEnhancedElement {
143
143
 
144
144
  // Close dialog box on outside click
145
145
  dialogs.forEach((dialogElement) => {
146
- const originalClickHandler = dialogElement._outsideClickHandler
147
- if (originalClickHandler) dialogElement.removeEventListener("click", originalClickHandler)
148
-
146
+ const originalMousedownHandler = dialogElement._outsideClickHandler
147
+ if (originalMousedownHandler) dialogElement.removeEventListener("mousedown", originalMousedownHandler)
149
148
  dialogElement._outsideClickHandler = (event) => {
150
149
  const dialogParentDataset = dialogElement.parentElement.dataset
151
150
  if (dialogParentDataset.overlayClick === "overlay_close") return
152
151
 
153
- // Get the dialog's bounding box (the actual content area)
154
- const rect = dialogElement.getBoundingClientRect()
155
- const clickedInDialog = (
156
- event.clientX >= rect.left &&
157
- event.clientX <= rect.right &&
158
- event.clientY >= rect.top &&
159
- event.clientY <= rect.bottom
160
- )
161
-
162
- // Only close if clicked outside the dialog content (on the backdrop)
163
- if (!clickedInDialog) {
152
+ const dialogModal = event.target.getBoundingClientRect()
153
+ const clickedOutsideDialogModal = event.clientX < dialogModal.left ||
154
+ event.clientX > dialogModal.right ||
155
+ event.clientY < dialogModal.top ||
156
+ event.clientY > dialogModal.bottom
157
+
158
+ if (clickedOutsideDialogModal) {
164
159
  dialogElement.close()
165
160
  event.stopPropagation()
166
161
  }
167
162
  }
168
163
 
169
- dialogElement.addEventListener("click", dialogElement._outsideClickHandler);
164
+ dialogElement.addEventListener("mousedown", dialogElement._outsideClickHandler);
170
165
  })
171
166
  }
172
167
  }
@@ -110,13 +110,25 @@ 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 hasBlurredRef = useRef<boolean>(false);
114
+ const formSubmittedRef = useRef<boolean>(false);
113
115
  const [inputValue, setInputValue] = useState(value)
114
116
  const [error, setError] = useState(props.error || "")
115
117
  const [dropDownIsOpen, setDropDownIsOpen] = useState(false)
116
118
  const [selectedData, setSelectedData] = useState()
117
119
  const [hasTyped, setHasTyped] = useState(false)
120
+ const [hasBlurred, setHasBlurred] = useState(false)
118
121
  const [formSubmitted, setFormSubmitted] = useState(false)
119
122
  const [hasStartedValidating, setHasStartedValidating] = useState(false)
123
+
124
+ // Keep refs in sync with state for use in event listeners
125
+ useEffect(() => {
126
+ hasBlurredRef.current = hasBlurred
127
+ }, [hasBlurred])
128
+
129
+ useEffect(() => {
130
+ formSubmittedRef.current = formSubmitted
131
+ }, [formSubmitted])
120
132
 
121
133
  // Only sync initial error from props, not continuous updates
122
134
  // Once validation starts, internal validation takes over
@@ -143,8 +155,8 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
143
155
  }
144
156
 
145
157
  // Determine which error to display
146
- // Show internal errors on blur (hasTyped) or on form submission (formSubmitted)
147
- const shouldShowInternalError = (hasTyped || formSubmitted) && required && error
158
+ // Show internal errors only after blur (hasBlurred) or on form submission (formSubmitted)
159
+ const shouldShowInternalError = (hasBlurred || formSubmitted) && error
148
160
  const displayError = shouldShowInternalError ? error : ""
149
161
 
150
162
  useEffect(() => {
@@ -259,7 +271,9 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
259
271
  return
260
272
  }
261
273
 
262
- if (!hasTyped && !error) return
274
+ // Only validate if field has been blurred or form has been submitted
275
+ // Use refs here since state updates are async and we need current values
276
+ if (!hasBlurredRef.current && !formSubmittedRef.current) return
263
277
 
264
278
  // Run validation checks
265
279
  if (itiRef.current) isValid(itiRef.current.isValidNumber())
@@ -280,6 +294,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
280
294
  if (phoneNumberContainer && phoneNumberContainer === wrapperRef.current) {
281
295
  const invalidInputName = target.name || target.getAttribute('name')
282
296
  if (invalidInputName === name) {
297
+ formSubmittedRef.current = true
283
298
  setFormSubmitted(true)
284
299
  // Trigger validation when form is submitted
285
300
  validateErrors()
@@ -305,6 +320,9 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
305
320
  setInputValue("")
306
321
  setError("")
307
322
  setHasTyped(false)
323
+ hasBlurredRef.current = false
324
+ setHasBlurred(false)
325
+ formSubmittedRef.current = false
308
326
  setFormSubmitted(false)
309
327
  setHasStartedValidating(false)
310
328
  // Only clear validation state if field was required
@@ -322,6 +340,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
322
340
 
323
341
  if (required && isEmpty) {
324
342
  setError('Missing phone number')
343
+ formSubmittedRef.current = true
325
344
  setFormSubmitted(true)
326
345
  return 'Missing phone number'
327
346
  }
@@ -378,6 +397,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
378
397
 
379
398
  // Set the error state so the validation attribute gets added
380
399
  setError(errorMessage)
400
+ formSubmittedRef.current = true
381
401
  setFormSubmitted(true)
382
402
  setHasTyped(true)
383
403
 
@@ -401,6 +421,7 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
401
421
 
402
422
  // Reset form submitted state when user types
403
423
  if (formSubmitted) {
424
+ formSubmittedRef.current = false
404
425
  setFormSubmitted(false)
405
426
  }
406
427
 
@@ -416,11 +437,15 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
416
437
 
417
438
  setSelectedData(phoneNumberData)
418
439
  onChange(phoneNumberData)
419
- isValid(itiRef.current.isValidNumber())
440
+
441
+ // Don't call isValid callback on change - only on blur or form submission
442
+ // This prevents triggering validation while typing
443
+ // Use refs to get current values in case this is called from event listener
444
+ if (hasBlurredRef.current || formSubmittedRef.current) {
445
+ isValid(itiRef.current.isValidNumber())
446
+ }
420
447
 
421
- // Trigger validation after onChange for React Hook Form
422
- // This ensures validation state is up-to-date
423
- setTimeout(() => validateErrors(), 0)
448
+ // Don't validate on change - only validate on blur or form submission
424
449
  }
425
450
 
426
451
  // Separating Concerns as React Docs Recommend
@@ -482,7 +507,12 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
482
507
 
483
508
  setSelectedData(phoneNumberData)
484
509
  onChange(phoneNumberData)
485
- isValid(telInputInit.isValidNumber())
510
+
511
+ // Don't call isValid callback on change - only on blur or form submission
512
+ // Use refs to check current blur state in the event listener (closure issue)
513
+ if (hasBlurredRef.current || formSubmittedRef.current) {
514
+ isValid(telInputInit.isValidNumber())
515
+ }
486
516
  })
487
517
  }
488
518
  }
@@ -492,12 +522,16 @@ const PhoneNumberInput = (props: PhoneNumberInputProps, ref?: React.Ref<unknown>
492
522
  dark,
493
523
  "data-phone-number": JSON.stringify(selectedData),
494
524
  disabled,
495
- error: hasTyped ? error : props.error || displayError,
525
+ error: displayError || props.error || "",
496
526
  type: 'tel',
497
527
  id,
498
528
  label,
499
529
  name,
500
- onBlur: validateErrors,
530
+ onBlur: () => {
531
+ hasBlurredRef.current = true
532
+ setHasBlurred(true)
533
+ validateErrors()
534
+ },
501
535
  onChange: formatAsYouType ? undefined : handleOnChange,
502
536
  value: inputValue
503
537
  }
@@ -1,12 +1,42 @@
1
1
  <form id="example-form-validation" action="" method="get">
2
- <%= pb_rails("phone_number_input", props: { error: "Missing phone number", id: "validation", initial_country: "af", value: "", required: true }) %>
2
+ <%= pb_rails("phone_number_input", props: {
3
+ id: "validation",
4
+ initial_country: "af",
5
+ value: "",
6
+ required: true
7
+ }) %>
3
8
  <%= pb_rails("button", props: {html_type: "submit", text: "Save Phone Number"}) %>
4
9
  </form>
5
10
 
6
11
  <%= javascript_tag do %>
7
12
  document.addEventListener('DOMContentLoaded', function () {
8
- document.querySelector('#example-form-validation').addEventListener('submit', function (e) {
9
- if (e.target.querySelectorAll('[error]:not([error=""])').length > 0) e.preventDefault();
10
- })
13
+ const form = document.querySelector('#example-form-validation');
14
+
15
+ // Wait for React component to mount
16
+ function waitForComponent() {
17
+ const phoneInput = form.querySelector('#validation');
18
+
19
+ if (!phoneInput) {
20
+ setTimeout(waitForComponent, 100);
21
+ return;
22
+ }
23
+
24
+ // Wait for intl-tel-input to initialize, then focus and blur to trigger validation
25
+ setTimeout(function() {
26
+ phoneInput.focus({ preventScroll: true });
27
+ setTimeout(function() {
28
+ phoneInput.blur();
29
+ }, 100);
30
+ }, 500);
31
+ }
32
+
33
+ waitForComponent();
34
+
35
+ // Prevent form submission if there are validation errors
36
+ form.addEventListener('submit', function (e) {
37
+ if (e.target.querySelectorAll('[error]:not([error=""])').length > 0) {
38
+ e.preventDefault();
39
+ }
40
+ });
11
41
  })
12
42
  <% end %>
@@ -10,8 +10,19 @@ const PhoneNumberInputValidation = (props) => {
10
10
  const [showFormErrors, setShowFormErrors] = useState(false);
11
11
  const [phoneNumber, setPhoneNumber] = useState("");
12
12
  const [countryCode, setCountryCode] = useState("af");
13
+ const [isValid, setIsValid] = useState(false);
14
+ const [hasInteracted, setHasInteracted] = useState(false);
15
+
16
+ // Start with initial error - will be cleared on blur if valid
17
+ const initialError = (
18
+ <>
19
+ <Icon icon="warning" /> Missing phone number.
20
+ </>
21
+ );
13
22
 
14
23
  const handleOnValidate = (valid) => {
24
+ setIsValid(valid);
25
+ setHasInteracted(true);
15
26
  setFormErrors(
16
27
  valid ? "" : "Please correct the fields below and try again."
17
28
  );
@@ -23,18 +34,16 @@ const PhoneNumberInputValidation = (props) => {
23
34
  };
24
35
 
25
36
  const handleOnSubmit = (e) => {
26
- if (showFormErrors) e.preventDefault()
37
+ if (!isValid) e.preventDefault()
27
38
  }
28
39
 
29
40
  useEffect(() => {
30
41
  setShowFormErrors(formErrors.length > 0);
31
42
  }, [formErrors]);
32
43
 
33
- const error = (
34
- <>
35
- <Icon icon="warning" /> Missing phone number.
36
- </>
37
- )
44
+ // Only show error prop initially, or if invalid after interaction
45
+ // Clear error prop once valid (component handles validation on blur)
46
+ const shouldShowError = !hasInteracted || (hasInteracted && !isValid);
38
47
 
39
48
  return (
40
49
  <form
@@ -50,7 +59,7 @@ const PhoneNumberInputValidation = (props) => {
50
59
  />
51
60
  )}
52
61
  <PhoneNumberInput
53
- error={error}
62
+ error={shouldShowError ? initialError : undefined}
54
63
  id="validation"
55
64
  initialCountry={countryCode}
56
65
  onChange={handleOnChange}