Skip to content

Commit a47ebe1

Browse files
emman27marcosmoura
authored andcommitted
feat(MdDatepicker): Debounce the conversion into a date object (#1666)
* feat(MdDatepicker): Debounce the conversion into a date object * feat(MdDatepicker): Use core utils debounce instead * feat(MdDatepicker): Fix wrongly scoped debounce and allow the mdDebounce prop * Capitalize MdDebounce to avoid conflict with props Signed-off-by: Emman <eygohlolz@gmail.com>
1 parent 7cdcb66 commit a47ebe1

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

docs/app/pages/Components/Datepicker/Datepicker.vue

+6
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@
8484
type: 'Boolean',
8585
description: 'Override native browser pickers by changing type of input to text.',
8686
defaults: 'true'
87+
},
88+
{
89+
name: 'md-debounce',
90+
type: 'Number',
91+
description: 'Debounces the conversion of plaintext into a date object. Set to a longer time if your users type slowly, or shorter if your users type really fast.',
92+
defaults: 1000
8793
}
8894
]
8995
},

src/components/MdDatepicker/MdDatepicker.vue

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<md-field :class="['md-datepicker', { 'md-native': !this.mdOverrideNative }]" md-clearable>
33
<md-date-icon class="md-date-icon" @click.native="toggleDialog" />
4-
<md-input :type="type" ref="input" v-model="modelDate" @focus.native="onFocus" pattern="[0-9]{4}-[0-9]{2}-[0-9]{2}" />
4+
<md-input :type="type" ref="input" :value="modelDate" @input="onInput" @focus.native="onFocus" pattern="[0-9]{4}-[0-9]{2}-[0-9]{2}" />
55

66
<slot />
77

@@ -28,6 +28,7 @@
2828
import MdOverlay from 'components/MdOverlay/MdOverlay'
2929
import MdDatepickerDialog from './MdDatepickerDialog'
3030
import MdDateIcon from 'core/icons/MdDateIcon'
31+
import MdDebounce from 'core/utils/MdDebounce'
3132
import MdField from 'components/MdField/MdField'
3233
import MdInput from 'components/MdField/MdInput/MdInput'
3334
@@ -54,6 +55,10 @@
5455
mdImmediately: {
5556
type: Boolean,
5657
default: false
58+
},
59+
MdDebounce: {
60+
type: Number,
61+
default: 1000
5762
}
5863
},
5964
data: () => ({
@@ -93,6 +98,12 @@
9398
}
9499
},
95100
methods: {
101+
onInput(value) {
102+
const parsedDate = parse(value)
103+
if (isValid(parsedDate)) {
104+
this.selectedDate = parsedDate
105+
}
106+
},
96107
toggleDialog () {
97108
if (!isFirefox || this.mdOverrideNative) {
98109
this.showDialog = !this.showDialog
@@ -126,6 +137,7 @@
126137
}
127138
},
128139
created () {
140+
this.onInput = MdDebounce(this.onInput, this.MdDebounce)
129141
this.modelDate = this.dateToHTMLString(this.value)
130142
this.selectedDate = this.value
131143
}

0 commit comments

Comments
 (0)