Skip to content

Commit 4b2509b

Browse files
committed
Merge branch 'hotfix/v2.10.3'
2 parents 34508c4 + dfd67d8 commit 4b2509b

12 files changed

+147
-49
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ This project is licensed under the MIT License
129129

130130
## Change log
131131

132+
### 2.10.3 (2022-01-06)
133+
* Fixed [popover position in rtl pages](https://github.com/talkhabi/vue-persian-datetime-picker/issues/204)
134+
* Fixed [keep the selected day in simple mode](https://github.com/talkhabi/vue-persian-datetime-picker/issues/207)
135+
132136
### 2.10.2 (2021-12-24)
133137
* Fixed [popover mode when using custom input](https://github.com/talkhabi/vue-persian-datetime-picker/issues/200)
134138
* Fixed [change jump-minute by muse wheel](https://github.com/talkhabi/vue-persian-datetime-picker/issues/198)

dist/vue-persian-datetime-picker.common.js

+38-11
Large diffs are not rendered by default.

dist/vue-persian-datetime-picker.umd.js

+38-11
Large diffs are not rendered by default.

dist/vue-persian-datetime-picker.umd.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/config/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,14 @@ Enable or disable multiple mode
324324
## popover
325325

326326
Enable or disable popover mode
327-
- Type: `Boolean` | `String`
327+
- Type: `Boolean` | `String` | `Object`
328328
- Default: `false`
329329
- Accepted:
330330
* `true` | `false`
331-
* `top-left` | `top-right`
332-
* `bottom-right` | `bottom-left`
333-
* `left-top` | `left-bottom`
334-
* `right-top` | `right-bottom`
331+
* `top` | `bottom` | `right` | `left`
332+
* `top-left` | `top-right` | `bottom-right` | `bottom-left`
333+
* `{ offsetX: Number, offsetY: Number }`
334+
* `{ placement: String, offsetX: Number, offsetY: Number }`
335335

336336

337337
## useRouter

docs/guide/popover.md

+22-8
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,30 @@
1515
<date-picker auto-submit popover="bottom-left" />
1616
</ClientOnly>
1717

18+
```vue
19+
<date-picker
20+
auto-submit
21+
:popover="{
22+
placement: 'right',
23+
offsetX: 10,
24+
offsetY: 10
25+
}"
26+
/>
27+
```
28+
<ClientOnly>
29+
<date-picker auto-submit :popover="{ placement: 'right', offsetX: 10, offsetY: 10 }" />
30+
</ClientOnly>
31+
1832

1933
accepted:
2034

2135
`true` | `false`
22-
23-
`top-left` | `top-right`
24-
25-
`bottom-right` | `bottom-left`
26-
27-
`top` | `bottom`
28-
29-
`right` | `left`
36+
37+
`top` | `bottom` | `right` | `left`
38+
39+
`top-left` | `top-right` | `bottom-right` | `bottom-left`
40+
41+
`{ offsetX: Number, offsetY: Number }`
42+
43+
`{ placement: String, offsetX: Number, offsetY: Number }`
3044

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-persian-datetime-picker",
33
"description": "A vue plugin to select jalali date and time",
4-
"version": "2.10.2",
4+
"version": "2.10.3",
55
"private": false,
66
"author": "Mohammad Talkhabi",
77
"license": "MIT",

src/VuePersianDatetimePicker.vue

+26-7
Original file line numberDiff line numberDiff line change
@@ -841,13 +841,15 @@ export default {
841841
* true | false
842842
* top | bottom | right | left
843843
* top-left | top-right | bottom-right | bottom-left
844+
* { offsetX: -10, offsetY: 10 }
845+
* { placement: 'right', offsetX: 10, offsetY: 10 }
844846
* @default false
845847
* @example <date-picker popover />
846848
* @example <date-picker popover="right" />
847849
* @example <date-picker popover="top-left" />
848850
* @version 2.6.0
849851
*/
850-
popover: { type: [Boolean, String], default: false },
852+
popover: { type: [Boolean, String, Object], default: false },
851853
852854
/**
853855
* If you want to change route address in open/close action,
@@ -1400,19 +1402,30 @@ export default {
14001402
selectYear(year) {
14011403
if (year.disabled) return
14021404
this.date = this.date.clone().xYear(year.xYear())
1403-
if (['year', 'year-month'].indexOf(this.type) !== -1)
1404-
this.selectedDates = [this.date.clone()]
1405+
this.keepCurrentSelectedDay()
1406+
this.resetSelectedDates(this.date)
14051407
this.$emit('year-change', year)
14061408
this.nextStep('year')
14071409
},
14081410
selectMonth(month) {
14091411
if (month.disabled) return
14101412
this.date = this.date.clone().xMonth(month.xMonth())
1411-
if (['month', 'year-month'].indexOf(this.type) !== -1)
1412-
this.selectedDates = [this.date.clone()]
1413+
this.keepCurrentSelectedDay()
1414+
this.resetSelectedDates(this.date)
14131415
this.$emit('month-change', month)
14141416
this.nextStep('month')
14151417
},
1418+
keepCurrentSelectedDay() {
1419+
if (!this.simple || this.multiple || this.range) return
1420+
let currentDay = this.selectedDate.xDate()
1421+
this.date.xDate(Math.min(currentDay, this.date.xDaysInMonth()))
1422+
this.selectedDates = [this.date.clone()]
1423+
this.autoSubmit && this.submit(false)
1424+
},
1425+
resetSelectedDates(date) {
1426+
if (['month', 'year-month'].indexOf(this.type) !== -1)
1427+
this.selectedDates = [date.clone()]
1428+
},
14161429
submit(close = true) {
14171430
let steps = this.steps.length - 1
14181431
let selected = this.selectedDates
@@ -1789,9 +1802,15 @@ export default {
17891802
},
17901803
setPlacement() {
17911804
if (!this.isPopover || !this.visible) return
1792-
const positionOptions = {
1793-
placement: this.popover
1805+
let positionOptions = {
1806+
placement: '',
1807+
offsetX: 0,
1808+
offsetY: 0
17941809
}
1810+
if (typeof this.popover === 'object' && this.popover)
1811+
positionOptions.placement = this.popover
1812+
else if (typeof this.popover === 'string')
1813+
positionOptions.placement = this.popover
17951814
popover.setPickerPosition(
17961815
this.$refs.picker,
17971816
this.$refs.container,

src/assets/scss/style.scss

+2
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@
582582
width: 100px;
583583
height: 0;
584584
z-index: 500;
585+
right: unset;
586+
bottom: unset;
585587
.#{$prefix}container {
586588
position: absolute;
587589
transform: none;

src/modules/core.js

+3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ const Core = function(defaultLocaleName, defaultOptions) {
129129
date.xAdd = function(amount, key) {
130130
return this.add(amount, methods[key])
131131
}
132+
date.xDaysInMonth = function() {
133+
return xDaysInMonth(this.xYear(), this.xMonth())
134+
}
132135
date.clone = function() {
133136
return Instance.moment(this.toDate())
134137
}

src/modules/popover-util.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ const popover = {
2626
setPickerPosition(pickerWrapperEl, containerEl, inputWrapperEl, options) {
2727
if (!inputWrapperEl || !pickerWrapperEl) return
2828

29+
let { placement = '', offsetX = 0, offsetY = 0 } = options
2930
let dataPlacement = ''
30-
const placement = options.placement
3131
let isOnTop = /top/.test(placement)
3232
let isOnLeft = /left/.test(placement)
3333
let isOnRight = /right/.test(placement)
@@ -52,13 +52,15 @@ const popover = {
5252
dataPlacement += isOnLeft ? '-left' : '-right'
5353

5454
if (isOnTop) {
55-
pickerWrapperEl.style.top = inputWrapperRect.top - distanceY + 'px'
55+
pickerWrapperEl.style.top =
56+
inputWrapperRect.top - distanceY - offsetY + 'px'
5657
} else {
57-
pickerWrapperEl.style.top = top + distanceY + 'px'
58+
pickerWrapperEl.style.top = top + distanceY + offsetY + 'px'
5859
}
5960

61+
offsetX *= isOnRight ? 1 : -1
6062
pickerWrapperEl.setAttribute('data-placement', dataPlacement)
61-
pickerWrapperEl.style.left = inputWrapperRect.left + 'px'
63+
pickerWrapperEl.style.left = inputWrapperRect.left + offsetX + 'px'
6264
}
6365
}
6466

0 commit comments

Comments
 (0)