@jobber/components-native 0.90.0 → 0.90.1-JOB-140976-20bb6ae.11

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.
@@ -4,6 +4,7 @@ import {
4
4
  fireEvent,
5
5
  render,
6
6
  renderHook,
7
+ screen,
7
8
  waitFor,
8
9
  } from "@testing-library/react-native";
9
10
  import type { TextStyle } from "react-native";
@@ -548,6 +549,80 @@ describe("InputText", () => {
548
549
  expect(styleOverride.inputText.color).toEqual(flattenedStyle.color);
549
550
  });
550
551
  });
552
+
553
+ describe("showMiniLabel", () => {
554
+ it("defaults to true", () => {
555
+ const props = { placeholder: "placeholder", value: "value" };
556
+ renderInputText(props);
557
+ expect(
558
+ screen.getByText("placeholder", { includeHiddenElements: true }),
559
+ ).toBeDefined();
560
+ expect(MockInputFieldWrapper).toHaveBeenCalledWith(
561
+ expect.objectContaining({
562
+ placeholderMode: "mini",
563
+ }),
564
+ );
565
+ });
566
+
567
+ describe("when true", () => {
568
+ it("renders the placeholder in its normal position when the input has no value", () => {
569
+ const props = { showMiniLabel: true, placeholder: "placeholder" };
570
+ renderInputText(props);
571
+ expect(
572
+ screen.getByText("placeholder", { includeHiddenElements: true }),
573
+ ).toBeDefined();
574
+ expect(MockInputFieldWrapper).toHaveBeenCalledWith(
575
+ expect.objectContaining({
576
+ placeholderMode: "normal",
577
+ }),
578
+ );
579
+ });
580
+
581
+ it("renders the placeholder as a mini label when the input has a value", () => {
582
+ const props = {
583
+ showMiniLabel: true,
584
+ placeholder: "placeholder",
585
+ value: "value",
586
+ };
587
+ renderInputText(props);
588
+ expect(
589
+ screen.getByText("placeholder", { includeHiddenElements: true }),
590
+ ).toBeDefined();
591
+ expect(MockInputFieldWrapper).toHaveBeenCalledWith(
592
+ expect.objectContaining({
593
+ placeholderMode: "mini",
594
+ }),
595
+ );
596
+ });
597
+ });
598
+
599
+ describe("when false", () => {
600
+ it("renders the placeholder in its normal position when the input has no value", () => {
601
+ const props = { showMiniLabel: false, placeholder: "placeholder" };
602
+ renderInputText(props);
603
+ expect(
604
+ screen.getByText("placeholder", { includeHiddenElements: true }),
605
+ ).toBeDefined();
606
+ expect(MockInputFieldWrapper).toHaveBeenCalledWith(
607
+ expect.objectContaining({
608
+ placeholderMode: "normal",
609
+ }),
610
+ );
611
+ });
612
+
613
+ it("does not render the placeholder when the input has a value", () => {
614
+ const props = {
615
+ showMiniLabel: false,
616
+ placeholder: "placeholder",
617
+ value: "value",
618
+ };
619
+ renderInputText(props);
620
+ expect(
621
+ screen.queryByText("placeholder", { includeHiddenElements: true }),
622
+ ).toBeNull();
623
+ });
624
+ });
625
+ });
551
626
  });
552
627
 
553
628
  describe("Transform", () => {
@@ -65,6 +65,15 @@ export interface InputTextProps
65
65
  */
66
66
  readonly assistiveText?: string;
67
67
 
68
+ /**
69
+ * Controls the visibility of the mini label that appears inside the input
70
+ * when a value is entered. By default, the placeholder text moves up to
71
+ * become a mini label. Set to false to disable this behavior.
72
+ *
73
+ * @default true
74
+ */
75
+ readonly showMiniLabel?: boolean;
76
+
68
77
  /**
69
78
  * Determines what keyboard is shown
70
79
  */
@@ -245,6 +254,7 @@ function InputTextInternal(
245
254
  name,
246
255
  placeholder,
247
256
  assistiveText,
257
+ showMiniLabel = true,
248
258
  keyboard,
249
259
  value: controlledValue,
250
260
  defaultValue,
@@ -292,7 +302,8 @@ function InputTextInternal(
292
302
 
293
303
  const hasValue = internalValue !== "" && internalValue !== undefined;
294
304
  const [focused, setFocused] = useState(false);
295
- const { hasMiniLabel } = useMiniLabel(internalValue);
305
+ const placeholderMode = getPlaceholderMode(showMiniLabel, internalValue);
306
+ const miniLabelActive = placeholderMode === "mini";
296
307
 
297
308
  const textInputRef = useTextInputRef({ ref, onClear: handleClear });
298
309
 
@@ -367,7 +378,7 @@ function InputTextInternal(
367
378
  prefix={prefix}
368
379
  suffix={suffix}
369
380
  hasValue={hasValue}
370
- hasMiniLabel={hasMiniLabel}
381
+ placeholderMode={placeholderMode}
371
382
  assistiveText={assistiveText}
372
383
  focused={focused}
373
384
  error={error}
@@ -391,11 +402,11 @@ function InputTextInternal(
391
402
  style={[
392
403
  commonInputStyles.input,
393
404
  styles.inputPaddingTop,
394
- !hasMiniLabel && commonInputStyles.inputEmpty,
405
+ !miniLabelActive && commonInputStyles.inputEmpty,
395
406
  disabled && commonInputStyles.inputDisabled,
396
407
  multiline && styles.multiLineInput,
397
408
  multiline && Platform.OS === "ios" && styles.multilineInputiOS,
398
- multiline && hasMiniLabel && styles.multiLineInputWithMini,
409
+ multiline && miniLabelActive && styles.multiLineInputWithMini,
399
410
  styleOverride?.inputText,
400
411
  loading && loadingType === "glimmer" && { color: "transparent" },
401
412
  ]}
@@ -510,13 +521,19 @@ function useTextInputRef({ ref, onClear }: UseTextInputRefProps) {
510
521
  return textInputRef;
511
522
  }
512
523
 
513
- function useMiniLabel(internalValue: string): {
514
- hasMiniLabel: boolean;
515
- } {
516
- const [hasMiniLabel, setHasMiniLabel] = useState(Boolean(internalValue));
517
- useEffect(() => {
518
- setHasMiniLabel(Boolean(internalValue));
519
- }, [internalValue]);
524
+ function getPlaceholderMode(
525
+ isMiniLabelAllowed: boolean,
526
+ internalValue: string,
527
+ ): InputFieldWrapperProps["placeholderMode"] {
528
+ const hasValue = Boolean(internalValue);
520
529
 
521
- return { hasMiniLabel };
530
+ if (hasValue) {
531
+ if (isMiniLabelAllowed) {
532
+ return "mini";
533
+ } else {
534
+ return "hidden";
535
+ }
536
+ } else {
537
+ return "normal";
538
+ }
522
539
  }