Skip to content

Commit 8a7e017

Browse files
committed
fix: resolve useZIndex inject warning
1 parent b6e69df commit 8a7e017

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

packages/anu-vue/src/composables/useZIndex.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import { isNumber } from '@antfu/utils'
2-
import { computed, inject, ref } from 'vue'
2+
import { type App, computed, inject, ref } from 'vue'
33

44
import { ANU_Z_INDEX } from '@/symbols'
55

66
const zIndexCounter = ref(0)
77

8-
export const useZIndex = createGlobalState((defaultBaseZIndex?: number) => {
9-
if (!defaultBaseZIndex)
8+
export const useZIndex = createGlobalState((defaultBaseZIndex?: number, app?: App) => {
9+
if (!defaultBaseZIndex || !app)
1010
throw new Error('[Anu] `useZIndex` composable must be initialized before usage.')
1111

12-
const injectedZIndex = inject(ANU_Z_INDEX)
12+
let injectedZIndex: Ref<number | undefined> | undefined
13+
14+
app.runWithContext(() => {
15+
injectedZIndex = inject(ANU_Z_INDEX, undefined)
16+
})
1317

1418
const baseZIndex = computed(() => {
1519
const injectedZIndexValue = injectedZIndex?.value

packages/anu-vue/src/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,6 @@ export const plugin = {
114114
})
115115

116116
// Initialize useZIndex composable
117-
useZIndex(config.baseZIndex)
117+
useZIndex(config.baseZIndex, app)
118118
},
119119
}

packages/anu-vue/src/symbols.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import type { PluginOptions } from '@/plugin'
33

44
export const ANU_CONFIG = Symbol('ANU_CONFIG') as InjectionKey<PluginOptions>
55
export const ANU_PROPS_DEFAULTS = Symbol('ANU_PROPS_DEFAULTS') as InjectionKey<MaybeRef<PluginOptions['propsDefaults']>>
6-
export const ANU_Z_INDEX: InjectionKey<Ref<number | undefined>> = Symbol('zIndexContextKey')
6+
export const ANU_Z_INDEX = Symbol('ANU_Z_INDEX') as InjectionKey<Ref<number | undefined>>

0 commit comments

Comments
 (0)