@giro-ds/react 3.0.1 → 3.0.3

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.d.ts CHANGED
@@ -676,7 +676,7 @@ declare const TablePagination: React__default.FC<TablePaginationProps>;
676
676
  type TextFieldType = 'text' | 'email' | 'password' | 'number' | 'tel' | 'url';
677
677
  interface TextFieldProps extends Omit<React__default.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'value' | 'type'> {
678
678
  /** Controlled value */
679
- value?: string;
679
+ value?: string | number;
680
680
  /** Change handler - receives string value */
681
681
  onChange?: (value: string) => void;
682
682
  /** Label text */
package/dist/index.esm.js CHANGED
@@ -676,15 +676,28 @@ const validateInput = ({ value, maxLength, errorMessage, required }) => {
676
676
  };
677
677
 
678
678
  const TextField = forwardRef(({ className, value = '', label, placeholder, type = 'text', onChange, disabled = false, maxLength = 30, required = false, helperText, tooltip = false, tooltipText = '', side = 'bottom', align = 'start', errorMessage = '', id, icon, onBlur, onFocus, name, ...inputProps }, ref) => {
679
- const [inputValue, setInputValue] = useState(value);
679
+ const normalizeValue = (val) => {
680
+ return val === undefined || val === null ? '' : String(val);
681
+ };
682
+ const [inputValue, setInputValue] = useState(normalizeValue(value));
680
683
  const [inputError, setInputError] = useState('');
681
684
  const [isFocused, setIsFocused] = useState(false);
682
685
  const generatedId = useId();
683
686
  const componentId = id || generatedId;
684
- // ✅ Sincronizar estado interno com prop value externa
685
687
  useEffect(() => {
686
- setInputValue(value);
687
- }, [value]);
688
+ const newValue = normalizeValue(value);
689
+ setInputValue(newValue);
690
+ // Reavaliar erro quando valor muda externamente (ex: DatePicker atualiza o campo)
691
+ if (inputError) {
692
+ const error = validateInput({
693
+ value: newValue,
694
+ maxLength,
695
+ errorMessage,
696
+ required,
697
+ });
698
+ setInputError(error);
699
+ }
700
+ }, [value, inputError, type, maxLength, errorMessage, required]);
688
701
  const handleChange = useCallback((e) => {
689
702
  const newValue = e.target.value;
690
703
  if (!disabled && (!maxLength || newValue.length <= maxLength)) {
@@ -2529,7 +2542,7 @@ function useSelectLogic({ value, required = false, search = false, onValueChange
2529
2542
  }
2530
2543
  }, [state.isOpen, enableApiSearch, onApiSearch]);
2531
2544
  useEffect(() => {
2532
- if (enableApiSearch && state.searchTerm && state.isOpen) {
2545
+ if (enableApiSearch && state.isOpen) {
2533
2546
  if (lastSearchTermRef.current !== state.searchTerm) {
2534
2547
  debouncedApiSearch(state.searchTerm);
2535
2548
  }
@@ -2720,25 +2733,28 @@ const Select = ({ items, onValueChange, onOpenChange, variant, required = false,
2720
2733
  maxWidth: maxWidth ? `${maxWidth}px` : undefined,
2721
2734
  }), [maxWidth]);
2722
2735
  const handleSearchChange = (e) => {
2723
- actions.setSearchInput(e.target.value);
2736
+ const value = e.target.value;
2737
+ actions.setSearchInput(value);
2738
+ if (enableApiSearch) {
2739
+ actions.setSearchTerm(value);
2740
+ }
2724
2741
  };
2725
2742
  const handleSearchKeyDown = (e) => {
2743
+ const isNavigationKey = ['ArrowDown', 'ArrowUp', 'Enter', 'Escape', 'Tab'].includes(e.key);
2744
+ if (!isNavigationKey) {
2745
+ e.stopPropagation();
2746
+ return;
2747
+ }
2726
2748
  if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
2727
- const input = e.currentTarget;
2728
- const hasSelection = input.selectionStart !== input.selectionEnd;
2729
- if (!hasSelection) {
2730
- e.preventDefault();
2731
- return;
2732
- }
2749
+ e.currentTarget.blur();
2750
+ return;
2733
2751
  }
2734
2752
  if (e.key === 'Enter') {
2735
- e.preventDefault();
2736
- e.stopPropagation();
2737
- actions.setSearchTerm(state.searchInput);
2753
+ e.currentTarget.blur();
2754
+ return;
2738
2755
  }
2739
- if (e.key === 'Escape') {
2756
+ else if (e.key === 'Escape') {
2740
2757
  e.preventDefault();
2741
- e.stopPropagation();
2742
2758
  actions.resetSearch();
2743
2759
  }
2744
2760
  };