fis-component 0.0.84 → 0.0.86
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 +35 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +35 -6
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -64947,13 +64947,42 @@ FISInputLabel.displayName = "FISInputLabel";
|
|
|
64947
64947
|
|
|
64948
64948
|
const FISInputText = React.forwardRef((props, ref) => {
|
|
64949
64949
|
const { className, typeSuffix, textLabel = "", iconLabel, required, iconPrefix, sizeInput, showCount, message, negative, positive, maxLength = 500, disabled, onChange, onEnter, onKeyDown, onClickIconLabel, onClickSuffix, ...rest } = props;
|
|
64950
|
-
|
|
64950
|
+
// Internal ref to access DOM element when external ref is not provided
|
|
64951
|
+
const internalRef = React.useRef(null);
|
|
64952
|
+
const inputRef = ref || internalRef;
|
|
64953
|
+
const [internalValue, setInternalValue] = React.useState(rest.value || rest.defaultValue || "");
|
|
64954
|
+
// State to trigger re-render for character count (React Hook Form compatibility)
|
|
64955
|
+
const [, forceUpdate] = React.useReducer((x) => x + 1, 0);
|
|
64956
|
+
// Sync internal value with controlled value prop
|
|
64957
|
+
React.useEffect(() => {
|
|
64958
|
+
if (rest.value !== undefined) {
|
|
64959
|
+
setInternalValue(rest.value);
|
|
64960
|
+
}
|
|
64961
|
+
}, [rest.value]);
|
|
64962
|
+
// Get current value for display (controlled vs uncontrolled)
|
|
64963
|
+
const getCurrentValue = () => {
|
|
64964
|
+
// Controlled mode: use value prop
|
|
64965
|
+
if (rest.value !== undefined) {
|
|
64966
|
+
return rest.value;
|
|
64967
|
+
}
|
|
64968
|
+
// Uncontrolled mode: use internal state, fallback to DOM value for React Hook Form
|
|
64969
|
+
return internalValue ?? inputRef.current?.value ?? "";
|
|
64970
|
+
};
|
|
64951
64971
|
const handleChange = React.useCallback((event) => {
|
|
64952
|
-
|
|
64972
|
+
const newValue = event.target.value;
|
|
64973
|
+
// Only update internal state if not controlled
|
|
64974
|
+
if (rest.value === undefined) {
|
|
64975
|
+
setInternalValue(newValue);
|
|
64976
|
+
}
|
|
64977
|
+
else {
|
|
64978
|
+
// Force re-render for character count when using React Hook Form
|
|
64979
|
+
// This ensures character count updates even when value prop doesn't change
|
|
64980
|
+
forceUpdate();
|
|
64981
|
+
}
|
|
64953
64982
|
if (onChange) {
|
|
64954
64983
|
onChange(event);
|
|
64955
64984
|
}
|
|
64956
|
-
}, [onChange]);
|
|
64985
|
+
}, [onChange, rest.value, forceUpdate]);
|
|
64957
64986
|
const handleKeyPress = React.useCallback((event) => {
|
|
64958
64987
|
if (!event)
|
|
64959
64988
|
return;
|
|
@@ -64963,13 +64992,13 @@ const FISInputText = React.forwardRef((props, ref) => {
|
|
|
64963
64992
|
}
|
|
64964
64993
|
}
|
|
64965
64994
|
}, [onEnter]);
|
|
64966
|
-
return (jsxRuntime.jsxs(DivContainerSC$6, { className: className, children: [(textLabel || iconLabel) && (jsxRuntime.jsx(FISInputLabel, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsxRuntime.jsx(FISInputField, { ...rest, ref:
|
|
64995
|
+
return (jsxRuntime.jsxs(DivContainerSC$6, { className: className, children: [(textLabel || iconLabel) && (jsxRuntime.jsx(FISInputLabel, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsxRuntime.jsx(FISInputField, { ...rest, ref: inputRef, typeSuffix: typeSuffix, sizeInput: sizeInput, iconPrefix: iconPrefix, onKeyPress: handleKeyPress, onChange: handleChange, disabled: disabled, negative: negative, maxLength: maxLength, onClickSuffix: onClickSuffix }), (message || showCount) && (jsxRuntime.jsxs(DivHintWrapperSC$1, { children: [jsxRuntime.jsx(SpanHintSC$3, { className: classNames({
|
|
64967
64996
|
disabled: disabled,
|
|
64968
64997
|
negative: negative,
|
|
64969
64998
|
positive: positive,
|
|
64970
64999
|
}), children: message ? message : "" }), showCount && maxLength > 0 && (jsxRuntime.jsxs(SpanCountSC, { className: classNames({
|
|
64971
|
-
negative:
|
|
64972
|
-
}), children: [
|
|
65000
|
+
negative: getCurrentValue()?.length > maxLength,
|
|
65001
|
+
}), children: [getCurrentValue()?.length, "/", maxLength] }))] }))] }));
|
|
64973
65002
|
});
|
|
64974
65003
|
FISInputText.displayName = "FISInputText";
|
|
64975
65004
|
|