@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.esm.js
CHANGED
|
@@ -771,14 +771,17 @@ const TextField = ({ name = 'textfield', className = '', value = '', label = '',
|
|
|
771
771
|
}
|
|
772
772
|
}, [disabled, onChange]);
|
|
773
773
|
const onBlur = useCallback(() => {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
774
|
+
// Se já existe um errorMessage externo, não validar internamente
|
|
775
|
+
if (!errorMessage) {
|
|
776
|
+
const error = validateInput({
|
|
777
|
+
value: inputValue,
|
|
778
|
+
type,
|
|
779
|
+
maxLength,
|
|
780
|
+
errorMessage,
|
|
781
|
+
required,
|
|
782
|
+
}) || '';
|
|
783
|
+
setInputError(error);
|
|
784
|
+
}
|
|
782
785
|
setFocus(false);
|
|
783
786
|
}, [inputValue, type, maxLength, errorMessage, required]);
|
|
784
787
|
useEffect(() => {
|
|
@@ -786,6 +789,15 @@ const TextField = ({ name = 'textfield', className = '', value = '', label = '',
|
|
|
786
789
|
setValue(value);
|
|
787
790
|
}
|
|
788
791
|
}, [value]);
|
|
792
|
+
// Sincroniza errorMessage externo com estado interno
|
|
793
|
+
useEffect(() => {
|
|
794
|
+
if (errorMessage) {
|
|
795
|
+
setInputError(errorMessage);
|
|
796
|
+
}
|
|
797
|
+
else if (!errorMessage && inputError && !required) {
|
|
798
|
+
setInputError('');
|
|
799
|
+
}
|
|
800
|
+
}, [errorMessage]);
|
|
789
801
|
const TextFieldClass = clsx(styles$j['zds-textfield__container'], {
|
|
790
802
|
[styles$j['zds-textfield__error']]: inputError,
|
|
791
803
|
[styles$j['zds-textfield__disabled']]: disabled,
|
|
@@ -799,7 +811,7 @@ const TextField = ({ name = 'textfield', className = '', value = '', label = '',
|
|
|
799
811
|
: helper && helperText
|
|
800
812
|
? `${componentId}-helper`
|
|
801
813
|
: undefined;
|
|
802
|
-
return (jsxs("div", { className: TextFieldClass, children: [label && (jsx("label", { htmlFor: componentId, className: styles$j['zds-textfield__wrapper-label'], children: tooltip ? (jsx(Tooltip, { text: tooltipText, position: positionTooltip, children: jsxs("div", { className: styles$j['zds-textfield__container-tooltip'], children: [label, required && jsx("span", { className: styles$j['zds-textfield__required'], children: "*" }), jsx(Info12Regular, { className: styles$j['zds-textfield__tooltip'] })] }) })) : (jsxs("div", { className: styles$j['zds-textfield__container-tooltip'], children: [label, required && jsx("span", { className: styles$j['zds-textfield__required'], children: "*" })] })) })), jsxs("div", { className: styles$j['zds-textfield__container__box'], children: [jsxs("div", { className: styles$j['zds-textfield__box__input'], children: [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 && (jsx("span", { className: styles$j['zds-textfield__icon'], children: icon })), shouldRenderClearIcon && (jsx(
|
|
814
|
+
return (jsxs("div", { className: TextFieldClass, children: [label && (jsx("label", { htmlFor: componentId, className: styles$j['zds-textfield__wrapper-label'], children: tooltip ? (jsx(Tooltip, { text: tooltipText, position: positionTooltip, children: jsxs("div", { className: styles$j['zds-textfield__container-tooltip'], children: [label, required && jsx("span", { className: styles$j['zds-textfield__required'], children: "*" }), jsx(Info12Regular, { className: styles$j['zds-textfield__tooltip'] })] }) })) : (jsxs("div", { className: styles$j['zds-textfield__container-tooltip'], children: [label, required && jsx("span", { className: styles$j['zds-textfield__required'], children: "*" })] })) })), jsxs("div", { className: styles$j['zds-textfield__container__box'], children: [jsxs("div", { className: styles$j['zds-textfield__box__input'], children: [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 && (jsx("span", { className: styles$j['zds-textfield__icon'], children: icon })), shouldRenderClearIcon && (jsx("span", { className: styles$j['zds-textfield__icon'], onClick: clearInput, onMouseDown: (e) => e.preventDefault(), role: "button", tabIndex: 0, "aria-label": "Limpar campo", children: jsx(Dismiss16Regular, {}) }))] }), jsx("span", { id: helperId, className: styles$j['zds-textfield__helper-text'], "aria-live": inputError ? 'polite' : undefined, children: helperContent })] })] }));
|
|
803
815
|
};
|
|
804
816
|
const MemoizedTextField = React__default.memo(TextField);
|
|
805
817
|
MemoizedTextField.displayName = 'TextField';
|