Skip to content

Commit e13f4c5

Browse files
committed
fix: DatePicker
Fixed the issue where the component lost focus after selecting the date. Fixed the issue that cause Safari to unresponsive. Fixed the issue where WeekPicker's date selection box was not aligned with the input box. add da_DK he_IL hu_HU id_ID
1 parent 7422026 commit e13f4c5

File tree

12 files changed

+140
-40
lines changed

12 files changed

+140
-40
lines changed

components/date-picker/RangePicker.jsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ function fixLocale (value, localeCode) {
5050
if (!value || value.length === 0) {
5151
return
5252
}
53-
if (value[0]) {
54-
value[0].locale(localeCode)
53+
const [start, end] = value
54+
if (start) {
55+
start.locale(localeCode)
5556
}
56-
if (value[1]) {
57-
value[1].locale(localeCode)
57+
if (end) {
58+
end.locale(localeCode)
5859
}
5960
}
6061

@@ -73,9 +74,10 @@ export default {
7374
},
7475
data () {
7576
const value = this.value || this.defaultValue || []
77+
const [start, end] = value
7678
if (
77-
value[0] && !interopDefault(moment).isMoment(value[0]) ||
78-
value[1] && !interopDefault(moment).isMoment(value[1])
79+
start && !interopDefault(moment).isMoment(start) ||
80+
end && !interopDefault(moment).isMoment(end)
7981
) {
8082
throw new Error(
8183
'The value/defaultValue of RangePicker must be a moment object array after `[email protected]`, ' +
@@ -127,11 +129,11 @@ export default {
127129
sShowDate: getShowDateFromValue(value) || sShowDate,
128130
}))
129131
}
132+
const [start, end] = value
130133
this.$emit('change', value, [
131-
formatValue(value[0], this.format),
132-
formatValue(value[1], this.format),
134+
formatValue(start, this.format),
135+
formatValue(end, this.format),
133136
])
134-
this.focus()
135137
},
136138

137139
handleOpenChange (open) {
@@ -143,6 +145,10 @@ export default {
143145
this.clearHoverValue()
144146
}
145147
this.$emit('openChange', open)
148+
149+
if (!open) {
150+
this.focus()
151+
}
146152
},
147153

148154
handleShowDateChange (showDate) {
@@ -160,7 +166,8 @@ export default {
160166
},
161167

162168
handleCalendarInputSelect (value) {
163-
if (!value[0]) {
169+
const [start] = value
170+
if (!start) {
164171
return
165172
}
166173
this.setState(({ sShowDate }) => ({
@@ -317,8 +324,8 @@ export default {
317324
if (props.showTime) {
318325
pickerStyle.width = '350px'
319326
}
320-
321-
const clearIcon = (!props.disabled && props.allowClear && value && (value[0] || value[1])) ? (
327+
const [startValue, endValue] = value
328+
const clearIcon = (!props.disabled && props.allowClear && value && (startValue || endValue)) ? (
322329
<Icon
323330
type='close-circle'
324331
class={`${prefixCls}-picker-clear`}
@@ -339,8 +346,7 @@ export default {
339346
)
340347

341348
const input = ({ value: inputValue }) => {
342-
const start = inputValue[0]
343-
const end = inputValue[1]
349+
const [start, end] = inputValue
344350
return (
345351
<span class={props.pickerInputClass}>
346352
<input

components/date-picker/WeekPicker.jsx

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,22 @@ export default {
4040
)
4141
}
4242
return {
43-
sValue: value,
43+
_value: value,
44+
_open: this.open,
4445
}
4546
},
4647
watch: {
4748
value (val) {
48-
this.setState({ sValue: val })
49+
this.setState({ _value: val })
50+
},
51+
open (val) {
52+
this.setState({ _open: val })
4953
},
5054
},
5155

5256
methods: {
5357
weekDateRender (current) {
54-
const selectedValue = this.sValue
58+
const selectedValue = this.$data._value
5559
const { prefixCls } = this
5660
if (selectedValue &&
5761
current.year() === selectedValue.year() &&
@@ -72,10 +76,19 @@ export default {
7276
},
7377
handleChange (value) {
7478
if (!hasProp(this, 'value')) {
75-
this.setState({ sValue: value })
79+
this.setState({ _value: value })
7680
}
7781
this.$emit('change', value, formatValue(value, this.format))
78-
this.focus()
82+
},
83+
handleOpenChange (open) {
84+
if (!hasProp(this, 'open')) {
85+
this.setState({ _open: open })
86+
}
87+
this.$emit('openChange', open)
88+
89+
if (!open) {
90+
this.focus()
91+
}
7992
},
8093
clearSelection (e) {
8194
e.preventDefault()
@@ -99,8 +112,9 @@ export default {
99112
const {
100113
prefixCls, disabled, pickerClass, popupStyle,
101114
pickerInputClass, format, allowClear, locale, localeCode, disabledDate,
102-
sValue: pickerValue, $listeners, $scopedSlots,
115+
$data, $listeners, $scopedSlots,
103116
} = this
117+
const { _value: pickerValue, _open: open } = $data
104118
const { focus = noop, blur = noop } = $listeners
105119

106120
if (pickerValue && localeCode) {
@@ -121,7 +135,7 @@ export default {
121135
disabledDate={disabledDate}
122136
/>
123137
)
124-
const clearIcon = (!disabled && allowClear && this.sValue) ? (
138+
const clearIcon = (!disabled && allowClear && $data._value) ? (
125139
<Icon
126140
type='close-circle'
127141
class={`${prefixCls}-picker-clear`}
@@ -143,7 +157,7 @@ export default {
143157

144158
const input = ({ value }) => {
145159
return (
146-
<span>
160+
<span style={{ display: 'inline-block', width: '100%' }}>
147161
<input
148162
ref='input'
149163
disabled={disabled}
@@ -165,10 +179,12 @@ export default {
165179
calendar,
166180
prefixCls: `${prefixCls}-picker-container`,
167181
value: pickerValue,
182+
open,
168183
},
169184
on: {
170185
...$listeners,
171186
change: this.handleChange,
187+
openChange: this.handleOpenChange,
172188
},
173189
style: popupStyle,
174190
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`WeekPicker should support style prop 1`] = `<span class="ant-calendar-picker" style="width: 400px;"><span class=""><input readonly="true" placeholder="Select date" class="ant-calendar-picker-input ant-input"><i class="ant-calendar-picker-icon anticon anticon-calendar"><svg viewBox="64 64 896 896" data-icon="calendar" width="1em" height="1em" fill="currentColor" aria-hidden="true" class=""><path d="M880 184H712v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H384v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H144c-17.7 0-32 14.3-32 32v664c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V216c0-17.7-14.3-32-32-32zm-40 656H184V460h656v380zM184 392V256h128v48c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-48h256v48c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-48h128v136H184z"></path></svg></i></span></span>`;
3+
exports[`WeekPicker should support style prop 1`] = `<span class="ant-calendar-picker" style="width: 400px;"><span class="" style="display: inline-block; width: 100%;"><input readonly="true" placeholder="Select date" class="ant-calendar-picker-input ant-input"><i class="ant-calendar-picker-icon anticon anticon-calendar"><svg viewBox="64 64 896 896" data-icon="calendar" width="1em" height="1em" fill="currentColor" aria-hidden="true" class=""><path d="M880 184H712v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H384v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H144c-17.7 0-32 14.3-32 32v664c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V216c0-17.7-14.3-32-32-32zm-40 656H184V460h656v380zM184 392V256h128v48c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-48h256v48c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-48h128v136H184z"></path></svg></i></span></span>`;

0 commit comments

Comments
 (0)