Skip to content

Commit c7a51b9

Browse files
committed
Merge branch 'develop' into rylan/fix/form/clone
2 parents 16e4da1 + 7622f9e commit c7a51b9

File tree

155 files changed

+3372
-2571
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+3372
-2571
lines changed

packages/components/_util/composeRefs.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/components/_util/dom.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { isString } from 'lodash-es';
22
import { getCssVarsValue } from './style';
3+
import type { AttachNode } from '../common';
34

45
// 用于判断是否可使用 dom
56
export const canUseDocument = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
@@ -13,7 +14,7 @@ export const canUseDocument = !!(typeof window !== 'undefined' && window.documen
1314
*/
1415
export const isWindow = (val: unknown): val is Window => val === window;
1516

16-
export const getAttach = (node: any): HTMLElement => {
17+
export const getAttach = (node: AttachNode): HTMLElement => {
1718
const attachNode = typeof node === 'function' ? node() : node;
1819
if (!attachNode) {
1920
return document.body;

packages/components/_util/listener.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ import { canUseDocument } from './dom';
22

33
export const on = ((): any => {
44
if (canUseDocument && document.addEventListener) {
5-
return (element: Node, event: string, handler: EventListenerOrEventListenerObject): any => {
5+
return (
6+
element: Node,
7+
event: string,
8+
handler: EventListenerOrEventListenerObject,
9+
options?: AddEventListenerOptions,
10+
): any => {
611
if (element && event && handler) {
7-
element.addEventListener(event, handler, false);
12+
element.addEventListener(event, handler, options ?? false);
813
}
914
};
1015
}
@@ -17,9 +22,14 @@ export const on = ((): any => {
1722

1823
export const off = ((): any => {
1924
if (canUseDocument && document.removeEventListener) {
20-
return (element: Node, event: string, handler: EventListenerOrEventListenerObject): any => {
25+
return (
26+
element: Node,
27+
event: string,
28+
handler: EventListenerOrEventListenerObject,
29+
options?: EventListenerOptions,
30+
): any => {
2131
if (element && event) {
22-
element.removeEventListener(event, handler, false);
32+
element.removeEventListener(event, handler, options ?? false);
2333
}
2434
};
2535
}

packages/components/_util/ref.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const supportRef = (nodeOrComponent: any): boolean => {
3838
// 获取 ref 中的 dom 元素
3939
export function getRefDom(domRef: React.RefObject<any>) {
4040
if (domRef.current && typeof domRef.current === 'object' && 'currentElement' in domRef.current) {
41+
// 兼容 TD 部分组件的 ref 被 useImperativeHandle 覆盖,无法拿到实际 DOM 节点的情况
4142
return domRef.current.currentElement;
4243
}
4344
return domRef.current;
@@ -70,3 +71,17 @@ export const getNodeRef: <T = any>(node: React.ReactNode) => React.Ref<T> | null
7071
}
7172
return null;
7273
};
74+
75+
export function composeRefs<T>(...refs: React.Ref<T>[]) {
76+
return (instance: T) => {
77+
// eslint-disable-next-line no-restricted-syntax
78+
for (const ref of refs) {
79+
if (typeof ref === 'function') {
80+
ref(instance);
81+
} else if (ref) {
82+
(ref as any).current = instance;
83+
}
84+
}
85+
};
86+
}
87+

packages/components/alert/Alert.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { useLocaleReceiver } from '../locale/LocalReceiver';
1616
import { TdAlertProps } from './type';
1717
import { StyledProps } from '../common';
1818
import { alertDefaultProps } from './defaultProps';
19-
import composeRefs from '../_util/composeRefs';
19+
import { composeRefs } from '../_util/ref';
2020
import useDefaultProps from '../hooks/useDefaultProps';
2121

2222
const transitionTime = 200;

packages/components/auto-complete/AutoComplete.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export interface AutoCompleteRef {
2222

2323
const AutoComplete = forwardRef<AutoCompleteRef, AutoCompleteProps>((originalProps, ref) => {
2424
const props = useDefaultProps(originalProps, autoCompleteDefaultProps);
25+
const readOnly = props.readOnly || props.readonly;
26+
2527
const inputRef = useRef(null);
2628
const popupRef = useRef(null);
2729
const [tValue, setTValue] = useControlled(props, 'value', props.onChange);
@@ -104,7 +106,7 @@ const AutoComplete = forwardRef<AutoCompleteRef, AutoCompleteProps>((originalPro
104106
};
105107

106108
const onInnerSelect: OptionsListProps['onSelect'] = (value, context) => {
107-
if (props.readonly || props.disabled) return;
109+
if (readOnly || props.disabled) return;
108110
setPopupVisible(false);
109111
setTValue(value, context);
110112
props.onSelect?.(value, context);
@@ -123,7 +125,7 @@ const AutoComplete = forwardRef<AutoCompleteRef, AutoCompleteProps>((originalPro
123125
placeholder={props.placeholder ?? global.placeholder}
124126
tips={props.tips}
125127
status={props.status}
126-
readonly={props.readonly}
128+
readOnly={readOnly}
127129
disabled={props.disabled}
128130
clearable={props.clearable}
129131
autofocus={props.autofocus}

packages/components/auto-complete/__tests__/vitest-auto-complete.test.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,17 @@ describe('AutoComplete Component', () => {
173173
expect(customClassNameDom).toBeTruthy();
174174
});
175175

176-
it('props.readonly works fine', () => {
176+
it('props.readOnly works fine', () => {
177177
// readonly default value is
178178
const wrapper1 = getNormalAutoCompleteMount(AutoComplete);
179179
const container1 = wrapper1.container.querySelector('.t-input');
180180
expect(container1.querySelector(`.${'t-is-readonly'}`)).toBeFalsy();
181181
// readonly = true
182-
const wrapper2 = getNormalAutoCompleteMount(AutoComplete, { readonly: true });
182+
const wrapper2 = getNormalAutoCompleteMount(AutoComplete, { readOnly: true });
183183
const container2 = wrapper2.container.querySelector('.t-input');
184184
expect(container2).toHaveClass('t-is-readonly');
185185
// readonly = false
186-
const wrapper3 = getNormalAutoCompleteMount(AutoComplete, { readonly: false });
186+
const wrapper3 = getNormalAutoCompleteMount(AutoComplete, { readOnly: false });
187187
const container3 = wrapper3.container.querySelector('.t-input');
188188
expect(container3.querySelector(`.${'t-is-readonly'}`)).toBeFalsy();
189189
});

packages/components/auto-complete/_example/status.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const AutoCompleteStatus = () => {
2020
value={value}
2121
options={options}
2222
onChange={setValue}
23-
readonly
23+
readOnly
2424
tips="这是只读状态"
2525
placeholder="请输入关键词搜索"
2626
/>

packages/components/auto-complete/auto-complete.en-US.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ options | Array | - | Typescript: `Array<T>` | N
2222
panelBottomContent | TNode | - | Typescript: `string \| TNode`[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N
2323
panelTopContent | TNode | - | Typescript: `string \| TNode`[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N
2424
placeholder | String | undefined | \- | N
25-
popupProps | Object | - | Typescript: `PopupProps`[Popup API Documents](./popup?tab=api)[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/auto-complete/type.ts) | N
26-
readonly | Boolean | - | \- | N
27-
size | String | medium | options: small/medium/large。Typescript: `SizeEnum`[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N
25+
popupProps | Object | - | Typescript`PopupProps`[Popup API Documents](./popup?tab=api)[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/auto-complete/type.ts) | N
26+
readOnly | Boolean | - | \- | N
27+
size | String | medium | options: small/medium/large。Typescript`SizeEnum`[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N
2828
status | String | default | options: default/success/warning/error | N
2929
textareaProps | Object | - | Typescript: `TextareaProps`[Textarea API Documents](./textarea?tab=api)[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/auto-complete/type.ts) | N
3030
tips | TNode | - | Typescript: `string \| TNode`[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N

0 commit comments

Comments
 (0)