Skip to content

Commit

Permalink
feat(date): allow passing already constructed DateInstance
Browse files Browse the repository at this point in the history
closes #17293
  • Loading branch information
KaelWD committed May 4, 2023
1 parent 04dbc94 commit 507d87e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/vuetify/src/labs/date/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface DateInstance extends DateAdapter<Date> {
}

export type DateOptions = {
adapter: { new(locale: string): DateInstance }
adapter: (new (locale: string) => DateInstance) | DateInstance
}

export const DateAdapterSymbol: InjectionKey<DateOptions> = Symbol.for('vuetify:date-adapter')
Expand Down Expand Up @@ -51,12 +51,16 @@ export function useDate (props: DateProps) {

if (!date) throw new Error('[Vuetify] Could not find injected date')

// eslint-disable-next-line new-cap
const instance = new date.adapter(locale.current.value)
const instance = typeof date.adapter === 'function'
// eslint-disable-next-line new-cap
? new date.adapter(locale.current.value)
: date.adapter

watch(locale.current, val => {
instance.locale = val
}, { immediate: true })
if (typeof date.adapter === 'function') {
watch(locale.current, val => {
instance.locale = val
})
}

return instance
}

0 comments on commit 507d87e

Please sign in to comment.