ant-design-vue/components/vc-time-picker/TimePicker.jsx

394 lines
9.8 KiB
Vue
Raw Normal View History

2019-03-04 13:00:08 +00:00
import moment from 'moment';
2020-08-31 08:53:19 +00:00
import classNames from '../_util/classNames';
2019-01-12 03:33:27 +00:00
import PropTypes from '../_util/vue-types';
import BaseMixin from '../_util/BaseMixin';
2019-05-28 03:37:38 +00:00
import {
initDefaultProps,
hasProp,
getComponent,
2019-05-28 03:37:38 +00:00
isValidElement,
getEvents,
} from '../_util/props-util';
2019-03-04 13:00:08 +00:00
import { cloneElement } from '../_util/vnode';
2019-01-12 03:33:27 +00:00
import Trigger from '../vc-trigger';
import Panel from './Panel';
import placements from './placements';
2020-10-12 05:27:16 +00:00
import { defineComponent } from 'vue';
2018-03-19 02:16:27 +00:00
2019-01-12 03:33:27 +00:00
function noop() {}
2020-07-21 08:46:39 +00:00
function refFn(field, component) {
this[field] = component;
}
2018-03-07 14:21:55 +00:00
2020-10-12 05:27:16 +00:00
export default defineComponent({
name: 'VcTimePicker',
2019-02-01 09:23:00 +00:00
mixins: [BaseMixin],
2020-07-21 08:46:39 +00:00
inheritAttrs: false,
2019-01-12 03:33:27 +00:00
props: initDefaultProps(
{
prefixCls: PropTypes.string,
clearText: PropTypes.string,
value: PropTypes.any,
defaultOpenValue: {
type: Object,
default: () => {
return moment();
},
2018-03-08 15:02:04 +00:00
},
inputReadOnly: PropTypes.looseBool,
disabled: PropTypes.looseBool,
allowEmpty: PropTypes.looseBool,
2019-01-12 03:33:27 +00:00
defaultValue: PropTypes.any,
open: PropTypes.looseBool,
defaultOpen: PropTypes.looseBool,
2019-01-12 03:33:27 +00:00
align: PropTypes.object,
placement: PropTypes.any,
transitionName: PropTypes.string,
getPopupContainer: PropTypes.func,
placeholder: PropTypes.string,
format: PropTypes.string,
showHour: PropTypes.looseBool,
showMinute: PropTypes.looseBool,
showSecond: PropTypes.looseBool,
2019-01-12 03:33:27 +00:00
popupClassName: PropTypes.string,
2019-03-04 13:00:08 +00:00
popupStyle: PropTypes.object,
2019-01-12 03:33:27 +00:00
disabledHours: PropTypes.func,
disabledMinutes: PropTypes.func,
disabledSeconds: PropTypes.func,
hideDisabledOptions: PropTypes.looseBool,
2019-01-12 03:33:27 +00:00
// onChange: PropTypes.func,
2019-03-04 13:00:08 +00:00
// onAmPmChange: PropTypes.func,
2019-01-12 03:33:27 +00:00
// onOpen: PropTypes.func,
// onClose: PropTypes.func,
// onFocus: PropTypes.func,
// onBlur: PropTypes.func,
name: PropTypes.string,
autocomplete: PropTypes.string,
use12Hours: PropTypes.looseBool,
2019-01-12 03:33:27 +00:00
hourStep: PropTypes.number,
minuteStep: PropTypes.number,
secondStep: PropTypes.number,
focusOnOpen: PropTypes.looseBool,
2019-01-12 03:33:27 +00:00
// onKeyDown: PropTypes.func,
autofocus: PropTypes.looseBool,
2019-01-12 03:33:27 +00:00
id: PropTypes.string,
inputIcon: PropTypes.any,
clearIcon: PropTypes.any,
addon: PropTypes.func,
},
{
clearText: 'clear',
prefixCls: 'rc-time-picker',
defaultOpen: false,
inputReadOnly: false,
popupClassName: '',
2019-03-04 13:00:08 +00:00
popupStyle: {},
2019-01-12 03:33:27 +00:00
align: {},
allowEmpty: true,
showHour: true,
showMinute: true,
showSecond: true,
disabledHours: noop,
disabledMinutes: noop,
disabledSeconds: noop,
hideDisabledOptions: false,
placement: 'bottomLeft',
use12Hours: false,
focusOnOpen: false,
2018-03-08 15:02:04 +00:00
},
2019-01-12 03:33:27 +00:00
),
data() {
2020-07-21 08:46:39 +00:00
this.saveInputRef = refFn.bind(this, 'picker');
this.savePanelRef = refFn.bind(this, 'panelInstance');
2019-01-12 03:33:27 +00:00
const { defaultOpen, defaultValue, open = defaultOpen, value = defaultValue } = this;
2018-03-08 15:02:04 +00:00
return {
sOpen: open,
sValue: value,
2019-01-12 03:33:27 +00:00
};
2018-03-08 15:02:04 +00:00
},
2018-03-07 14:21:55 +00:00
2018-03-08 15:02:04 +00:00
watch: {
2019-01-12 03:33:27 +00:00
value(val) {
2018-03-07 14:21:55 +00:00
this.setState({
2018-03-08 15:02:04 +00:00
sValue: val,
2019-01-12 03:33:27 +00:00
});
2018-03-08 15:02:04 +00:00
},
2019-01-12 03:33:27 +00:00
open(val) {
2018-03-08 15:02:04 +00:00
if (val !== undefined) {
this.setState({
sOpen: val,
2019-01-12 03:33:27 +00:00
});
2018-03-08 15:02:04 +00:00
}
},
},
2019-02-01 09:23:00 +00:00
mounted() {
this.$nextTick(() => {
2020-07-17 09:36:58 +00:00
if (this.autofocus) {
2019-02-01 09:23:00 +00:00
this.focus();
}
});
},
2018-03-08 15:02:04 +00:00
methods: {
2019-01-12 03:33:27 +00:00
onPanelChange(value) {
this.setValue(value);
2018-03-08 15:02:04 +00:00
},
2018-03-07 14:21:55 +00:00
2019-03-04 13:00:08 +00:00
onAmPmChange(ampm) {
this.__emit('amPmChange', ampm);
},
onClear(event) {
event.stopPropagation();
2019-01-12 03:33:27 +00:00
this.setValue(null);
this.setOpen(false);
2018-03-08 15:02:04 +00:00
},
2018-03-07 14:21:55 +00:00
2019-01-12 03:33:27 +00:00
onVisibleChange(open) {
this.setOpen(open);
2018-03-08 15:02:04 +00:00
},
2018-03-07 14:21:55 +00:00
2019-01-12 03:33:27 +00:00
onEsc() {
this.setOpen(false);
this.focus();
2018-03-08 15:02:04 +00:00
},
2018-03-07 14:21:55 +00:00
2019-01-12 03:33:27 +00:00
onKeyDown(e) {
2018-03-08 15:02:04 +00:00
if (e.keyCode === 40) {
2019-01-12 03:33:27 +00:00
this.setOpen(true);
2018-03-08 15:02:04 +00:00
}
},
2019-01-12 03:33:27 +00:00
onKeyDown2(e) {
this.__emit('keydown', e);
2018-03-08 15:02:04 +00:00
},
2018-03-07 14:21:55 +00:00
2019-01-12 03:33:27 +00:00
setValue(value) {
2018-03-08 15:02:04 +00:00
if (!hasProp(this, 'value')) {
this.setState({
sValue: value,
2019-01-12 03:33:27 +00:00
});
2018-03-08 15:02:04 +00:00
}
2019-01-12 03:33:27 +00:00
this.__emit('change', value);
2018-03-08 15:02:04 +00:00
},
2018-03-07 14:21:55 +00:00
2019-01-12 03:33:27 +00:00
getFormat() {
const { format, showHour, showMinute, showSecond, use12Hours } = this;
2018-03-08 15:02:04 +00:00
if (format) {
2019-01-12 03:33:27 +00:00
return format;
2018-03-08 15:02:04 +00:00
}
2018-03-07 14:21:55 +00:00
2018-03-08 15:02:04 +00:00
if (use12Hours) {
2019-01-12 03:33:27 +00:00
const fmtString = [showHour ? 'h' : '', showMinute ? 'mm' : '', showSecond ? 'ss' : '']
.filter(item => !!item)
.join(':');
2018-03-08 15:02:04 +00:00
2019-01-12 03:33:27 +00:00
return fmtString.concat(' a');
2018-03-08 15:02:04 +00:00
}
2018-03-07 14:21:55 +00:00
2019-01-12 03:33:27 +00:00
return [showHour ? 'HH' : '', showMinute ? 'mm' : '', showSecond ? 'ss' : '']
.filter(item => !!item)
.join(':');
2018-03-08 15:02:04 +00:00
},
2018-03-07 14:21:55 +00:00
2019-01-12 03:33:27 +00:00
getPanelElement() {
2018-03-08 15:02:04 +00:00
const {
2019-01-12 03:33:27 +00:00
prefixCls,
placeholder,
disabledHours,
addon,
disabledMinutes,
disabledSeconds,
hideDisabledOptions,
inputReadOnly,
showHour,
showMinute,
showSecond,
defaultOpenValue,
clearText,
use12Hours,
focusOnOpen,
onKeyDown2,
hourStep,
minuteStep,
secondStep,
2018-03-08 15:02:04 +00:00
sValue,
2019-01-12 03:33:27 +00:00
} = this;
const clearIcon = getComponent(this, 'clearIcon');
2018-03-08 15:02:04 +00:00
return (
<Panel
clearText={clearText}
prefixCls={`${prefixCls}-panel`}
2020-07-21 08:46:39 +00:00
ref={this.savePanelRef}
2018-03-08 15:02:04 +00:00
value={sValue}
inputReadOnly={inputReadOnly}
onChange={this.onPanelChange}
2019-03-04 13:00:08 +00:00
onAmPmChange={this.onAmPmChange}
2018-03-08 15:02:04 +00:00
defaultOpenValue={defaultOpenValue}
showHour={showHour}
showMinute={showMinute}
showSecond={showSecond}
onEsc={this.onEsc}
format={this.getFormat()}
placeholder={placeholder}
disabledHours={disabledHours}
disabledMinutes={disabledMinutes}
disabledSeconds={disabledSeconds}
hideDisabledOptions={hideDisabledOptions}
use12Hours={use12Hours}
hourStep={hourStep}
minuteStep={minuteStep}
secondStep={secondStep}
focusOnOpen={focusOnOpen}
onKeydown={onKeyDown2}
clearIcon={clearIcon}
addon={addon}
/>
2019-01-12 03:33:27 +00:00
);
2018-03-08 15:02:04 +00:00
},
2018-03-07 14:21:55 +00:00
2019-01-12 03:33:27 +00:00
getPopupClassName() {
Feat 1.5.0 (#1853) * feat: add Result component * fix: update md template tag html>tpl - fix `result` typo - update jest `result` snapshots * refactor: svg file to functional component icon - update jest snapshot * feat: add result * Feat descriptions (#1251) * feat: add descriptions * fix: add descriptions types and fix docs * fix: lint change code * fix: demo warning * fix: update demo, snapshot and remove classnames * test: add descriptions test * fix: descriptions demo (#1498) * feat: add page header (#1250) * feat: add page-header component * update site: page-header * ts definition update: page-header * get page-header props with getComponentFromProp func * optimize page-header * doc: add page-header actions.md responsive.md * breadcrumb itemRender add pure function support * style: format code * feat: update style to 3.23.6 from 2.13.6 * feat: update style to 3.26.8 from 3.23.6 * chore: update util * chore: update util * feat: update affix * feat: update alert * feat: update anchor * feat: update auto-complete * feat: update avatar * feat: update back-top * feat: update badge * feat: update button * feat: update breadcrumb * feat: update ts * docs: update doc * feat: update calendat * feat: update card * feat: update carousel * feat: update carousel * feat: update checkbox * feat: update comment * feat: update config-provider * docs: update doc * feat: update collapse * feat: update locale * feat: update date-picker * feat: update divider * feat: update drawer * feat: update dropdown * feat: update rc-trigger * feat: update dropdown * feat: update empty * test: add empty test * feat: update form * feat: update form * feat: update spin * feat: update grid * docs: update grid doc * feat: update icon * feat: update slider * feat: update textarea * feat: update input-number * feat: update layout * feat: update list * feat: update menu * feat: meaage add key for update content * feat: modal add closeIcon support * feat: update notification * feat: add pagination disabled support * feat: popconfirm add disabled support * test: update popover * feat: progress support custom line-gradiend * feat: update radio * test: update radio test * docs: update rate demo * feat: skeleton add avatar support number type * test: add switch test * test: update statistic test * fix: input clear icon event * feat: steps add type、 v-model、subTitle * feat: delete typography component * feat: delete Typography style * perf: update select * feat: add download transformFile previewFile actio * docs: update upload * feat: update tree-select * docs: update tree-select * feat: tree add blockNode selectable * docs: add tree demo * test: update snap * docs: updatedoc * feat: update tag * docs: update ad doc * feat: update tooltip * feat: update timeline * feat: time-picker add clearIcon * docs: update tabs * feat: transfer support custom children * test: update transfer test * feat: update table * test: update table test * test: update test * feat: calendar update locale * test: update test snap * feat: add mentions (#1790) * feat: mentions style * feat: theme default * feat: add mentions component * feat: mentions API * feat: add unit test for mentions * feat: update mentions demo * perf: model and inheritAttrs for mentions * perf: use getComponentFromProp instead of this.$props * perf: mentions rm defaultProps * feat: rm rows in mentionsProps * fix: mentions keyDown didn't work * docs: update mentions api * perf: mentions code * feat: update mentions * bump 1.5.0-alpha.1 * feat: pageheader add ghost prop * docs: update descriptions demo * chore: page-header add ghost type * fix: color error * feat: update to 3.26.12 * fix: some prop default value * fix(typo): form, carousel, upload. duplicate identifier (#1848) * Add Mentions Type (#1845) * feat: add mentions type * feat: add mentions in ant-design-vue.d.ts * docs: update doc * docs: add changelog * fix: mentions getPopupCotainer value (#1850) * docs: update doc * docs: uptate demo * docs: update demo * docs: delete demo * docs: delete doc * test: update snapshots * style: format code * chore: update travis * docs: update demo Co-authored-by: Sendya <18x@loacg.com> Co-authored-by: zkwolf <chenhao5866@gmail.com> Co-authored-by: drafish <xwlyy1991@163.com> Co-authored-by: Amour1688 <31695475+Amour1688@users.noreply.github.com>
2020-03-07 11:45:13 +00:00
const { showHour, showMinute, showSecond, use12Hours, prefixCls, popupClassName } = this;
2019-01-12 03:33:27 +00:00
let selectColumnCount = 0;
2018-03-08 15:02:04 +00:00
if (showHour) {
2019-01-12 03:33:27 +00:00
selectColumnCount += 1;
2018-03-07 14:21:55 +00:00
}
2018-03-08 15:02:04 +00:00
if (showMinute) {
2019-01-12 03:33:27 +00:00
selectColumnCount += 1;
2018-03-08 15:02:04 +00:00
}
if (showSecond) {
2019-01-12 03:33:27 +00:00
selectColumnCount += 1;
2018-03-08 15:02:04 +00:00
}
if (use12Hours) {
2019-01-12 03:33:27 +00:00
selectColumnCount += 1;
2018-03-08 15:02:04 +00:00
}
Feat 1.5.0 (#1853) * feat: add Result component * fix: update md template tag html>tpl - fix `result` typo - update jest `result` snapshots * refactor: svg file to functional component icon - update jest snapshot * feat: add result * Feat descriptions (#1251) * feat: add descriptions * fix: add descriptions types and fix docs * fix: lint change code * fix: demo warning * fix: update demo, snapshot and remove classnames * test: add descriptions test * fix: descriptions demo (#1498) * feat: add page header (#1250) * feat: add page-header component * update site: page-header * ts definition update: page-header * get page-header props with getComponentFromProp func * optimize page-header * doc: add page-header actions.md responsive.md * breadcrumb itemRender add pure function support * style: format code * feat: update style to 3.23.6 from 2.13.6 * feat: update style to 3.26.8 from 3.23.6 * chore: update util * chore: update util * feat: update affix * feat: update alert * feat: update anchor * feat: update auto-complete * feat: update avatar * feat: update back-top * feat: update badge * feat: update button * feat: update breadcrumb * feat: update ts * docs: update doc * feat: update calendat * feat: update card * feat: update carousel * feat: update carousel * feat: update checkbox * feat: update comment * feat: update config-provider * docs: update doc * feat: update collapse * feat: update locale * feat: update date-picker * feat: update divider * feat: update drawer * feat: update dropdown * feat: update rc-trigger * feat: update dropdown * feat: update empty * test: add empty test * feat: update form * feat: update form * feat: update spin * feat: update grid * docs: update grid doc * feat: update icon * feat: update slider * feat: update textarea * feat: update input-number * feat: update layout * feat: update list * feat: update menu * feat: meaage add key for update content * feat: modal add closeIcon support * feat: update notification * feat: add pagination disabled support * feat: popconfirm add disabled support * test: update popover * feat: progress support custom line-gradiend * feat: update radio * test: update radio test * docs: update rate demo * feat: skeleton add avatar support number type * test: add switch test * test: update statistic test * fix: input clear icon event * feat: steps add type、 v-model、subTitle * feat: delete typography component * feat: delete Typography style * perf: update select * feat: add download transformFile previewFile actio * docs: update upload * feat: update tree-select * docs: update tree-select * feat: tree add blockNode selectable * docs: add tree demo * test: update snap * docs: updatedoc * feat: update tag * docs: update ad doc * feat: update tooltip * feat: update timeline * feat: time-picker add clearIcon * docs: update tabs * feat: transfer support custom children * test: update transfer test * feat: update table * test: update table test * test: update test * feat: calendar update locale * test: update test snap * feat: add mentions (#1790) * feat: mentions style * feat: theme default * feat: add mentions component * feat: mentions API * feat: add unit test for mentions * feat: update mentions demo * perf: model and inheritAttrs for mentions * perf: use getComponentFromProp instead of this.$props * perf: mentions rm defaultProps * feat: rm rows in mentionsProps * fix: mentions keyDown didn't work * docs: update mentions api * perf: mentions code * feat: update mentions * bump 1.5.0-alpha.1 * feat: pageheader add ghost prop * docs: update descriptions demo * chore: page-header add ghost type * fix: color error * feat: update to 3.26.12 * fix: some prop default value * fix(typo): form, carousel, upload. duplicate identifier (#1848) * Add Mentions Type (#1845) * feat: add mentions type * feat: add mentions in ant-design-vue.d.ts * docs: update doc * docs: add changelog * fix: mentions getPopupCotainer value (#1850) * docs: update doc * docs: uptate demo * docs: update demo * docs: delete demo * docs: delete doc * test: update snapshots * style: format code * chore: update travis * docs: update demo Co-authored-by: Sendya <18x@loacg.com> Co-authored-by: zkwolf <chenhao5866@gmail.com> Co-authored-by: drafish <xwlyy1991@163.com> Co-authored-by: Amour1688 <31695475+Amour1688@users.noreply.github.com>
2020-03-07 11:45:13 +00:00
// Keep it for old compatibility
return classNames(
popupClassName,
{
[`${prefixCls}-panel-narrow`]: (!showHour || !showMinute || !showSecond) && !use12Hours,
},
`${prefixCls}-panel-column-${selectColumnCount}`,
);
2018-03-08 15:02:04 +00:00
},
2019-01-12 03:33:27 +00:00
setOpen(open) {
2018-03-08 15:02:04 +00:00
if (this.sOpen !== open) {
if (!hasProp(this, 'open')) {
2019-01-12 03:33:27 +00:00
this.setState({ sOpen: open });
2018-03-08 15:02:04 +00:00
}
if (open) {
2019-01-12 03:33:27 +00:00
this.__emit('open', { open });
2018-03-08 15:02:04 +00:00
} else {
2019-01-12 03:33:27 +00:00
this.__emit('close', { open });
2018-03-08 15:02:04 +00:00
}
}
},
2018-03-07 14:21:55 +00:00
2019-01-12 03:33:27 +00:00
focus() {
2020-07-21 08:46:39 +00:00
this.picker.focus();
2018-03-08 15:02:04 +00:00
},
2018-03-07 14:21:55 +00:00
2019-01-12 03:33:27 +00:00
blur() {
2020-07-21 08:46:39 +00:00
this.picker.blur();
2018-03-08 15:02:04 +00:00
},
2019-01-12 03:33:27 +00:00
onFocus(e) {
this.__emit('focus', e);
2018-03-08 15:02:04 +00:00
},
2019-01-12 03:33:27 +00:00
onBlur(e) {
this.__emit('blur', e);
2018-03-08 15:02:04 +00:00
},
2019-03-04 13:00:08 +00:00
renderClearButton() {
const { sValue } = this;
Feat 1.5.0 (#1853) * feat: add Result component * fix: update md template tag html>tpl - fix `result` typo - update jest `result` snapshots * refactor: svg file to functional component icon - update jest snapshot * feat: add result * Feat descriptions (#1251) * feat: add descriptions * fix: add descriptions types and fix docs * fix: lint change code * fix: demo warning * fix: update demo, snapshot and remove classnames * test: add descriptions test * fix: descriptions demo (#1498) * feat: add page header (#1250) * feat: add page-header component * update site: page-header * ts definition update: page-header * get page-header props with getComponentFromProp func * optimize page-header * doc: add page-header actions.md responsive.md * breadcrumb itemRender add pure function support * style: format code * feat: update style to 3.23.6 from 2.13.6 * feat: update style to 3.26.8 from 3.23.6 * chore: update util * chore: update util * feat: update affix * feat: update alert * feat: update anchor * feat: update auto-complete * feat: update avatar * feat: update back-top * feat: update badge * feat: update button * feat: update breadcrumb * feat: update ts * docs: update doc * feat: update calendat * feat: update card * feat: update carousel * feat: update carousel * feat: update checkbox * feat: update comment * feat: update config-provider * docs: update doc * feat: update collapse * feat: update locale * feat: update date-picker * feat: update divider * feat: update drawer * feat: update dropdown * feat: update rc-trigger * feat: update dropdown * feat: update empty * test: add empty test * feat: update form * feat: update form * feat: update spin * feat: update grid * docs: update grid doc * feat: update icon * feat: update slider * feat: update textarea * feat: update input-number * feat: update layout * feat: update list * feat: update menu * feat: meaage add key for update content * feat: modal add closeIcon support * feat: update notification * feat: add pagination disabled support * feat: popconfirm add disabled support * test: update popover * feat: progress support custom line-gradiend * feat: update radio * test: update radio test * docs: update rate demo * feat: skeleton add avatar support number type * test: add switch test * test: update statistic test * fix: input clear icon event * feat: steps add type、 v-model、subTitle * feat: delete typography component * feat: delete Typography style * perf: update select * feat: add download transformFile previewFile actio * docs: update upload * feat: update tree-select * docs: update tree-select * feat: tree add blockNode selectable * docs: add tree demo * test: update snap * docs: updatedoc * feat: update tag * docs: update ad doc * feat: update tooltip * feat: update timeline * feat: time-picker add clearIcon * docs: update tabs * feat: transfer support custom children * test: update transfer test * feat: update table * test: update table test * test: update test * feat: calendar update locale * test: update test snap * feat: add mentions (#1790) * feat: mentions style * feat: theme default * feat: add mentions component * feat: mentions API * feat: add unit test for mentions * feat: update mentions demo * perf: model and inheritAttrs for mentions * perf: use getComponentFromProp instead of this.$props * perf: mentions rm defaultProps * feat: rm rows in mentionsProps * fix: mentions keyDown didn't work * docs: update mentions api * perf: mentions code * feat: update mentions * bump 1.5.0-alpha.1 * feat: pageheader add ghost prop * docs: update descriptions demo * chore: page-header add ghost type * fix: color error * feat: update to 3.26.12 * fix: some prop default value * fix(typo): form, carousel, upload. duplicate identifier (#1848) * Add Mentions Type (#1845) * feat: add mentions type * feat: add mentions in ant-design-vue.d.ts * docs: update doc * docs: add changelog * fix: mentions getPopupCotainer value (#1850) * docs: update doc * docs: uptate demo * docs: update demo * docs: delete demo * docs: delete doc * test: update snapshots * style: format code * chore: update travis * docs: update demo Co-authored-by: Sendya <18x@loacg.com> Co-authored-by: zkwolf <chenhao5866@gmail.com> Co-authored-by: drafish <xwlyy1991@163.com> Co-authored-by: Amour1688 <31695475+Amour1688@users.noreply.github.com>
2020-03-07 11:45:13 +00:00
const { prefixCls, allowEmpty, clearText, disabled } = this.$props;
if (!allowEmpty || !sValue || disabled) {
2019-03-04 13:00:08 +00:00
return null;
}
const clearIcon = getComponent(this, 'clearIcon');
2019-03-04 13:00:08 +00:00
if (isValidElement(clearIcon)) {
2020-07-21 08:46:39 +00:00
const { onClick } = getEvents(clearIcon) || {};
2019-03-04 13:00:08 +00:00
return cloneElement(clearIcon, {
2020-07-21 08:46:39 +00:00
onClick: (...args) => {
if (onClick) onClick(...args);
this.onClear(...args);
2019-03-04 13:00:08 +00:00
},
});
}
return (
<a
role="button"
class={`${prefixCls}-clear`}
title={clearText}
onClick={this.onClear}
tabindex={0}
2019-03-04 13:00:08 +00:00
>
{clearIcon || <i class={`${prefixCls}-clear-icon`} />}
</a>
);
},
2018-03-08 15:02:04 +00:00
},
2018-03-07 14:21:55 +00:00
2019-01-12 03:33:27 +00:00
render() {
2018-03-07 14:21:55 +00:00
const {
2019-01-12 03:33:27 +00:00
prefixCls,
placeholder,
placement,
align,
id,
disabled,
transitionName,
getPopupContainer,
name,
autocomplete,
2020-07-17 09:36:58 +00:00
autofocus,
2019-01-12 03:33:27 +00:00
inputReadOnly,
sOpen,
sValue,
onFocus,
onBlur,
2019-03-04 13:00:08 +00:00
popupStyle,
2019-01-12 03:33:27 +00:00
} = this;
2020-07-21 08:46:39 +00:00
const { class: className, style } = this.$attrs;
2019-01-12 03:33:27 +00:00
const popupClassName = this.getPopupClassName();
const inputIcon = getComponent(this, 'inputIcon');
2018-03-07 14:21:55 +00:00
return (
<Trigger
prefixCls={`${prefixCls}-panel`}
popupClassName={popupClassName}
2019-03-04 13:00:08 +00:00
popupStyle={popupStyle}
2018-03-07 14:21:55 +00:00
popupAlign={align}
builtinPlacements={placements}
popupPlacement={placement}
action={disabled ? [] : ['click']}
destroyPopupOnHide
getPopupContainer={getPopupContainer}
popupTransitionName={transitionName}
2018-03-08 15:02:04 +00:00
popupVisible={sOpen}
2018-03-07 14:21:55 +00:00
onPopupVisibleChange={this.onVisibleChange}
2020-07-21 08:46:39 +00:00
popup={this.getPanelElement()}
2018-03-07 14:21:55 +00:00
>
2020-07-21 08:46:39 +00:00
<span class={classNames(prefixCls, className)} style={style}>
2018-03-07 14:21:55 +00:00
<input
2018-03-08 15:02:04 +00:00
class={`${prefixCls}-input`}
2020-07-21 08:46:39 +00:00
ref={this.saveInputRef}
2019-01-12 03:33:27 +00:00
type="text"
2018-03-07 14:21:55 +00:00
placeholder={placeholder}
name={name}
2018-03-08 15:02:04 +00:00
onKeydown={this.onKeyDown}
2018-03-07 14:21:55 +00:00
disabled={disabled}
2019-01-12 03:33:27 +00:00
value={(sValue && sValue.format(this.getFormat())) || ''}
autocomplete={autocomplete}
2018-03-07 14:21:55 +00:00
onFocus={onFocus}
onBlur={onBlur}
2020-07-17 09:36:58 +00:00
autofocus={autofocus}
readonly={!!inputReadOnly}
2018-03-13 02:19:00 +00:00
id={id}
2018-03-07 14:21:55 +00:00
/>
2019-01-12 03:33:27 +00:00
{inputIcon || <span class={`${prefixCls}-icon`} />}
2019-03-04 13:00:08 +00:00
{this.renderClearButton()}
2018-03-07 14:21:55 +00:00
</span>
</Trigger>
2019-01-12 03:33:27 +00:00
);
2018-03-08 15:02:04 +00:00
},
2020-10-12 05:27:16 +00:00
});