Skip to content

Commit b3126a0

Browse files
committed
fix: provide scoped slot to input slot (#492)
1 parent 1bca35b commit b3126a0

File tree

1 file changed

+46
-13
lines changed

1 file changed

+46
-13
lines changed

src/date-picker.vue

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,47 @@
88
}"
99
>
1010
<div v-if="!inline" :class="`${prefixClass}-input-wrapper`" @mousedown="openPopup">
11-
<slot name="input">
11+
<slot
12+
name="input"
13+
:props="{
14+
name: 'date',
15+
type: 'text',
16+
autocomplete: 'off',
17+
value: text,
18+
class: inputClass,
19+
readonly: !editable,
20+
disabled,
21+
placeholder,
22+
...inputAttr,
23+
}"
24+
:events="{
25+
keydown: handleInputKeydown,
26+
focus: handleInputFocus,
27+
blur: handleInputBlur,
28+
input: handleInputInput,
29+
change: handleInputChange,
30+
}"
31+
>
1232
<input
1333
ref="input"
14-
v-bind="{ name: 'date', type: 'text', autocomplete: 'off', value: text, ...inputAttr }"
15-
:class="inputClass"
16-
:disabled="disabled"
17-
:readonly="!editable"
18-
:placeholder="placeholder"
19-
@keydown="handleInputKeydown"
20-
@focus="handleInputFocus"
21-
@blur="handleInputBlur"
22-
@input="handleInputInput"
23-
@change="handleInputChange"
34+
v-bind="{
35+
name: 'date',
36+
type: 'text',
37+
autocomplete: 'off',
38+
value: text,
39+
class: inputClass,
40+
readonly: !editable,
41+
disabled,
42+
placeholder,
43+
...inputAttr,
44+
}"
45+
v-on="{
46+
keydown: handleInputKeydown,
47+
focus: handleInputFocus,
48+
blur: handleInputBlur,
49+
input: handleInputInput,
50+
change: handleInputChange,
51+
}"
2452
/>
2553
</slot>
2654
<i v-if="showClearIcon" :class="`${prefixClass}-icon-clear`" @mousedown.stop="handleClear">
@@ -456,10 +484,15 @@ export default {
456484
this.$emit('update:open', false);
457485
},
458486
blur() {
459-
this.$refs.input.blur();
487+
// when use slot input
488+
if (this.$refs.input) {
489+
this.$refs.input.blur();
490+
}
460491
},
461492
focus() {
462-
this.$refs.input.focus();
493+
if (this.$refs.input) {
494+
this.$refs.input.focus();
495+
}
463496
},
464497
handleInputChange() {
465498
if (!this.editable || this.userInput === null) return;

0 commit comments

Comments
 (0)