x-ui-design 0.6.99 → 0.7.21

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.
@@ -2,7 +2,7 @@ import { ReactElement } from 'react';
2
2
  import { SelectProps } from '../../types/select';
3
3
  import './style.css';
4
4
  declare const Select: {
5
- ({ prefixCls, prefixClsV3, id, searchValue, autoClearSearchValue, filterOption, optionFilterProp, children, options, listHeight, menuItemSelectedIcon, mode, value, defaultValue, maxCount, disabled, loading, placeholder, allowClear, filterable, defaultOpen, size, error, dropdownClassName, className, suffixIcon, searchIcon, style, showSearch, open, closeFromParent, showArrow, notFoundContent, noStyle, feedbackIcons, placement, removeIcon, maxTagCount, iconClickClear, onSearch, onSelect, onDeselect, onClear, onChange, onClose, tagRender, getPopupContainer, dropdownRender, onDropdownVisibleChange, iconClick, ref }: SelectProps): ReactElement;
5
+ ({ prefixCls, prefixClsV3, id, searchValue, autoClearSearchValue, filterOption, optionFilterProp, children, options, listHeight, menuItemSelectedIcon, mode, value, defaultValue, maxCount, disabled, loading, placeholder, allowClear, filterable, defaultOpen, size, error, dropdownClassName, className, suffixIcon, searchIcon, style, showSearch, open, closeFromParent, showArrow, notFoundContent, noStyle, feedbackIcons, placement, removeIcon, maxTagCount, iconClickClear, onSearch, onSelect, onDeselect, onClear, onChange, onClose, tagRender, getPopupContainer, dropdownRender, onDropdownVisibleChange, iconClick, ref, controlled }: SelectProps): ReactElement;
6
6
  displayName: string;
7
7
  };
8
8
  export default Select;
@@ -51,6 +51,7 @@ export type SelectProps = DefaultProps & {
51
51
  maxTagCount?: number | 'responsive';
52
52
  ref?: ForwardedRef<HTMLDivElement>;
53
53
  closeFromParent?: boolean;
54
+ controlled?: boolean;
54
55
  };
55
56
  export interface OptionType {
56
57
  value: RuleType;
package/dist/index.esm.js CHANGED
@@ -697,7 +697,15 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
697
697
  }
698
698
  });
699
699
  } else {
700
- errorsRef.current[name] = errors;
700
+ if (reset === -1) {
701
+ setTimeout(() => {
702
+ errorsRef.current[name] = errors;
703
+ notifyErrorSubscribers(name);
704
+ }, 0);
705
+ } else {
706
+ errorsRef.current[name] = errors;
707
+ notifyErrorSubscribers(name);
708
+ }
701
709
  }
702
710
  }
703
711
  function setFieldsValue(values, reset) {
@@ -708,7 +716,7 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
708
716
  name,
709
717
  value,
710
718
  errors
711
- }) => setFieldValue(Array.isArray(name) ? name[0] : name, value, errors));
719
+ }) => setFieldValue(Array.isArray(name) ? name[0] : name, value ?? getFieldValue(Array.isArray(name) ? name[0] : name), errors, -1));
712
720
  }
713
721
  function setFieldInstance(fieldName, fieldRef) {
714
722
  fieldInstancesRef.current[fieldName] = fieldRef;
@@ -1097,7 +1105,7 @@ const FormItem$1 = ({
1097
1105
  if (initialValue && getFieldValue(name) === undefined) {
1098
1106
  setFieldValue(name, initialValue);
1099
1107
  }
1100
- }, []);
1108
+ }, [name]);
1101
1109
  useEffect(() => {
1102
1110
  if (name && dependencies.length > 0) {
1103
1111
  const unsubscribe = subscribeToFields(dependencies, () => {
@@ -3499,7 +3507,8 @@ const Select = ({
3499
3507
  dropdownRender,
3500
3508
  onDropdownVisibleChange,
3501
3509
  iconClick,
3502
- ref
3510
+ ref,
3511
+ controlled
3503
3512
  }) => {
3504
3513
  const asTag = mode === 'tags';
3505
3514
  const asMultiple = mode === 'multiple';
@@ -3689,26 +3698,26 @@ const Select = ({
3689
3698
  return;
3690
3699
  }
3691
3700
  const newSelection = selected.includes(optionValue) ? selected.filter(item => item !== optionValue) : [...selected, optionValue];
3692
- setSelected(newSelection);
3701
+ !controlled && setSelected(newSelection);
3693
3702
  onChange?.(newSelection, option);
3694
3703
  if (selected.includes(optionValue)) {
3695
- onDeselect?.(optionValue, option);
3704
+ !controlled && onDeselect?.(optionValue, option);
3696
3705
  } else {
3697
- onSelect?.(optionValue, option);
3706
+ !controlled && onSelect?.(optionValue, option);
3698
3707
  }
3699
3708
  } else {
3700
3709
  setIsOpen(defaultOpen);
3701
- setSelected(optionValue);
3710
+ !controlled && setSelected(optionValue);
3702
3711
  onChange?.(optionValue, option);
3703
- onSelect?.(optionValue, option);
3712
+ !controlled && onSelect?.(optionValue, option);
3704
3713
  }
3705
3714
  handleClearInputValue();
3706
3715
  };
3707
3716
  const handleClear = () => {
3708
3717
  const value = hasMode ? [] : '';
3709
- setSelected(value);
3718
+ !controlled && setSelected(value);
3710
3719
  onChange?.('');
3711
- onSelect?.('');
3720
+ !controlled && onSelect?.('');
3712
3721
  onClear?.();
3713
3722
  handleClearInputValue();
3714
3723
  };