diff --git a/components/date-picker/InputIcon.js b/components/date-picker/InputIcon.js
index ea23a6a71..1836802e7 100644
--- a/components/date-picker/InputIcon.js
+++ b/components/date-picker/InputIcon.js
@@ -1,20 +1,22 @@
import CalendarOutlined from '@ant-design/icons-vue/CalendarOutlined';
import { isValidElement } from '../_util/props-util';
import { cloneElement } from '../_util/vnode';
+import classNames from 'classnames';
-export default {
- functional: true,
- render(h, context) {
- const { props } = context;
- const { suffixIcon, prefixCls } = props;
- return (
- (suffixIcon && isValidElement(suffixIcon) ? (
- cloneElement(suffixIcon, {
- class: `${prefixCls}-picker-icon`,
- })
- ) : (
- {suffixIcon}
- )) ||
- );
- },
+const InputIcon = (_, { attrs }) => {
+ const { suffixIcon, prefixCls } = attrs;
+ return (
+ (suffixIcon && isValidElement(suffixIcon) ? (
+ cloneElement(suffixIcon, {
+ class: classNames({
+ [suffixIcon.props?.class]: suffixIcon.props.class,
+ [`${prefixCls}-picker-icon`]: true,
+ }),
+ })
+ ) : (
+ {suffixIcon}
+ )) ||
+ );
};
+InputIcon.inheritAttrs = false;
+export default InputIcon;
diff --git a/components/date-picker/RangePicker.jsx b/components/date-picker/RangePicker.jsx
index 2bd257f12..96d9fa74c 100644
--- a/components/date-picker/RangePicker.jsx
+++ b/components/date-picker/RangePicker.jsx
@@ -1,3 +1,4 @@
+import { inject } from 'vue';
import * as moment from 'moment';
import RangeCalendar from '../vc-calendar/src/RangeCalendar';
import VcDatePicker from '../vc-calendar/src/Picker';
@@ -8,19 +9,11 @@ import Tag from '../tag';
import { ConfigConsumerProps } from '../config-provider';
import interopDefault from '../_util/interopDefault';
import { RangePickerProps } from './interface';
-import {
- hasProp,
- getOptionProps,
- initDefaultProps,
- mergeProps,
- getComponent,
- getListeners,
-} from '../_util/props-util';
+import { hasProp, getOptionProps, initDefaultProps, getComponent } from '../_util/props-util';
import BaseMixin from '../_util/BaseMixin';
import { formatDate } from './utils';
import InputIcon from './InputIcon';
-function noop() {}
function getShowDateFromValue(value, mode) {
const [start, end] = value;
// value could be an empty array, then we should not reset showDate
@@ -70,17 +63,16 @@ function fixLocale(value, localeCode) {
export default {
name: 'ARangePicker',
mixins: [BaseMixin],
- model: {
- prop: 'value',
- event: 'change',
- },
+ inheritAttrs: false,
props: initDefaultProps(RangePickerProps(), {
allowClear: true,
showToday: false,
separator: '~',
}),
- inject: {
- configProvider: { default: () => ConfigConsumerProps },
+ setup() {
+ return {
+ configProvider: inject('configProvider', ConfigConsumerProps),
+ };
},
data() {
const value = this.value || this.defaultValue || [];
@@ -133,6 +125,10 @@ export default {
this.setState({ sOpen: false });
}
},
+
+ savePicker(node) {
+ this.picker = node;
+ },
clearSelection(e) {
e.preventDefault();
e.stopPropagation();
@@ -212,18 +208,17 @@ export default {
},
focus() {
- this.$refs.picker.focus();
+ this.picker.focus();
},
blur() {
- this.$refs.picker.blur();
+ this.picker.blur();
},
renderFooter() {
- const { ranges, $scopedSlots, $slots } = this;
+ const { ranges, $slots } = this;
const { _prefixCls: prefixCls, _tagPrefixCls: tagPrefixCls } = this;
- const renderExtraFooter =
- this.renderExtraFooter || $scopedSlots.renderExtraFooter || $slots.renderExtraFooter;
+ const renderExtraFooter = this.renderExtraFooter || $slots.renderExtraFooter;
if (!ranges && !renderExtraFooter) {
return null;
}
@@ -261,7 +256,7 @@ export default {
},
render() {
- const props = getOptionProps(this);
+ const props = { ...getOptionProps(this), ...this.$attrs };
let suffixIcon = getComponent(this, 'suffixIcon');
suffixIcon = Array.isArray(suffixIcon) ? suffixIcon[0] : suffixIcon;
const {
@@ -269,16 +264,8 @@ export default {
sShowDate: showDate,
sHoverValue: hoverValue,
sOpen: open,
- $scopedSlots,
+ $slots,
} = this;
- const listeners = getListeners(this);
- const {
- calendarChange = noop,
- ok = noop,
- focus = noop,
- blur = noop,
- panelChange = noop,
- } = listeners;
const {
prefixCls: customizePrefixCls,
tagPrefixCls: customizeTagPrefixCls,
@@ -293,6 +280,12 @@ export default {
format,
separator,
inputReadOnly,
+ style,
+ onCalendarChange,
+ onOk,
+ onBlur,
+ onFocus,
+ onPanelChange,
} = props;
const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('calendar', customizePrefixCls);
@@ -300,7 +293,7 @@ export default {
this._prefixCls = prefixCls;
this._tagPrefixCls = tagPrefixCls;
- const dateRender = props.dateRender || $scopedSlots.dateRender;
+ const dateRender = props.dateRender || $slots.dateRender;
fixLocale(value, localeCode);
fixLocale(showDate, localeCode);
@@ -311,23 +304,18 @@ export default {
// 需要选择时间时,点击 ok 时才触发 onChange
const pickerChangeHandler = {
- on: {
- change: this.handleChange,
- },
+ onChange: this.handleChange,
};
let calendarProps = {
- on: {
- ok: this.handleChange,
- },
- props: {},
+ onOk: this.handleChange,
};
if (props.timePicker) {
- pickerChangeHandler.on.change = changedValue => this.handleChange(changedValue);
+ pickerChangeHandler.onChange = changedValue => this.handleChange(changedValue);
} else {
- calendarProps = { on: {}, props: {} };
+ calendarProps = {};
}
if ('mode' in props) {
- calendarProps.props.mode = props.mode;
+ calendarProps.mode = props.mode;
}
const startPlaceholder = Array.isArray(props.placeholder)
@@ -337,35 +325,31 @@ export default {
? props.placeholder[1]
: locale.lang.rangePlaceholder[1];
- const rangeCalendarProps = mergeProps(calendarProps, {
- props: {
- separator,
- format,
- prefixCls,
- renderFooter: this.renderFooter,
- timePicker: props.timePicker,
- disabledDate,
- disabledTime,
- dateInputPlaceholder: [startPlaceholder, endPlaceholder],
- locale: locale.lang,
- dateRender,
- value: showDate,
- hoverValue,
- showToday,
- inputReadOnly,
- },
- on: {
- change: calendarChange,
- ok,
- valueChange: this.handleShowDateChange,
- hoverChange: this.handleHoverChange,
- panelChange,
- inputSelect: this.handleCalendarInputSelect,
- },
+ const rangeCalendarProps = {
+ ...calendarProps,
+ separator,
+ format,
+ prefixCls,
+ renderFooter: this.renderFooter,
+ timePicker: props.timePicker,
+ disabledDate,
+ disabledTime,
+ dateInputPlaceholder: [startPlaceholder, endPlaceholder],
+ locale: locale.lang,
+ dateRender,
+ value: showDate,
+ hoverValue,
+ showToday,
+ inputReadOnly,
+ onChange: onCalendarChange,
+ onOk,
+ onValueChange: this.handleShowDateChange,
+ onHoverChange: this.handleHoverChange,
+ onPanelChange,
+ onInputSelect: this.handleCalendarInputSelect,
class: calendarClassName,
- scopedSlots: $scopedSlots,
- });
- const calendar = ;
+ };
+ const calendar = ;
// default width for showTime
const pickerStyle = {};
@@ -406,38 +390,31 @@ export default {
);
};
- const vcDatePickerProps = mergeProps(
- {
- props,
- on: listeners,
- },
- pickerChangeHandler,
- {
- props: {
- calendar,
- value,
- open,
- prefixCls: `${prefixCls}-picker-container`,
- },
- on: {
- openChange: this.handleOpenChange,
- },
- style: popupStyle,
- scopedSlots: { default: input, ...$scopedSlots },
- },
- );
+ const vcDatePickerProps = {
+ ...props,
+ ...pickerChangeHandler,
+ calendar,
+ value,
+ open,
+ prefixCls: `${prefixCls}-picker-container`,
+ onOpenChange: this.handleOpenChange,
+ style: popupStyle,
+ };
return (
-
+
);
},
diff --git a/components/date-picker/WeekPicker.jsx b/components/date-picker/WeekPicker.jsx
index ed3f76ceb..039856caf 100644
--- a/components/date-picker/WeekPicker.jsx
+++ b/components/date-picker/WeekPicker.jsx
@@ -1,15 +1,11 @@
+import { inject } from 'vue';
import * as moment from 'moment';
import Calendar from '../vc-calendar';
import VcDatePicker from '../vc-calendar/src/Picker';
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';
import { ConfigConsumerProps } from '../config-provider';
-import {
- hasProp,
- getOptionProps,
- initDefaultProps,
- getComponent,
- getListeners,
-} from '../_util/props-util';
+import { hasProp, getOptionProps, initDefaultProps, getComponent } from '../_util/props-util';
+import classNames from 'classnames';
import BaseMixin from '../_util/BaseMixin';
import { WeekPickerProps } from './interface';
import interopDefault from '../_util/interopDefault';
@@ -21,24 +17,17 @@ function formatValue(value, format) {
function noop() {}
export default {
- // static defaultProps = {
- // format: 'YYYY-wo',
- // allowClear: true,
- // };
-
- // private input: any;
name: 'AWeekPicker',
mixins: [BaseMixin],
- model: {
- prop: 'value',
- event: 'change',
- },
+ inheritAttrs: false,
props: initDefaultProps(WeekPickerProps(), {
format: 'gggg-wo',
allowClear: true,
}),
- inject: {
- configProvider: { default: () => ConfigConsumerProps },
+ setup() {
+ return {
+ configProvider: inject('configProvider', ConfigConsumerProps),
+ };
},
data() {
const value = this.value || this.defaultValue;
@@ -82,10 +71,13 @@ export default {
});
},
methods: {
+ saveInput(node) {
+ this.input = node;
+ },
weekDateRender(current) {
const selectedValue = this.$data._value;
- const { _prefixCls: prefixCls, $scopedSlots } = this;
- const dateRender = this.dateRender || $scopedSlots.dateRender;
+ const { _prefixCls: prefixCls, $slots } = this;
+ const dateRender = this.dateRender || $slots.dateRender;
const dateNode = dateRender ? dateRender(current) : current.date();
if (
selectedValue &&
@@ -118,15 +110,15 @@ export default {
this.handleChange(null);
},
focus() {
- this.$refs.input.focus();
+ this.input.focus();
},
blur() {
- this.$refs.input.blur();
+ this.input.blur();
},
renderFooter(...args) {
- const { _prefixCls: prefixCls, $scopedSlots } = this;
- const renderExtraFooter = this.renderExtraFooter || $scopedSlots.renderExtraFooter;
+ const { _prefixCls: prefixCls, $slots } = this;
+ const renderExtraFooter = this.renderExtraFooter || $slots.renderExtraFooter;
return renderExtraFooter ? (
) : null;
@@ -134,7 +126,7 @@ export default {
},
render() {
- const props = getOptionProps(this);
+ const props = { ...getOptionProps(this), ...this.$attrs };
let suffixIcon = getComponent(this, 'suffixIcon');
suffixIcon = Array.isArray(suffixIcon) ? suffixIcon[0] : suffixIcon;
const {
@@ -150,22 +142,21 @@ export default {
disabledDate,
defaultPickerValue,
$data,
- $scopedSlots,
+ $slots,
} = this;
- const listeners = getListeners(this);
const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('calendar', customizePrefixCls);
this._prefixCls = prefixCls;
const { _value: pickerValue, _open: open } = $data;
- const { focus = noop, blur = noop } = listeners;
+ const { class: className, style, id, onFocus = noop, onBlur = noop } = props;
if (pickerValue && localeCode) {
pickerValue.locale(localeCode);
}
const placeholder = hasProp(this, 'placeholder') ? this.placeholder : locale.lang.placeholder;
- const weekDateRender = this.dateRender || $scopedSlots.dateRender || this.weekDateRender;
+ const weekDateRender = this.dateRender || $slots.dateRender || this.weekDateRender;
const calendar = (
{clearIcon}
{inputIcon}
@@ -206,24 +197,18 @@ export default {
);
};
const vcDatePickerProps = {
- props: {
- ...props,
- calendar,
- prefixCls: `${prefixCls}-picker-container`,
- value: pickerValue,
- open,
- },
- on: {
- ...listeners,
- change: this.handleChange,
- openChange: this.handleOpenChange,
- },
+ ...props,
+ calendar,
+ prefixCls: `${prefixCls}-picker-container`,
+ value: pickerValue,
+ open,
+ onChange: this.handleChange,
+ onOpenChange: this.handleOpenChange,
style: popupStyle,
- scopedSlots: { default: input, ...$scopedSlots },
};
return (
-
-
+
+
);
},
diff --git a/components/date-picker/createPicker.js b/components/date-picker/createPicker.js
index c7a7bf37e..bab5b65a7 100644
--- a/components/date-picker/createPicker.js
+++ b/components/date-picker/createPicker.js
@@ -1,3 +1,4 @@
+import { inject } from 'vue';
import * as moment from 'moment';
import omit from 'lodash/omit';
import MonthCalendar from '../vc-calendar/src/MonthCalendar';
@@ -12,10 +13,8 @@ import {
hasProp,
getOptionProps,
initDefaultProps,
- mergeProps,
getComponent,
isValidElement,
- getListeners,
} from '../_util/props-util';
import { cloneElement } from '../_util/vnode';
import { formatDate } from './utils';
@@ -24,20 +23,18 @@ import { formatDate } from './utils';
// value?: moment.Moment;
// prefixCls: string;
// }
-function noop() {}
export default function createPicker(TheCalendar, props) {
return {
+ inheritAttrs: false,
props: initDefaultProps(props, {
allowClear: true,
showToday: true,
}),
mixins: [BaseMixin],
- model: {
- prop: 'value',
- event: 'change',
- },
- inject: {
- configProvider: { default: () => ConfigConsumerProps },
+ setup() {
+ return {
+ configProvider: inject('configProvider', ConfigConsumerProps),
+ };
},
data() {
const value = this.value || this.defaultValue;
@@ -79,6 +76,9 @@ export default function createPicker(TheCalendar, props) {
},
},
methods: {
+ saveInput(node) {
+ this.input = node;
+ },
clearSelection(e) {
e.preventDefault();
e.stopPropagation();
@@ -106,16 +106,15 @@ export default function createPicker(TheCalendar, props) {
this.$emit('openChange', open);
},
focus() {
- this.$refs.input.focus();
+ this.input.focus();
},
blur() {
- this.$refs.input.blur();
+ this.input.blur();
},
renderFooter(...args) {
- const { $scopedSlots, $slots, _prefixCls: prefixCls } = this;
- const renderExtraFooter =
- this.renderExtraFooter || $scopedSlots.renderExtraFooter || $slots.renderExtraFooter;
+ const { $slots, _prefixCls: prefixCls } = this;
+ const renderExtraFooter = this.renderExtraFooter || $slots.renderExtraFooter;
return renderExtraFooter ? (