Skip to content

Commit 65f0182

Browse files
Wesley-0808uyarntdesign-bot
authored
fix: components props transmit bugs (#6052)
* fix: props transmit bugs and test tag-input * fix: cascader and selectInput * fix: upload * fix: tree-select * fix: base-table * fix: color-picker * fix: date-picker * fix: input-number * fix: range-input * fix: time-picker * fix: autoComplete * fix: select * fix: transfer-search * chore: hooks * chore: stash changelog [ci skip] * chore: remove test demo * fix:lint --------- Co-authored-by: wū yāng <[email protected]> Co-authored-by: tdesign-bot <[email protected]>
1 parent 9f380fe commit 65f0182

File tree

21 files changed

+437
-262
lines changed

21 files changed

+437
-262
lines changed

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
useDisabled,
1111
useReadonly,
1212
useCommonClassName,
13+
useEventForward,
1314
} from '@tdesign/shared-hooks';
1415
import AutoCompleteOptionList from './components/option-list';
1516

@@ -111,6 +112,16 @@ export default defineComponent({
111112
};
112113

113114
return () => {
115+
const inputEvents = useEventForward(innerInputProps.value, {
116+
onChange: onInputChange,
117+
onFocus: onInnerFocus,
118+
onBlur: onInnerBlur,
119+
onClear: props.onClear,
120+
onCompositionend: onInnerCompositionend,
121+
onCompositionstart: onInnerCompositionstart,
122+
onEnter: onInnerEnter,
123+
});
124+
114125
// 触发元素
115126
const triggerNode = renderContent('default', 'triggerElement') || (
116127
<TInput
@@ -122,14 +133,7 @@ export default defineComponent({
122133
disabled={isDisabled.value}
123134
autofocus={props.autofocus}
124135
clearable={props.clearable}
125-
onChange={onInputChange}
126-
onFocus={onInnerFocus}
127-
onBlur={onInnerBlur}
128-
onClear={props.onClear}
129-
onCompositionend={onInnerCompositionend}
130-
onCompositionstart={onInnerCompositionstart}
131-
onEnter={onInnerEnter}
132-
{...innerInputProps.value}
136+
{...inputEvents.value}
133137
v-slots={slots}
134138
/>
135139
);
@@ -167,6 +171,9 @@ export default defineComponent({
167171
overlayInnerClassName: popupInnerClasses.value,
168172
overlayClassName: popupClasses.value,
169173
};
174+
const popupEvents = useEventForward(popupProps, {
175+
onVisibleChange: onPopupVisibleChange,
176+
});
170177
return (
171178
<div class={classes.value}>
172179
<Popup
@@ -176,7 +183,7 @@ export default defineComponent({
176183
placement="bottom-left"
177184
hideEmptyPopup={true}
178185
content={panelContent ? () => panelContent : null}
179-
{...popupProps}
186+
{...popupEvents.value}
180187
>
181188
{triggerNode}
182189
</Popup>

packages/components/cascader/cascader.tsx

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { defineComponent, computed } from 'vue';
2-
import { omit } from 'lodash-es';
32
import TCascaderSubPanel from './components/Panel';
43
import SelectInput from '../select-input';
54
import FakeArrow from '../common-components/fake-arrow';
@@ -22,6 +21,7 @@ import {
2221
useReadonly,
2322
usePrefixClass,
2423
useCommonClassName,
24+
useEventForward,
2525
} from '@tdesign/shared-hooks';
2626
import { useCascaderContext } from './hooks';
2727

@@ -104,6 +104,38 @@ export default defineComponent({
104104
return () => {
105105
const { setVisible, visible, inputVal, setInputVal } = cascaderContext.value;
106106

107+
const selectInputEvents = useEventForward(props.selectInputProps as TdSelectInputProps, {
108+
onTagChange: (val: CascaderValue, ctx) => {
109+
// 按 enter 键不处理
110+
if (ctx.trigger === 'enter') return;
111+
handleRemoveTagEffect(cascaderContext.value, ctx.index, props.onRemove);
112+
},
113+
onInputChange: (value) => {
114+
if (!isFilterable.value) return;
115+
setInputVal(`${value}`);
116+
},
117+
onPopupVisibleChange: (val: boolean, context) => {
118+
if (isDisabled.value) return;
119+
setVisible(val, context);
120+
},
121+
onBlur: (val, context) => {
122+
props.onBlur?.({
123+
value: cascaderContext.value.value,
124+
inputValue: context.inputValue || '',
125+
e: context.e as FocusEvent,
126+
});
127+
},
128+
onFocus: (val, context) => {
129+
props.onFocus?.({
130+
value: cascaderContext.value.value,
131+
e: context.e,
132+
});
133+
},
134+
onClear: () => {
135+
closeIconClickEffect(cascaderContext.value);
136+
},
137+
});
138+
107139
return (
108140
<SelectInput
109141
class={cascaderClassNames.value}
@@ -142,42 +174,6 @@ export default defineComponent({
142174
...(props.tagInputProps as TdCascaderProps['tagInputProps']),
143175
}}
144176
tagProps={{ ...(props.tagProps as TdCascaderProps['tagProps']) }}
145-
onInputChange={(value, ctx) => {
146-
if (!isFilterable.value) return;
147-
setInputVal(`${value}`);
148-
(props?.selectInputProps as TdSelectInputProps)?.onInputChange?.(value, ctx);
149-
}}
150-
onTagChange={(val: CascaderValue, ctx) => {
151-
// 按 enter 键不处理
152-
if (ctx.trigger === 'enter') return;
153-
handleRemoveTagEffect(cascaderContext.value, ctx.index, props.onRemove);
154-
// @ts-ignore TODO: fix bug
155-
(props?.selectInputProps as TdSelectInputProps)?.onTagChange?.(val, ctx);
156-
}}
157-
onPopupVisibleChange={(val: boolean, context) => {
158-
if (isDisabled.value) return;
159-
setVisible(val, context);
160-
(props?.selectInputProps as TdSelectInputProps)?.onPopupVisibleChange?.(val, context);
161-
}}
162-
onBlur={(val, context) => {
163-
props.onBlur?.({
164-
value: cascaderContext.value.value,
165-
inputValue: context.inputValue || '',
166-
e: context.e as FocusEvent,
167-
});
168-
(props?.selectInputProps as TdSelectInputProps)?.onBlur?.(val, context);
169-
}}
170-
onFocus={(val, context) => {
171-
props.onFocus?.({
172-
value: cascaderContext.value.value,
173-
e: context.e,
174-
});
175-
(props?.selectInputProps as TdSelectInputProps)?.onFocus?.(val, context);
176-
}}
177-
onClear={(context: { e: MouseEvent }) => {
178-
closeIconClickEffect(cascaderContext.value);
179-
(props?.selectInputProps as TdSelectInputProps)?.onClear?.(context);
180-
}}
181177
v-slots={{
182178
label: slots.label,
183179
suffix: slots.suffix,
@@ -201,14 +197,7 @@ export default defineComponent({
201197
),
202198
collapsedItems: slots.collapsedItems,
203199
}}
204-
{...omit(props.selectInputProps as TdSelectInputProps, [
205-
'onTagChange',
206-
'onInputChange',
207-
'onPopupVisibleChange',
208-
'onBlur',
209-
'onFocus',
210-
'onClear',
211-
])}
200+
{...selectInputEvents.value}
212201
/>
213202
);
214203
};

packages/components/color-picker/components/trigger/index.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import TInput from '../../../input';
33
import { Color, getColorObject } from '../../utils';
44
import { TdColorPickerProps } from '../../type';
55
import { useBaseClassName } from '../../hooks';
6-
import { useCommonClassName } from '@tdesign/shared-hooks';
6+
import { useCommonClassName, useEventForward } from '@tdesign/shared-hooks';
77

88
export default defineComponent({
99
name: 'DefaultTrigger',
@@ -70,6 +70,12 @@ export default defineComponent({
7070

7171
const handleClear = (context: { e: MouseEvent }) => props.onTriggerClear?.(context);
7272

73+
const inputEvents = useEventForward(props.inputProps as TdColorPickerProps['inputProps'], {
74+
onBlur: handleChange,
75+
onChange: handleChange,
76+
onClear: handleClear,
77+
});
78+
7379
return () => {
7480
const inputSlots = {
7581
label: () => {
@@ -98,10 +104,7 @@ export default defineComponent({
98104
v-slots={inputSlots}
99105
v-model={value.value}
100106
disabled={props.disabled}
101-
onBlur={handleChange}
102-
onChange={handleChange}
103-
onClear={handleClear}
104-
{...props.inputProps}
107+
{...inputEvents.value}
105108
/>
106109
);
107110
};

packages/components/date-picker/DatePicker.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ import dayjs from 'dayjs';
33
import { isFunction, isDate } from 'lodash-es';
44
import { CalendarIcon as TdCalendarIcon } from 'tdesign-icons-vue-next';
55

6-
import { useConfig, useTNodeJSX, useDisabled, useReadonly, useGlobalIcon, usePrefixClass } from '@tdesign/shared-hooks';
6+
import {
7+
useConfig,
8+
useTNodeJSX,
9+
useDisabled,
10+
useReadonly,
11+
useGlobalIcon,
12+
usePrefixClass,
13+
useEventForward,
14+
} from '@tdesign/shared-hooks';
715

816
import { useSingle } from './hooks/useSingle';
917
import { parseToDayjs, getDefaultFormat, formatTime, formatDate } from '@tdesign/common-js/date-picker/format';
@@ -343,6 +351,10 @@ export default defineComponent({
343351
onPanelClick: () => inputRef.value?.focus?.(),
344352
}));
345353

354+
const selectInputEvents = useEventForward(props.selectInputProps as TdDatePickerProps['selectInputProps'], {
355+
onClear: onTagClearClick,
356+
});
357+
346358
return () => (
347359
<div class={COMPONENT_NAME.value}>
348360
<TSelectInput
@@ -363,14 +375,13 @@ export default defineComponent({
363375
popupVisible={!isReadOnly.value && popupVisible.value}
364376
valueDisplay={() => renderTNodeJSX('valueDisplay', { params: valueDisplayParams.value })}
365377
needConfirm={props.needConfirm}
366-
{...(props.selectInputProps as TdDatePickerProps['selectInputProps'])}
367378
panel={() => <TSinglePanel {...panelProps.value} />}
368379
tagInputProps={{
369380
onRemove: onTagRemoveClick,
370381
}}
371-
onClear={onTagClearClick}
372382
prefixIcon={() => renderTNodeJSX('prefixIcon')}
373383
suffixIcon={() => renderTNodeJSX('suffixIcon') || <CalendarIcon />}
384+
{...selectInputEvents.value}
374385
/>
375386
</div>
376387
);

packages/components/input-number/input-number.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import TButton from '../button';
99
import TInput from '../input';
1010
import props from './props';
11-
import { useGlobalIcon } from '@tdesign/shared-hooks';
11+
import { useEventForward, useGlobalIcon } from '@tdesign/shared-hooks';
1212
import { TdInputNumberProps } from './type';
1313
import useInputNumber from './hooks/useInputNumber';
1414

@@ -27,6 +27,11 @@ export default defineComponent({
2727
const { inputRef } = p;
2828
context.expose({ ...p });
2929

30+
const inputEvents = useEventForward(props.inputProps, {
31+
onChange: p.onInnerInputChange,
32+
...p.listeners,
33+
});
34+
3035
return () => {
3136
const reduceIcon =
3237
props.theme === 'column' ? <ChevronDownIcon size={props.size} /> : <RemoveIcon size={props.size} />;
@@ -58,11 +63,9 @@ export default defineComponent({
5863
label={props.label}
5964
suffix={props.suffix}
6065
tips={props.tips}
61-
{...p.listeners}
62-
{...props.inputProps}
6366
v-slots={context.slots}
6467
value={p.userInput.value}
65-
onChange={p.onInnerInputChange}
68+
{...inputEvents.value}
6669
/>
6770
{props.theme !== 'normal' && (
6871
<TButton

0 commit comments

Comments
 (0)