Skip to content

Commit

Permalink
fix: the second argument(type) to change event (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxiong10 committed Dec 16, 2021
1 parent 987b977 commit eb533f5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,18 @@ Set fixed time list to select;

### Events

| Name | Description | Callback Arguments |
| --------------- | -------------------------------------------------------------------------------------- | -------------------------------------- |
| input | When the value change(v-model event) | date |
| change | When the value change(same as input) | date |
| open | When panel opening | event |
| close | When panel closing | |
| confirm | When click 'confirm' button | date |
| clear | When click 'clear' button | |
| input-error | When user type a invalid Date | the input text |
| pick | when select date [#429](https://github.com/mengxiong10/vue-datepicker-next/issues/429) | date |
| calendar-change | when change the calendar | date, oldDate |
| panel-change | when the calendar panel changes | type('year'\|'month'\|'date'), oldType |
| Name | Description | Callback Arguments |
| --------------- | -------------------------------------------------------------------------------------- | ------------------------------------------------------ |
| update:value | When the value change(v-model:value event) | date |
| change | When the value change(same as input) | date, type('date'\|'hour'\|'minute'\|'second'\|'ampm') |
| open | When panel opening | event |
| close | When panel closing | |
| confirm | When click 'confirm' button | date |
| clear | When click 'clear' button | |
| input-error | When user type a invalid Date | the input text |
| pick | when select date [#429](https://github.com/mengxiong10/vue-datepicker-next/issues/429) | date |
| calendar-change | when change the calendar | date, oldDate |
| panel-change | when the calendar panel changes | type('year'\|'month'\|'date'), oldType |

### Slots

Expand Down
28 changes: 14 additions & 14 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,20 +270,20 @@ data() {

### 事件

| 名称 | 描述 | 回调函数的参数 |
| --------------- | ---------------------------------------------------------------------------------- | -------------------------------------- |
| input | 当选择日期的事件触发 | date |
| change | 当选择日期的事件触发 | date |
| open | 当弹出层打开时候 | event |
| close | 当弹出层关闭时候 | |
| confirm | 当点击确认按钮 | date |
| clear | 当点击清除按钮 | |
| input-error | 当输入一个无效的时间 | input text |
| focus | 当输入框有焦点 | |
| blur | 当输入框失焦 | |
| pick | 当点击日期时 [#429](https://github.com/mengxiong10/vue-datepicker-next/issues/429) | date |
| calendar-change | 当改变年月时 | date, oldDate |
| panel-change | 当日历面板改变时 | type('year'\|'month'\|'date'), oldType |
| 名称 | 描述 | 回调函数的参数 |
| --------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------ |
| update:value | 当选择日期的事件触发 | date |
| change | 当选择日期的事件触发 | date, type('date'\|'hour'\|'minute'\|'second'\|'ampm') |
| open | 当弹出层打开时候 | event |
| close | 当弹出层关闭时候 | |
| confirm | 当点击确认按钮 | date |
| clear | 当点击清除按钮 | |
| input-error | 当输入一个无效的时间 | input text |
| focus | 当输入框有焦点 | |
| blur | 当输入框失焦 | |
| pick | 当点击日期时 [#429](https://github.com/mengxiong10/vue-datepicker-next/issues/429) | date |
| calendar-change | 当改变年月时 | date, oldDate |
| panel-change | 当日历面板改变时 | type('year'\|'month'\|'date'), oldType |

### Slots

Expand Down
14 changes: 7 additions & 7 deletions __tests__/DatePicker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe('DatePicker', () => {
value: value,
format: 'YYYY/MM/DD',
open: true,
onChange: mockFn,
['onUpdate:value']: mockFn,
},
});
const cell = wrapper.find('[title="2019-10-01"]');
Expand Down Expand Up @@ -204,7 +204,7 @@ describe('DatePicker', () => {
open: true,
valueType: 'YYYY/MM/DD',
appendToBody: false,
onChange: mockFn,
['onUpdate:value']: mockFn,
shortcuts: [
{
text: 'Today',
Expand Down Expand Up @@ -256,7 +256,7 @@ describe('DatePicker', () => {
confirm: true,
confirmText: 'test',
appendToBody: false,
onChange: mockFn,
['onUpdate:value']: mockFn,
},
});
await wrapper.find('input').trigger('focus');
Expand Down Expand Up @@ -295,7 +295,7 @@ describe('DatePicker', () => {
range: false,
value: new Date(2019, 10, 9),
onClear: mockClearFn,
onChange: mockChangeFn,
['onUpdate:value']: mockChangeFn,
},
});
wrapper.find('.mx-icon-clear').trigger('click');
Expand Down Expand Up @@ -345,7 +345,7 @@ describe('DatePicker', () => {
separator,
range: true,
valueType: 'format',
onChange: mockFn,
['onUpdate:value']: mockFn,
},
});
const input = wrapper.find('input');
Expand All @@ -369,7 +369,7 @@ describe('DatePicker', () => {
open: true,
appendToBody: false,
value,
onChange: mockFn,
['onUpdate:value']: mockFn,
},
});
wrapper.find('.mx-date-row .active').trigger('click');
Expand All @@ -388,7 +388,7 @@ describe('DatePicker', () => {
disabledDate: (date) => {
return date < someday;
},
onChange: mockFn,
['onUpdate:value']: mockFn,
onInputError: inputErrorFn,
},
});
Expand Down
10 changes: 5 additions & 5 deletions lib/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface PickerBaseProps {
onClose?: () => void;
onOpen?: () => void;
onConfirm?: (v: any) => void;
onChange?: (v: any) => void;
onChange?: (v: any, type?: string) => void;
['onUpdate:open']?: (open: boolean) => void;
['onUpdate:value']?: (v: any) => void;
}
Expand All @@ -39,7 +39,7 @@ export type PickerProps = PickerBaseProps & PickerInputBaseProps;
export interface SlotProps {
value: any;
['onUpdate:value']: (value: any, type: string) => void;
emit: (value: any, close?: boolean) => void;
emit: (value: any, type?: string, close?: boolean) => void;
}

function Picker(originalProps: PickerProps, { slots }: SetupContext) {
Expand Down Expand Up @@ -136,10 +136,10 @@ function Picker(originalProps: PickerProps, { slots }: SetupContext) {
return value2date(value);
});

const emitValue = (date: Date | Date[] | null | null[], close = true) => {
const emitValue = (date: Date | Date[] | null | null[], type?: string, close = true) => {
const value = Array.isArray(date) ? date.map(date2value) : date2value(date);
props['onUpdate:value']?.(value);
props.onChange?.(value);
props.onChange?.(value, type);
if (close) {
closePopup();
}
Expand All @@ -159,7 +159,7 @@ function Picker(originalProps: PickerProps, { slots }: SetupContext) {
currentValue.value = val;
} else {
// type === 'datetime', click the time should close popup
emitValue(val, !props.multiple && (type === props.type || type === 'time'));
emitValue(val, type, !props.multiple && (type === props.type || type === 'time'));
}
};

Expand Down

0 comments on commit eb533f5

Please sign in to comment.