@@ -70,7 +70,7 @@ const props = withDefaults(defineProps<Props>(), {
7070})
7171
7272const emit = defineEmits <{
73- ' update:model-value ' : [value : number | string ]
73+ ' update:modelValue ' : [value : number | string ]
7474}>()
7575const internalSelectedOption = ref <SelectOption | null >(null )
7676const customDays = ref <SelectOption | null >(null )
@@ -117,7 +117,6 @@ const selectedOption = computed<SelectOption | null>({
117117 id: predefined .value ,
118118 label: predefined .label ,
119119 }
120- internalSelectedOption .value = option
121120 return option
122121 }
123122
@@ -127,7 +126,6 @@ const selectedOption = computed<SelectOption | null>({
127126 id: ' custom' ,
128127 label: t (' calendar' , ' Custom' ),
129128 }
130- internalSelectedOption .value = customOption
131129 return customOption
132130 }
133131
@@ -177,12 +175,24 @@ const minutesOptions = computed<SelectOption[]>(() => {
177175
178176// Watchers
179177watch (() => props .modelValue , (newValue : number | string ) => {
180- // Only update custom fields if custom is actually selected and we have a value
181- if (isCustomSelected .value && newValue ) {
182- const minutes = typeof newValue === ' string' ? iso8601ToMinutes (newValue ) : newValue
183- if (minutes > 0 ) {
184- updateCustomFields (minutes )
178+ const minutes = typeof newValue === ' string' ? iso8601ToMinutes (newValue ) : newValue || 0
179+
180+ // Calculate which option should be selected
181+ const predefined = props .predefinedOptions .find ((opt : DurationOption ) => opt .value === minutes )
182+ if (predefined ) {
183+ internalSelectedOption .value = {
184+ id: predefined .value ,
185+ label: predefined .label ,
186+ }
187+ } else if (props .showCustom && minutes > 0 ) {
188+ internalSelectedOption .value = {
189+ id: ' custom' ,
190+ label: t (' calendar' , ' Custom' ),
185191 }
192+ // Also update custom fields
193+ updateCustomFields (minutes )
194+ } else {
195+ internalSelectedOption .value = null
186196 }
187197}, { immediate: true })
188198
@@ -220,9 +230,9 @@ function onCustomMinutesChange(option: SelectOption): void {
220230
221231function emitDuration(minutes : number ): void {
222232 if (props .format === ' iso8601' ) {
223- emit (' update:model-value ' , minutesToISO8601 (minutes ))
233+ emit (' update:modelValue ' , minutesToISO8601 (minutes ))
224234 } else {
225- emit (' update:model-value ' , minutes )
235+ emit (' update:modelValue ' , minutes )
226236 }
227237}
228238
@@ -316,7 +326,7 @@ function minutesToISO8601(totalMinutes: number): string {
316326 </script >
317327
318328<template >
319- <div class =" property- duration" >
329+ <div class =" duration-selector " >
320330 <NcSelect
321331 :value =" selectedOption"
322332 :options =" allOptions"
@@ -330,15 +340,15 @@ function minutesToISO8601(totalMinutes: number): string {
330340 </NcSelect >
331341
332342 <!-- Custom duration controls (shown when "Custom" is selected) -->
333- <div v-if =" isCustomSelected" class =" property-duration__custom -controls" >
343+ <div v-if =" isCustomSelected" class =" duration-selector__custom -controls" >
334344 <NcSelect
335345 v-if =" showDays"
336346 :value =" customDays"
337347 :options =" daysOptions"
338348 :label-outside =" true"
339349 :placeholder =" t('calendar', 'Days')"
340350 :clearable =" false"
341- class =" property-duration__custom -select"
351+ class =" duration-selector__custom -select"
342352 @input =" onCustomDaysChange" >
343353 <template #selected-option =" option " >
344354 {{ option.label }}
@@ -352,7 +362,7 @@ function minutesToISO8601(totalMinutes: number): string {
352362 :label-outside =" true"
353363 :placeholder =" t('calendar', 'Hours')"
354364 :clearable =" false"
355- class =" property-duration__custom -select"
365+ class =" duration-selector__custom -select"
356366 @input =" onCustomHoursChange" >
357367 <template #selected-option =" option " >
358368 {{ option.label }}
@@ -366,7 +376,7 @@ function minutesToISO8601(totalMinutes: number): string {
366376 :label-outside =" true"
367377 :placeholder =" t('calendar', 'Minutes')"
368378 :clearable =" false"
369- class =" property-duration__custom -select"
379+ class =" duration-selector__custom -select"
370380 @input =" onCustomMinutesChange" >
371381 <template #selected-option =" option " >
372382 {{ option.label }}
@@ -377,7 +387,7 @@ function minutesToISO8601(totalMinutes: number): string {
377387</template >
378388
379389<style lang="scss" scoped>
380- .property- duration {
390+ .duration-selector {
381391 display : flex ;
382392 flex-direction : column ;
383393 gap : calc (var (--default-grid-baseline ) * 2 );
@@ -386,7 +396,7 @@ function minutesToISO8601(totalMinutes: number): string {
386396 overflow : hidden ;
387397}
388398
389- .property-duration__custom -controls {
399+ .duration-selector__custom -controls {
390400 display : flex ;
391401 gap : calc (var (--default-grid-baseline ) * 2 );
392402 flex-wrap : nowrap ;
@@ -395,9 +405,11 @@ function minutesToISO8601(totalMinutes: number): string {
395405 overflow : hidden ;
396406}
397407
398- .property-duration__custom -select {
408+ .duration-selector__custom -select {
399409 flex : 1 1 0 ;
400- min-width : 0 ;
410+ min-width : 0 !important ;
401411 max-width : 100% ;
412+ margin : 0 ;
413+ width : 100% ;
402414}
403415 </style >
0 commit comments