fis-component 0.0.87 → 0.0.89

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.
package/dist/cjs/index.js CHANGED
@@ -64974,38 +64974,23 @@ const FISInputText = React.forwardRef((props, ref) => {
64974
64974
  const { className, typeSuffix, textLabel = "", iconLabel, required, iconPrefix, sizeInput, showCount, message, negative, positive, maxLength = 500, disabled, onChange, onEnter, onKeyDown, onClickIconLabel, onClickSuffix, ...rest } = props;
64975
64975
  // Internal ref to access DOM element for character count
64976
64976
  const internalRef = React.useRef(null);
64977
- const [internalValue, setInternalValue] = React.useState(rest.value || rest.defaultValue || "");
64977
+ const [internalValue, setInternalValue] = React.useState("");
64978
64978
  // State to trigger re-render for character count (React Hook Form compatibility)
64979
64979
  const [, forceUpdate] = React.useReducer((x) => x + 1, 0);
64980
- // Sync internal value with controlled value prop
64981
- React.useEffect(() => {
64982
- if (rest.value !== undefined) {
64983
- setInternalValue(rest.value);
64984
- }
64985
- }, [rest.value]);
64986
- // Get current value for display (controlled vs uncontrolled)
64980
+ // Get current value for display (prioritize DOM for React Hook Form)
64987
64981
  const getCurrentValue = () => {
64988
- // Always prioritize DOM value for React Hook Form compatibility
64989
- const domValue = internalRef.current?.value;
64990
- if (domValue !== undefined) {
64991
- return domValue;
64992
- }
64993
- // Fallback to controlled value prop
64994
- if (rest.value !== undefined) {
64995
- return rest.value;
64996
- }
64997
- // Fallback to internal state for uncontrolled mode
64998
- return internalValue ?? "";
64982
+ return (internalRef.current?.value ??
64983
+ rest.value ??
64984
+ internalValue ??
64985
+ "");
64999
64986
  };
65000
64987
  const handleChange = React.useCallback((event) => {
65001
- const newValue = event.target.value;
65002
64988
  // Update internal state for uncontrolled mode
65003
64989
  if (rest.value === undefined) {
65004
- setInternalValue(newValue);
64990
+ setInternalValue(event.target.value);
65005
64991
  }
65006
64992
  else {
65007
64993
  // Force re-render only for controlled mode (React Hook Form case)
65008
- // This ensures character count updates when value prop doesn't change
65009
64994
  forceUpdate();
65010
64995
  }
65011
64996
  if (onChange) {
@@ -66058,13 +66043,26 @@ styled.div `
66058
66043
  const FISInputArea = React.forwardRef((props, ref) => {
66059
66044
  const { className, required = false, textLabel = "", iconLabel, iconSuffix, disabled = false, readOnly = false, negative, message, positive, maxLength = 50, showCount, size = "md", fixedWidth, onClickIconLabel, onClickIconSuffix, onChange, onEnter, ...rest } = props;
66060
66045
  const [internalValue, setInternalValue] = React.useState("");
66046
+ // State to trigger re-render for character count (React Hook Form compatibility)
66047
+ const [, forceUpdate] = React.useReducer((x) => x + 1, 0);
66061
66048
  const inputRef = React.useRef(null);
66049
+ // Get current value for display (prioritize DOM for React Hook Form)
66050
+ const getCurrentValue = () => {
66051
+ return (inputRef.current?.value ?? rest.value ?? internalValue ?? "");
66052
+ };
66062
66053
  const handleChange = React.useCallback((event) => {
66063
- setInternalValue(event.target.value);
66054
+ // Update internal state for uncontrolled mode
66055
+ if (rest.value === undefined) {
66056
+ setInternalValue(event.target.value);
66057
+ }
66058
+ else {
66059
+ // Force re-render only for controlled mode (React Hook Form case)
66060
+ forceUpdate();
66061
+ }
66064
66062
  if (onChange) {
66065
66063
  onChange(event);
66066
66064
  }
66067
- }, [onChange]);
66065
+ }, [onChange, rest.value]);
66068
66066
  const handleKeyPress = React.useCallback((event) => {
66069
66067
  if (!event)
66070
66068
  return;
@@ -66074,28 +66072,6 @@ const FISInputArea = React.forwardRef((props, ref) => {
66074
66072
  }
66075
66073
  }
66076
66074
  }, [onEnter]);
66077
- React.useImperativeHandle(ref, () => {
66078
- const inputElement = inputRef.current;
66079
- return {
66080
- ...inputElement,
66081
- focus: () => {
66082
- if (inputRef.current) {
66083
- inputRef.current.focus();
66084
- }
66085
- },
66086
- blur: () => {
66087
- if (inputRef.current) {
66088
- inputRef.current.blur();
66089
- }
66090
- },
66091
- clear: () => {
66092
- if (inputRef.current) {
66093
- inputRef.current.value = "";
66094
- setInternalValue("");
66095
- }
66096
- },
66097
- };
66098
- });
66099
66075
  const handleResize = (e) => {
66100
66076
  e.preventDefault();
66101
66077
  e.stopPropagation();
@@ -66136,7 +66112,7 @@ const FISInputArea = React.forwardRef((props, ref) => {
66136
66112
  "input-area-lg": size === "lg",
66137
66113
  "input-area-icon": iconSuffix,
66138
66114
  negative,
66139
- }), style: { width: fixedWidth ? `${fixedWidth}px` : "auto" }, children: [jsxRuntime.jsx(TextAreaSC, { ...rest, onChange: handleChange, onKeyDown: handleKeyPress, ref: inputRef, disabled: disabled, className: classNames({
66115
+ }), style: { width: fixedWidth ? `${fixedWidth}px` : "auto" }, children: [jsxRuntime.jsx(TextAreaSC, { ...rest, onChange: handleChange, onKeyDown: handleKeyPress, ref: mergeRefs(ref, inputRef), disabled: disabled, className: classNames({
66140
66116
  negative,
66141
66117
  "input-area-lg": size === "lg",
66142
66118
  "input-area-icon": iconSuffix,
@@ -66147,8 +66123,8 @@ const FISInputArea = React.forwardRef((props, ref) => {
66147
66123
  negative,
66148
66124
  positive,
66149
66125
  }), children: message ? message : "" }), jsxRuntime.jsx(DivCountSC, { children: showCount && maxLength > 0 && (jsxRuntime.jsxs("span", { className: classNames("text-area__count", {
66150
- negative: internalValue.length > maxLength,
66151
- }), children: [internalValue?.replaceAll("\n", "")?.length, "/", maxLength] })) })] })] }));
66126
+ negative: getCurrentValue()?.length > maxLength,
66127
+ }), children: [getCurrentValue()?.length, "/", maxLength] })) })] })] }));
66152
66128
  });
66153
66129
  FISInputArea.displayName = "FISInputArea";
66154
66130
 
@@ -73686,45 +73662,21 @@ const FISSelect = React.forwardRef(({ className, style, size = "md", options, va
73686
73662
  strategy: "fixed",
73687
73663
  }), []);
73688
73664
  const { styles, attributes } = usePopper(referenceElement, popperElement, popperOptions);
73689
- const originalOptionsRef = React.useRef(options);
73690
- React.useEffect(() => {
73691
- // Keep track of all items including selected ones
73692
- const allItems = new Map();
73693
- // Add items from current options
73694
- options.forEach((group) => {
73695
- group.items.forEach((item) => {
73696
- allItems.set(item.value, item);
73697
- });
73698
- });
73699
- // Add selected items that might not be in current options
73700
- if (multi && Array.isArray(value)) {
73701
- const selectedItems = originalOptionsRef.current
73702
- .flatMap((group) => group.items)
73703
- .filter((item) => value.includes(item.value));
73704
- selectedItems.forEach((item) => {
73705
- allItems.set(item.value, item);
73706
- });
73707
- }
73708
- // Update originalOptionsRef with all items
73709
- originalOptionsRef.current = [
73710
- {
73711
- items: Array.from(allItems.values()),
73712
- },
73713
- ];
73714
- }, [options, value, multi]);
73715
73665
  const selectedItems = React.useMemo(() => {
73716
73666
  const allItems = options.flatMap((group) => group.items);
73717
73667
  if (multi) {
73718
- return allItems.filter((item) => value.includes(item.value));
73668
+ const selectedArray = Array.isArray(value) ? value : [];
73669
+ return allItems.filter((item) => selectedArray.includes(item.value));
73719
73670
  }
73720
73671
  else {
73721
73672
  const found = allItems.find((item) => item.value === value);
73722
73673
  return found ? [found] : [];
73723
73674
  }
73724
73675
  }, [value, multi, options]);
73725
- const computedDisplayValue = () => {
73676
+ const computedDisplayValue = React.useMemo(() => {
73726
73677
  if (multi) {
73727
- const count = value.length;
73678
+ const selectedArray = Array.isArray(value) ? value : [];
73679
+ const count = selectedArray.length;
73728
73680
  if (count === 0) {
73729
73681
  return "";
73730
73682
  }
@@ -73733,17 +73685,18 @@ const FISSelect = React.forwardRef(({ className, style, size = "md", options, va
73733
73685
  : `Selected ${count.toString().padStart(2, "0")} option${count !== 1 ? "s" : ""}`;
73734
73686
  }
73735
73687
  else {
73736
- if (!selectedItems[0])
73688
+ const firstItem = selectedItems[0];
73689
+ if (!firstItem)
73737
73690
  return "";
73738
- return (displayValue?.(selectedItems[0]) || selectedItems[0].label);
73691
+ return displayValue?.(firstItem) || firstItem.label;
73739
73692
  }
73740
- };
73693
+ }, [multi, value, multiDisplayText, selectedItems, displayValue]);
73741
73694
  const handleToggle = React.useCallback(() => {
73742
73695
  if (!disabled)
73743
73696
  setIsOpen((prev) => !prev);
73744
73697
  }, [disabled]);
73745
73698
  const handleOptionRemove = React.useCallback((option) => {
73746
- if (multi) {
73699
+ if (multi && Array.isArray(value)) {
73747
73700
  const newValues = value.filter((v) => v !== option.value);
73748
73701
  onChange(newValues);
73749
73702
  }
@@ -73771,8 +73724,10 @@ const FISSelect = React.forwardRef(({ className, style, size = "md", options, va
73771
73724
  multi,
73772
73725
  size: isMenuSize(size) ? size : "md",
73773
73726
  selectedValues: multi
73774
- ? value
73775
- : value
73727
+ ? Array.isArray(value)
73728
+ ? value
73729
+ : []
73730
+ : value !== undefined && value !== null
73776
73731
  ? [value]
73777
73732
  : [],
73778
73733
  onChangeSelected: handleMenuChange,
@@ -73796,18 +73751,21 @@ const FISSelect = React.forwardRef(({ className, style, size = "md", options, va
73796
73751
  restProps,
73797
73752
  ]);
73798
73753
  React.useEffect(() => {
73754
+ if (!isOpen)
73755
+ return;
73799
73756
  const handleClickOutside = (event) => {
73757
+ const target = event.target;
73800
73758
  if (referenceElement &&
73801
- !referenceElement.contains(event.target) &&
73759
+ !referenceElement.contains(target) &&
73802
73760
  popperElement &&
73803
- !popperElement.contains(event.target)) {
73761
+ !popperElement.contains(target)) {
73804
73762
  setIsOpen(false);
73805
73763
  }
73806
73764
  };
73807
73765
  document.addEventListener("mousedown", handleClickOutside);
73808
73766
  return () => document.removeEventListener("mousedown", handleClickOutside);
73809
- }, [referenceElement, popperElement]);
73810
- return (jsxRuntime.jsxs(DivWrapperSC$1, { className: className, style: style, children: [(textLabel || iconLabel) && (jsxRuntime.jsx(FISInputLabel, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsxRuntime.jsx(DivInputWrapperSC, { ref: setReferenceElement, onClick: handleToggle, "$hasValue": !!value, children: jsxRuntime.jsx(FISSelectItem, { ...restProps, ref: ref, size: size, placeholder: placeholder, iconSuffix: isOpen ? jsxRuntime.jsx(ArrowUpIcon, {}) : jsxRuntime.jsx(ArrowDownIcon, {}), value: computedDisplayValue(), disabled: disabled, activeDropdown: isOpen, negative: negative }) }), message && (jsxRuntime.jsx(SpanHintSC$3, { className: classNames({ disabled, negative, positive }), children: message })), multi && value.length > 0 && (jsxRuntime.jsx(SelectedTagsWrapper, { children: jsxRuntime.jsx(MultipleValue, { options: selectedItems, onRemove: handleOptionRemove }) })), isOpen && (jsxRuntime.jsx(Portal, { portal: portal, children: jsxRuntime.jsx(DivDropdownMenuSC, { ref: setPopperElement, style: {
73767
+ }, [isOpen, referenceElement, popperElement]);
73768
+ return (jsxRuntime.jsxs(DivWrapperSC$1, { className: className, style: style, children: [(textLabel || iconLabel) && (jsxRuntime.jsx(FISInputLabel, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsxRuntime.jsx(DivInputWrapperSC, { ref: setReferenceElement, onClick: handleToggle, "$hasValue": !!value, children: jsxRuntime.jsx(FISSelectItem, { ...restProps, ref: ref, size: size, placeholder: placeholder, iconSuffix: isOpen ? jsxRuntime.jsx(ArrowUpIcon, {}) : jsxRuntime.jsx(ArrowDownIcon, {}), value: computedDisplayValue, disabled: disabled, activeDropdown: isOpen, negative: negative }) }), message && (jsxRuntime.jsx(SpanHintSC$3, { className: classNames({ disabled, negative, positive }), children: message })), multi && Array.isArray(value) && value.length > 0 && (jsxRuntime.jsx(SelectedTagsWrapper, { children: jsxRuntime.jsx(MultipleValue, { options: selectedItems, onRemove: handleOptionRemove }) })), isOpen && (jsxRuntime.jsx(Portal, { portal: portal, children: jsxRuntime.jsx(DivDropdownMenuSC, { ref: setPopperElement, style: {
73811
73769
  ...styles.popper,
73812
73770
  width: referenceElement?.offsetWidth,
73813
73771
  zIndex: 9999,