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

feat(data-picker): add method onApply #647

Merged
merged 1 commit into from
Apr 27, 2022
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
2 changes: 2 additions & 0 deletions examples/date-picker/demos/date-range.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
style="width: 350px"
@pick="onPick"
@change="onChange"
@apply="onApply"
/>
</div>
</template>

<script setup>
const onPick = (value, context) => console.log('onPick:', value, context);
const onChange = (value) => console.log('onChange:', value);
const onApply = (value) => console.log('onApply:', value);
</script>
15 changes: 15 additions & 0 deletions src/date-picker/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,21 @@ export default defineComponent({
this.submitInput(selectedDates, true);

if (closePicker) {
const mode = this.range ? 'range' : this.mode;
const { multiSeparator } = this;

switch (mode) {
case 'date':
case 'month':
case 'year':
emitEvent(this, 'apply', selectedDates.join(multiSeparator));
break;
case 'range':
emitEvent(this, 'apply', selectedDates);
break;
default:
break;
}
this.close();
}
},
Expand Down
2 changes: 2 additions & 0 deletions src/date-picker/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,6 @@ export default {
onInput: Function as PropType<TdDatePickerProps['onInput']>,
/* 选中日期时触发,可能是开始日期,也可能是结束日期,第二个参数可以区分是开始日期或是结束日期 */
onPick: Function as PropType<TdDateRangePickerProps['onPick']>,
/* 选择或点击确定按钮后触发 */
onApply: Function as PropType<TdDateRangePickerProps['onApply']>,
};
4 changes: 4 additions & 0 deletions src/date-picker/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ export interface TdDateRangePickerProps {
* 选中日期时触发,可能是开始日期,也可能是结束日期,第二个参数可以区分是开始日期或是结束日期
*/
onPick?: (value: DateValue, context: PickContext) => void;
/**
* 选择或点击确定按钮后触发
*/
onApply?: (value: DateRangeValue) => void;
}

export type DisableDate = Array<DateValue> | DisableDateObj | ((date: DateValue) => boolean);
Expand Down