Skip to content

Commit 3bfe776

Browse files
committed
fix: Correct type for updateTime function in time-picker slot, update documentation accordingly (fixes #1189)
1 parent eaea291 commit 3bfe776

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

docs/migration/from-v11.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ outline: [2, 4]
1717
- `import` statement is changed to named instead of default
1818
- Removed `onScroll` and `dpWrapMenuRef` exposed methods
1919
- In `action-row` slot, param `internalModelValue` is renamed to `modelValue`
20+
- In `time-picker` slot, exposed function `updateTime` parameters are changed
2021
- `noTz` property from `preset-dates` config array is removed
2122
- Removed props:
2223
- `position`
@@ -264,6 +265,24 @@ Use camel case for naming multi-word props. e.g. `enable-time-picker` -> `enable
264265
</template>
265266
```
266267

268+
### `time-picker` slot `updateTime`
269+
270+
Function parameters for `updateTime` in [`time-picker`](/slots/sections/#time-picker) slot are changed
271+
and now accept a full time object instead of determining the value to update via `boolean` flags.
272+
273+
To update time, pass back the exposed time object and override the properties you want to update.
274+
275+
```js
276+
<template>
277+
<VueDatePicker>
278+
<template #time-picker="{ time, updateTime }">
279+
<button @click="updateTime(0, false)">Reset minutes</button> // [!code --]
280+
<button @click="updateTime({ ...time, minutes: 0 })">Reset minutes</button> // [!code ++]
281+
</template>
282+
</VueDatePicker>
283+
</template>
284+
```
285+
267286

268287
### `day-class`
269288

docs/slots/sections/index.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ const formatDate = (date) => {
191191
<select
192192
class="w-full"
193193
:value="time.hours"
194-
@change="updateTime(+$event.target.value)"
194+
@change="updateTime({...time, hours: +$event.target.value,})"
195195
>
196196
<option
197197
v-for="h in hoursArray"
@@ -201,7 +201,7 @@ const formatDate = (date) => {
201201
<select
202202
class="w-full"
203203
:value="time.minutes"
204-
@change="updateTime(+$event.target.value, false)"
204+
@change="updateTime({...time, minutes: $event.target.value})"
205205
>
206206
<option
207207
v-for="m in minutesArray"
@@ -221,7 +221,11 @@ const formatDate = (date) => {
221221
minutes: number | number[];
222222
seconds: number | number[];
223223
};
224-
updateTime: (value: number | number[], isHours: boolean, isSeconds: boolean) => void;
224+
updateTime: (time: {
225+
hours: number | number[];
226+
minutes: number | number[];
227+
seconds?: number | number[];
228+
}) => void;
225229
}
226230
```
227231

@@ -232,7 +236,7 @@ const formatDate = (date) => {
232236

233237
:::tip
234238
Keep in mind that when you are using the range picker, both values for the time must be emitted.
235-
For example if you want to update the second date hours, you will call a function something like this `updateTime([firstValueSaved, newSecondValue])`
239+
For example, if you want to update the second date hours, you will call a function something like this `updateTime(...time, hours: [12, time.hours[1]])`
236240
:::
237241

238242

@@ -245,7 +249,7 @@ For example if you want to update the second date hours, you will call a functio
245249
<select
246250
style="width: 100%"
247251
:value="time.hours"
248-
@change="updateTime(+$event.target.value)"
252+
@change="updateTime({ ...time, hours: +$event.target.value })"
249253
>
250254
<option
251255
v-for="h in hoursArray"
@@ -255,7 +259,7 @@ For example if you want to update the second date hours, you will call a functio
255259
<select
256260
style="width: 100%"
257261
:value="time.minutes"
258-
@change="updateTime(+$event.target.value, false)"
262+
@change="updateTime({...time, minutes: +$event.target.value })"
259263
>
260264
<option
261265
v-for="m in minutesArray"

src/VueDatePicker/types/slots.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ComputedRef } from 'vue';
22
import type { InternalModelValue } from '@/types/generic.ts';
3-
import type { Marker } from '@/types/picker.ts';
3+
import type { Marker, TimeInternalModel } from '@/types/picker.ts';
44

55
export interface InternalTime {
66
hours: number | number[];
@@ -78,7 +78,7 @@ export interface ActionRowSlotProps {
7878

7979
export interface TimePickerSlotProps {
8080
time: InternalTime;
81-
updateTime: (value: number | number[], isHours?: boolean, isSeconds?: boolean) => void;
81+
updateTime: (time: TimeInternalModel) => void;
8282
}
8383

8484
export interface RootSlots {

0 commit comments

Comments
 (0)