@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 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
- const error = validateInput({
795
- value: inputValue,
796
- type,
797
- maxLength,
798
- errorMessage,
799
- required,
800
- }) || '';
801
- setInputError(error);
794
+ // Se 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(reactIcons.Dismiss16Regular, { className: styles$j['zds-textfield__icon'], onClick: clearInput, "aria-label": "Limpar campo", onMouseDown: (e) => e.preventDefault() }))] }), jsxRuntime.jsx("span", { id: helperId, className: styles$j['zds-textfield__helper-text'], "aria-live": inputError ? 'polite' : undefined, children: helperContent })] })] }));
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';