|
1 | 1 | <template>
|
2 | 2 | <md-field :class="['md-datepicker', { 'md-native': !mdOverrideNative }]" :md-clearable="mdClearable" @md-clear="onClear">
|
3 |
| - <md-date-icon class="md-date-icon" @click.native="toggleDialog" /> |
4 |
| - <md-input :type="type" ref="input" v-model="inputDate" @focus.native="onFocus" :pattern="pattern" /> |
| 3 | + <md-date-icon class="md-date-icon" @click.native="toggleDialog(true)" /> |
| 4 | + <md-input :type="type" ref="input" v-model="inputDate" @focus.native="onFocus" @focusout.native="onFocusOut" :pattern="pattern" /> |
5 | 5 |
|
6 | 6 | <slot />
|
7 | 7 |
|
8 | 8 | <keep-alive>
|
9 | 9 | <md-datepicker-dialog
|
10 | 10 | v-if="showDialog"
|
| 11 | + ref="mdRef" |
11 | 12 | :md-date.sync="localDate"
|
12 | 13 | :md-disabled-dates="mdDisabledDates"
|
13 | 14 | :mdImmediately="mdImmediately"
|
14 |
| - @md-closed="toggleDialog" |
| 15 | + @md-closed="toggleDialog(false)" |
15 | 16 | :md-placement="mdPlacement"
|
16 | 17 | />
|
17 | 18 | </keep-alive>
|
18 | 19 |
|
19 |
| - <md-overlay class="md-datepicker-overlay" md-fixed :md-active="showDialog" @click="toggleDialog" /> |
| 20 | + <md-overlay class="md-datepicker-overlay" md-fixed :md-active="showDialog" @click="toggleDialog(false)" /> |
20 | 21 | </md-field>
|
21 | 22 | </template>
|
22 | 23 |
|
|
50 | 51 | type: Boolean,
|
51 | 52 | default: true
|
52 | 53 | },
|
| 54 | + mdCloseOnBlur: { |
| 55 | + type: Boolean, |
| 56 | + default: true |
| 57 | + }, |
53 | 58 | mdOverrideNative: {
|
54 | 59 | type: Boolean,
|
55 | 60 | default: true
|
|
141 | 146 | }
|
142 | 147 | },
|
143 | 148 | watch: {
|
144 |
| - inputDate (value) { |
| 149 | + inputDate () { |
145 | 150 | this.inputDateToLocalDate()
|
146 | 151 | },
|
147 | 152 | localDate () {
|
|
186 | 191 | }
|
187 | 192 | },
|
188 | 193 | methods: {
|
189 |
| - toggleDialog () { |
| 194 | + toggleDialog (newState = null) { |
190 | 195 | if (!isFirefox || this.mdOverrideNative) {
|
191 |
| - this.showDialog = !this.showDialog |
| 196 | + // If new state (boolean) is provide, assign that to showDialog, else just toggle |
| 197 | + this.showDialog = newState === null ? !this.showDialog : newState |
192 | 198 | if (this.showDialog) {
|
193 | 199 | this.$emit('md-opened')
|
194 | 200 | } else {
|
|
200 | 206 | },
|
201 | 207 | onFocus () {
|
202 | 208 | if (this.mdOpenOnFocus) {
|
203 |
| - this.toggleDialog() |
| 209 | + this.toggleDialog(true) |
| 210 | + } |
| 211 | + }, |
| 212 | + onFocusOut (e) { |
| 213 | + if (this.mdCloseOnBlur && this.$refs.mdRef.$el !== e.relatedTarget) { |
| 214 | + this.toggleDialog(false) |
204 | 215 | }
|
205 | 216 | },
|
206 | 217 | inputDateToLocalDate () {
|
|
0 commit comments