Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Form bind this in form-item #148

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/arcodesign/components/_helpers/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export function useListenResize(resizeHandler: () => void, deps: any[] = [], nee
* @desc {en} Tips: Use in scenarios where asynchronous processing is not completed after unmount. It is not recommended to replace useState without brains
* @param initialState 初始状态
* @param initialState {en} Initial State
* @example
* ```
* import { useMountedState } from '@arco-design/mobile-react/esm/_helpers/hooks';
*
* const [scrollValue, setScrollValue] = useMountedState(value);
* ```
*/
export function useMountedState<S>(initialState: S | (() => S)) {
const [state, setState] = useState<S>(initialState);
Expand Down Expand Up @@ -431,13 +437,13 @@ export function usePreventBodyScroll(
}, [visible]);
}

export const useProgress = (
export function useProgress(
mountedTransition: boolean,
percentage: number,
duration: number,
mountedBezier: BezierType,
step: number,
): [number, boolean] => {
): [number, boolean] {
const [currentPercentage, setCurrentPercentage] = useState(0);
const [transitionControl, setTransitionControl] = useState(false);
const [count, setCount] = useState(0);
Expand Down Expand Up @@ -471,7 +477,7 @@ export const useProgress = (
}, [count, percentage, step]);

return [currentPercentage, transitionControl];
};
}

export function useSingleAndDoubleClick(
onClick: (e: React.MouseEvent) => void,
Expand Down
24 changes: 12 additions & 12 deletions packages/arcodesign/components/form/form-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,25 @@ class FormItemInner extends PureComponent<IFormItemInnerProps, IFromItemInnerSta
this.destroyField();
}

onValueChange(preStore: FieldItem, curStore: FieldItem) {
onValueChange = (preStore: FieldItem, curStore: FieldItem) => {
this._touched = true;
const { shouldUpdate } = this.props;
if (typeof shouldUpdate === 'function') {
shouldUpdate({ preStore, curStore }) && this.forceUpdate();
return;
}
this.forceUpdate();
}
};

getFieldError() {
getFieldError = () => {
return this._errors;
}
};

isFieldTouched() {
isFieldTouched = () => {
return this._touched;
}
};

validateField(): Promise<IFieldError> {
validateField = (): Promise<IFieldError> => {
const { validateMessages } = this.context;
const { getFieldValue } = this.context.form;
const { field, rules, onValidateStatusChange } = this.props;
Expand Down Expand Up @@ -107,14 +107,14 @@ class FormItemInner extends PureComponent<IFormItemInnerProps, IFromItemInnerSta
});
}
return Promise.resolve({ errors: [], warnings: [], value, field, dom: null });
}
};

setFieldData(value: FieldValue) {
setFieldData = (value: FieldValue) => {
const { field } = this.props;
const { setFieldValue } = this.context.form;
setFieldValue(field, value);
this.validateField();
}
};

innerTriggerFunction = (_, value, ...args) => {
this.setFieldData(value);
Expand All @@ -132,13 +132,13 @@ class FormItemInner extends PureComponent<IFormItemInnerProps, IFromItemInnerSta
}
};

innerClearFunction(...args) {
innerClearFunction = (...args) => {
const { children } = this.props;
this.setFieldData('');
if (children.props?.onClear) {
children.props?.onClear(...args);
}
}
};

renderChildren() {
const {
Expand Down
4 changes: 2 additions & 2 deletions packages/common-widgets/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function freeEleScroll(
* @param parentEl 父节点
* @param childrenEl 子节点
*/
export const isContains = (parentEl: HTMLElement | null, childrenEl: HTMLElement | null) => {
export function isContains(parentEl: HTMLElement | null, childrenEl: HTMLElement | null) {
if (!parentEl || !childrenEl) return false;
if (parentEl.contains) {
return parentEl.contains(childrenEl);
Expand All @@ -56,7 +56,7 @@ export const isContains = (parentEl: HTMLElement | null, childrenEl: HTMLElement
parent = parent.parentNode as HTMLElement;
}
return false;
};
}

export function execRAF(fn) {
try {
Expand Down
4 changes: 2 additions & 2 deletions packages/common-widgets/utils/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function isEmptyArray(obj: Array<unknown>): boolean {
return isArray(obj) && !obj?.length;
}

export const isDeepEqual = (obj: any, sub: any): boolean => {
export function isDeepEqual(obj: any, sub: any): boolean {
if (typeof obj !== 'object' || typeof sub !== 'object' || obj === null || sub === null) {
return obj === sub;
}
Expand All @@ -49,4 +49,4 @@ export const isDeepEqual = (obj: any, sub: any): boolean => {
if (!isDeepEqual(obj[key], sub[key])) return false;
}
return true;
};
}
Loading