Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(TimeField): initial TimeField segments based on granularity #1466

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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