Skip to content

Commit

Permalink
fix(TimeField): initial segments for TimeField based on granularity (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
epr3 authored Dec 1, 2024
1 parent 635b90e commit 8238615
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/TimeField/TimeFieldRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const isInvalid = computed(() => {
return false
})
const initialSegments = initializeTimeSegmentValues()
const initialSegments = initializeTimeSegmentValues(inferredGranularity.value)
const segmentValues = ref<SegmentValueObj>(modelValue.value ? { ...syncTimeSegmentValues({ value: convertedModelValue.value, formatter }) } : { ...initialSegments })
Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/shared/date/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function syncSegmentValues(props: SyncDateSegmentValuesProps) {
return Object.fromEntries(dateValues) as SegmentValueObj
}

export function initializeTimeSegmentValues(): SegmentValueObj {
export function initializeTimeSegmentValues(granularity: 'hour' | 'minute' | 'second'): SegmentValueObj {
return Object.fromEntries(
TIME_SEGMENT_PARTS.map((part) => {
if (part === 'dayPeriod')
Expand All @@ -48,6 +48,10 @@ export function initializeTimeSegmentValues(): SegmentValueObj {
}).filter(([key]) => {
if (key === 'literal' || key === null)
return false
if (granularity === 'minute' && key === 'second')
return false
if (granularity === 'hour' && (key === 'second' || key === 'minute'))
return false
else return true
}),
)
Expand All @@ -62,6 +66,10 @@ export function initializeSegmentValues(granularity: Granularity): SegmentValueO
}).filter(([key]) => {
if (key === 'literal' || key === null)
return false
if (granularity === 'minute' && key === 'second')
return false
if (granularity === 'hour' && (key === 'second' || key === 'minute'))
return false
if (granularity === 'day')
return !calendarDateTimeGranularities.includes(key) && key !== 'dayPeriod'
else return true
Expand Down

0 comments on commit 8238615

Please sign in to comment.