Skip to content

Commit ccce405

Browse files
windolepengjin
andauthored
fix: 修复PasswordInput组件阻止默认事件问题 (#60)
* chore: 更改release-it版本 * fix: 修复PasswordInput组件阻止默认事件问题 * fix(date-picker): 修改confirm时拿不到最新值的问题 * fix: 更新form组件的Snapshots --------- Co-authored-by: pengjin <pengjin@vcredit.com>
1 parent aaef179 commit ccce405

File tree

8 files changed

+2245
-2199
lines changed

8 files changed

+2245
-2199
lines changed

packages/rc-cli/site/mobile/routes.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export function getLangFromRoute(pathname) {
1919
}
2020

2121
function getRoutes() {
22-
console.log(demos);
2322
const routes = [];
2423
const names = Object.keys(demos);
2524
const langs = locales ? Object.keys(locales) : [];
@@ -82,7 +81,6 @@ function getRoutes() {
8281
meta: {},
8382
});
8483
}
85-
console.log(routes);
8684

8785
return routes;
8886
}

packages/rc-ui-lib/src/datetime-picker/DatePicker.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ const DatePicker = forwardRef<DateTimePickerInstance, DatePickerProps>((props, r
4444
const pickerRef = useRef<PickerInstance>(null);
4545
const [currentDate, setCurrentDate, currentDateRef] = useRefState(formatValue(value));
4646

47-
4847
const getBoundary = (type: 'max' | 'min', dateValue: Date) => {
4948
const boundary = props[`${type}Date`];
5049
const year = boundary.getFullYear();
@@ -243,7 +242,12 @@ const DatePicker = forwardRef<DateTimePickerInstance, DatePickerProps>((props, r
243242
};
244243

245244
const onConfirm = () => {
246-
props.onConfirm?.(currentDate);
245+
if (pickerRef.current) {
246+
const indexes = pickerRef.current?.getIndexes();
247+
const nextValue = updateInnerValue(indexes);
248+
setCurrentDate(nextValue);
249+
props.onConfirm?.(nextValue);
250+
}
247251
};
248252

249253
// useMount(() => {

packages/rc-ui-lib/src/datetime-picker/__test__/date-picker.spec.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ describe('DatePicker', () => {
7373
onConfirm,
7474
});
7575

76+
await sleep(400);
77+
7678
const confirmBtn = container.querySelector('.rc-picker__confirm');
7779
fireEvent.click(confirmBtn);
7880

@@ -83,7 +85,7 @@ describe('DatePicker', () => {
8385
await sleep(400);
8486

8587
fireEvent.click(confirmBtn);
86-
// expect(onConfirm.mock.calls[1][0].getMonth()).toEqual(11);
88+
expect(onConfirm.mock.calls[1][0].getMonth()).toEqual(11);
8789
expect(onConfirm.mock.calls[1][0].getDate()).toEqual(1);
8890
});
8991

@@ -100,9 +102,10 @@ describe('DatePicker', () => {
100102
onConfirm,
101103
});
102104

105+
await sleep(100);
106+
103107
const confirmBtn = container.querySelector('.rc-picker__confirm');
104108
fireEvent.click(confirmBtn);
105-
await sleep(100);
106109
expect(onConfirm.mock.calls[0][0].getFullYear()).toEqual(2020);
107110
expect(onConfirm.mock.calls[0][0].getMonth()).toEqual(10);
108111

@@ -154,6 +157,8 @@ describe('DatePicker', () => {
154157
onConfirm,
155158
});
156159

160+
await sleep(400);
161+
157162
const confirmBtn = container.querySelector('.rc-picker__confirm');
158163
fireEvent.click(confirmBtn);
159164

@@ -184,6 +189,8 @@ describe('DatePicker', () => {
184189
onConfirm,
185190
});
186191

192+
await sleep(400);
193+
187194
const confirmBtn = container.querySelector('.rc-picker__confirm');
188195
fireEvent.click(confirmBtn);
189196

packages/rc-ui-lib/src/datetime-picker/__test__/index.spec.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ describe('DateTimePicker', () => {
110110
onConfirm,
111111
});
112112

113+
await sleep(100);
114+
113115
act(() => {
114116
pickerRef.current.getPicker().setColumnIndex(2, 14);
115117
});
@@ -132,6 +134,8 @@ describe('DateTimePicker', () => {
132134
onConfirm,
133135
});
134136

137+
await sleep(100);
138+
135139
act(() => {
136140
pickerRef.current.getPicker().setColumnValue(2, '15');
137141
});

packages/rc-ui-lib/src/form/__test__/__snapshots__/index.spec.tsx.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ exports[`Form basic usage 1`] = `
9999
"validateTrigger": "onChange",
100100
}
101101
}
102+
isListField={false}
102103
key="_username"
103104
name={
104105
Array [
@@ -130,6 +131,7 @@ exports[`Form basic usage 1`] = `
130131
"username",
131132
],
132133
"touched": false,
134+
"validated": false,
133135
"validating": false,
134136
"warnings": Array [],
135137
}
@@ -457,6 +459,7 @@ exports[`Form when name props is set without shouldUpdate or dependencies 1`] =
457459
"validateTrigger": "onChange",
458460
}
459461
}
462+
isListField={false}
460463
key="_name"
461464
name={
462465
Array [
@@ -476,6 +479,7 @@ exports[`Form when name props is set without shouldUpdate or dependencies 1`] =
476479
"name",
477480
],
478481
"touched": false,
482+
"validated": false,
479483
"validating": false,
480484
"warnings": Array [],
481485
}
@@ -824,6 +828,7 @@ exports[`Form when shouldUpdate and dependencies are not set 1`] = `
824828
"validateTrigger": "onChange",
825829
}
826830
}
831+
isListField={false}
827832
key="_"
828833
trigger="onChange"
829834
validateTrigger="onChange"
@@ -836,6 +841,7 @@ exports[`Form when shouldUpdate and dependencies are not set 1`] = `
836841
"errors": Array [],
837842
"name": Array [],
838843
"touched": false,
844+
"validated": false,
839845
"validating": false,
840846
"warnings": Array [],
841847
}
@@ -948,6 +954,7 @@ exports[`Form when shouldUpdate props is set 1`] = `
948954
"validateTrigger": "onChange",
949955
}
950956
}
957+
isListField={false}
951958
key="_"
952959
shouldUpdate={true}
953960
trigger="onChange"
@@ -961,6 +968,7 @@ exports[`Form when shouldUpdate props is set 1`] = `
961968
"errors": Array [],
962969
"name": Array [],
963970
"touched": false,
971+
"validated": false,
964972
"validating": false,
965973
"warnings": Array [],
966974
}

packages/rc-ui-lib/src/password-input/PasswordInput.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ const PasswordInput = forwardRef<PasswordInputInstance, PasswordInputProps>((pro
6868
},
6969
}));
7070

71-
const onTouchStart = (event) => {
72-
event.stopPropagation();
73-
props.onFocus?.();
74-
};
75-
7671
const renderPoints = () => {
7772
const Points: JSX.Element[] = [];
7873
const { mask, gutter } = props;
@@ -114,7 +109,6 @@ const PasswordInput = forwardRef<PasswordInputInstance, PasswordInputProps>((pro
114109
>
115110
<ul
116111
className={classNames(bem('security'), { [BORDER_SURROUND]: !props.gutter })}
117-
onTouchStart={onTouchStart}
118112
>
119113
{renderPoints()}
120114
</ul>

packages/rc-ui-lib/src/password-input/__test__/index.spec.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ describe('PasswordInput', () => {
3434
jest.restoreAllMocks();
3535
});
3636

37-
it('should emit onFocus event when security is touched', async () => {
38-
const onFocus = jest.fn();
39-
const props = {
40-
...$props,
41-
onFocus,
42-
};
43-
44-
const { container } = createPasswordInput(props);
45-
const wrapper = container.querySelector('.rc-password-input__security');
46-
await TestsEvent.triggerTouch(wrapper, 'touchstart', [[0, 0]]);
47-
expect(onFocus).toHaveBeenCalled();
48-
});
37+
// it('should emit onFocus event when security is touched', async () => {
38+
// const onFocus = jest.fn();
39+
// const props = {
40+
// ...$props,
41+
// onFocus,
42+
// };
43+
44+
// const { container } = createPasswordInput(props);
45+
// const wrapper = container.querySelector('.rc-password-input__security');
46+
// await TestsEvent.triggerTouch(wrapper, 'touchstart', [[0, 0]]);
47+
// expect(onFocus).toHaveBeenCalled();
48+
// });
4949

5050
it('should emit onFocus event when wrapper is focused', async () => {
5151
const onFocus = jest.fn();

0 commit comments

Comments
 (0)