@giro-ds/react 1.0.2 → 1.0.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.
- package/dist/index.cjs +21 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +21 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -791,14 +791,17 @@ const TextField = ({ name = 'textfield', className = '', value = '', label = '',
|
|
|
791
791
|
}
|
|
792
792
|
}, [disabled, onChange]);
|
|
793
793
|
const onBlur = React.useCallback(() => {
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
794
|
+
// Se já existe um errorMessage externo, não validar internamente
|
|
795
|
+
if (!errorMessage) {
|
|
796
|
+
const error = validateInput({
|
|
797
|
+
value: inputValue,
|
|
798
|
+
type,
|
|
799
|
+
maxLength,
|
|
800
|
+
errorMessage,
|
|
801
|
+
required,
|
|
802
|
+
}) || '';
|
|
803
|
+
setInputError(error);
|
|
804
|
+
}
|
|
802
805
|
setFocus(false);
|
|
803
806
|
}, [inputValue, type, maxLength, errorMessage, required]);
|
|
804
807
|
React.useEffect(() => {
|
|
@@ -806,6 +809,15 @@ const TextField = ({ name = 'textfield', className = '', value = '', label = '',
|
|
|
806
809
|
setValue(value);
|
|
807
810
|
}
|
|
808
811
|
}, [value]);
|
|
812
|
+
// Sincroniza errorMessage externo com estado interno
|
|
813
|
+
React.useEffect(() => {
|
|
814
|
+
if (errorMessage) {
|
|
815
|
+
setInputError(errorMessage);
|
|
816
|
+
}
|
|
817
|
+
else if (!errorMessage && inputError && !required) {
|
|
818
|
+
setInputError('');
|
|
819
|
+
}
|
|
820
|
+
}, [errorMessage]);
|
|
809
821
|
const TextFieldClass = clsx(styles$j['zds-textfield__container'], {
|
|
810
822
|
[styles$j['zds-textfield__error']]: inputError,
|
|
811
823
|
[styles$j['zds-textfield__disabled']]: disabled,
|
|
@@ -819,7 +831,7 @@ const TextField = ({ name = 'textfield', className = '', value = '', label = '',
|
|
|
819
831
|
: helper && helperText
|
|
820
832
|
? `${componentId}-helper`
|
|
821
833
|
: undefined;
|
|
822
|
-
return (jsxRuntime.jsxs("div", { className: TextFieldClass, children: [label && (jsxRuntime.jsx("label", { htmlFor: componentId, className: styles$j['zds-textfield__wrapper-label'], children: tooltip ? (jsxRuntime.jsx(Tooltip, { text: tooltipText, position: positionTooltip, children: jsxRuntime.jsxs("div", { className: styles$j['zds-textfield__container-tooltip'], children: [label, required && jsxRuntime.jsx("span", { className: styles$j['zds-textfield__required'], children: "*" }), jsxRuntime.jsx(reactIcons.Info12Regular, { className: styles$j['zds-textfield__tooltip'] })] }) })) : (jsxRuntime.jsxs("div", { className: styles$j['zds-textfield__container-tooltip'], children: [label, required && jsxRuntime.jsx("span", { className: styles$j['zds-textfield__required'], children: "*" })] })) })), jsxRuntime.jsxs("div", { className: styles$j['zds-textfield__container__box'], children: [jsxRuntime.jsxs("div", { className: styles$j['zds-textfield__box__input'], children: [jsxRuntime.jsx("input", { id: componentId, name: name, type: type, value: inputValue, placeholder: placeholder, onChange: handleChange, onFocus: () => setFocus(true), onBlur: onBlur, maxLength: maxLength, disabled: disabled, "aria-invalid": !!inputError, "aria-required": required, "aria-describedby": helperId }), shouldRenderCustomIcon && (jsxRuntime.jsx("span", { className: styles$j['zds-textfield__icon'], children: icon })), shouldRenderClearIcon && (jsxRuntime.jsx(
|
|
834
|
+
return (jsxRuntime.jsxs("div", { className: TextFieldClass, children: [label && (jsxRuntime.jsx("label", { htmlFor: componentId, className: styles$j['zds-textfield__wrapper-label'], children: tooltip ? (jsxRuntime.jsx(Tooltip, { text: tooltipText, position: positionTooltip, children: jsxRuntime.jsxs("div", { className: styles$j['zds-textfield__container-tooltip'], children: [label, required && jsxRuntime.jsx("span", { className: styles$j['zds-textfield__required'], children: "*" }), jsxRuntime.jsx(reactIcons.Info12Regular, { className: styles$j['zds-textfield__tooltip'] })] }) })) : (jsxRuntime.jsxs("div", { className: styles$j['zds-textfield__container-tooltip'], children: [label, required && jsxRuntime.jsx("span", { className: styles$j['zds-textfield__required'], children: "*" })] })) })), jsxRuntime.jsxs("div", { className: styles$j['zds-textfield__container__box'], children: [jsxRuntime.jsxs("div", { className: styles$j['zds-textfield__box__input'], children: [jsxRuntime.jsx("input", { id: componentId, name: name, type: type, value: inputValue, placeholder: placeholder, onChange: handleChange, onFocus: () => setFocus(true), onBlur: onBlur, maxLength: maxLength, disabled: disabled, "aria-invalid": !!inputError, "aria-required": required, "aria-describedby": helperId }), shouldRenderCustomIcon && (jsxRuntime.jsx("span", { className: styles$j['zds-textfield__icon'], children: icon })), shouldRenderClearIcon && (jsxRuntime.jsx("span", { className: styles$j['zds-textfield__icon'], onClick: clearInput, onMouseDown: (e) => e.preventDefault(), role: "button", tabIndex: 0, "aria-label": "Limpar campo", children: jsxRuntime.jsx(reactIcons.Dismiss16Regular, {}) }))] }), jsxRuntime.jsx("span", { id: helperId, className: styles$j['zds-textfield__helper-text'], "aria-live": inputError ? 'polite' : undefined, children: helperContent })] })] }));
|
|
823
835
|
};
|
|
824
836
|
const MemoizedTextField = React.memo(TextField);
|
|
825
837
|
MemoizedTextField.displayName = 'TextField';
|