Skip to content

Commit 904f949

Browse files
committed
fix(theme): async transition should return a Promise
fixes #22900
1 parent 4fc3c8e commit 904f949

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

  • packages/vuetify/src/composables

packages/vuetify/src/composables/theme.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ interface OnColors {
108108
}
109109

110110
export interface ThemeInstance {
111-
change: (themeName: string, transition?: boolean | ThemeTransitionOptions) => void
112-
cycle: (themeArray?: string[], transition?: boolean | ThemeTransitionOptions) => void
113-
toggle: (themeArray?: [string, string], transition?: boolean | ThemeTransitionOptions) => void
111+
change: (themeName: string, transition?: boolean | ThemeTransitionOptions) => Promise<void>
112+
cycle: (themeArray?: string[], transition?: boolean | ThemeTransitionOptions) => Promise<void>
113+
toggle: (themeArray?: [string, string], transition?: boolean | ThemeTransitionOptions) => Promise<void>
114114
setTransitionOrigin: (e: PointerEvent | Element | null) => void
115115

116116
readonly isDisabled: boolean
@@ -554,10 +554,10 @@ export function createTheme (options?: ThemeOptions): ThemeInstance & { install:
554554
}
555555
}
556556

557-
function withPageTransition (callback: () => void, options: ThemeTransitionOptions) {
557+
function withPageTransition (callback: () => void, options: ThemeTransitionOptions): Promise<void> {
558558
if (!IN_BROWSER || !document.startViewTransition || PREFERS_REDUCED_MOTION()) {
559559
callback()
560-
return
560+
return Promise.resolve()
561561
}
562562

563563
const origin = options.origin ?? '50% 0%'
@@ -578,33 +578,36 @@ export function createTheme (options?: ThemeOptions): ThemeInstance & { install:
578578
_transitionOrigin = null
579579
style.remove()
580580
})
581+
582+
return transition.updateCallbackDone
581583
}
582584

583-
function change (themeName: string, transition?: boolean | ThemeTransitionOptions) {
585+
function change (themeName: string, transition?: boolean | ThemeTransitionOptions): Promise<void> {
584586
if (themeName !== 'system' && !themeNames.value.includes(themeName)) {
585587
consoleWarn(`Theme "${themeName}" not found on the Vuetify theme instance`)
586-
return
588+
return Promise.resolve()
587589
}
588590

589591
const apply = () => { name.value = themeName }
590592
const transitionOptions = resolveTransitionOptions(transition)
591593

592594
if (transitionOptions) {
593-
withPageTransition(apply, transitionOptions)
594-
} else {
595-
apply()
595+
return withPageTransition(apply, transitionOptions)
596596
}
597+
598+
apply()
599+
return Promise.resolve()
597600
}
598601

599-
function cycle (themeArray: string[] = themeNames.value, transition?: boolean | ThemeTransitionOptions) {
602+
function cycle (themeArray: string[] = themeNames.value, transition?: boolean | ThemeTransitionOptions): Promise<void> {
600603
const currentIndex = themeArray.indexOf(name.value)
601604
const nextIndex = currentIndex === -1 ? 0 : (currentIndex + 1) % themeArray.length
602605

603-
change(themeArray[nextIndex], transition)
606+
return change(themeArray[nextIndex], transition)
604607
}
605608

606-
function toggle (themeArray: [string, string] = ['light', 'dark'], transition?: boolean | ThemeTransitionOptions) {
607-
cycle(themeArray, transition)
609+
function toggle (themeArray: [string, string] = ['light', 'dark'], transition?: boolean | ThemeTransitionOptions): Promise<void> {
610+
return cycle(themeArray, transition)
608611
}
609612

610613
const globalName = new Proxy(name, {

0 commit comments

Comments
 (0)