Skip to content

Commit

Permalink
🇫🇷 [fix] Locale reactivity (#145)
Browse files Browse the repository at this point in the history
* [FIX] Locale reactivity

* update version tag

* update doc
  • Loading branch information
LouisMazel authored Mar 15, 2019
1 parent 0f8e783 commit 666d028
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-ctk-date-time-picker",
"version": "2.0.7",
"version": "2.0.8",
"description": "A vue component for select date & time (by Chronotruck)",
"author": "Louis Mazel <[email protected]>",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
input-size="lg"
color="purple"
:dark="darkMode"
locale="fr"
right
/>
</div>
Expand Down Expand Up @@ -252,7 +253,7 @@
'minDate', 'maxDate', 'inputSize', 'buttonNowTranslation', 'disabledWeekly'
],
optionsNotEditable: [
'customShortcuts', 'disabledDates', 'disabledHours'
'customShortcuts', 'disabledDates', 'disabledHours', 'locale'
],
intOptions: [
'minuteInterval', 'firstDayOfWeek'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@
return {
transitionDaysName: 'slidenext',
transitionLabelName: 'slidevnext',
weekDays: getWeekDays(this.locale, this.firstDayOfWeek),
selectingYearMonth: null,
isKeyboardActive: true
}
Expand All @@ -215,6 +214,9 @@
},
year () {
return `${this.month.getYear()}`
},
weekDays () {
return getWeekDays(this.locale, this.firstDayOfWeek)
}
},
methods: {
Expand Down
9 changes: 8 additions & 1 deletion src/VueCtkDateTimePicker/_subs/PickersContainer/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
>
<HeaderPicker
v-if="!noHeader"
:key="componentKey"
v-model="value"
:color="color"
:only-time="onlyTime"
Expand Down Expand Up @@ -48,6 +49,7 @@
:visible="visible"
:custom-shortcuts="customShortcuts"
:no-keyboard="noKeyboard"
:locale="locale"
@change-month="changeMonth"
@change-year-month="changeYearMonth"
@close="$emit('close')"
Expand Down Expand Up @@ -136,7 +138,8 @@
data () {
return {
month: this.getMonth(),
transitionName: 'slidevnext'
transitionName: 'slidevnext',
componentKey: 0
}
},
computed: {
Expand Down Expand Up @@ -220,6 +223,10 @@
watch: {
value (value) {
this.month = this.getMonth(value)
},
locale () {
this.month = this.getMonth()
this.componentKey += 1
}
},
methods: {
Expand Down
25 changes: 15 additions & 10 deletions src/VueCtkDateTimePicker/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,16 @@
const updateMomentLocale = (locale, firstDayOfWeek) => {
moment.locale(locale)
const firstDayNumber = Number.isInteger(firstDayOfWeek) && firstDayOfWeek === 0
? 7
: firstDayOfWeek || moment.localeData(locale).firstDayOfWeek()
moment.updateLocale(locale, {
week: {
dow: firstDayNumber
}
})
if (firstDayOfWeek) {
const firstDayNumber = Number.isInteger(firstDayOfWeek) && firstDayOfWeek === 0
? 7
: firstDayOfWeek || moment.localeData(locale).firstDayOfWeek()
moment.updateLocale(locale, {
week: {
dow: firstDayNumber
}
})
}
}
const nearestMinutes = (interval, date, format) => {
Expand Down Expand Up @@ -170,8 +172,8 @@
},
dateFormatted () {
const dateFormatted = this.range
? this.getRangeDatesFormatted()
: this.getDateFormatted()
? this.getRangeDatesFormatted(this.locale)
: this.getDateFormatted(this.locale)
this.$emit('formatted-value', dateFormatted)
return dateFormatted
},
Expand Down Expand Up @@ -212,6 +214,9 @@
open (val) {
if (this.disabled) return
this.pickerOpen = val
},
locale (value) {
updateMomentLocale(value, this.firstDayOfWeek)
}
},
mounted () {
Expand Down

0 comments on commit 666d028

Please sign in to comment.