From ce212a9737154068222a6101327eed7a31b3695b Mon Sep 17 00:00:00 2001 From: chizukicn Date: Fri, 20 Oct 2023 17:19:05 +0800 Subject: [PATCH] feat: add useAffixTargetProvider --- packages/core/src/affix/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/core/src/affix/index.ts b/packages/core/src/affix/index.ts index edaf793..ca27dd6 100644 --- a/packages/core/src/affix/index.ts +++ b/packages/core/src/affix/index.ts @@ -63,7 +63,7 @@ export const useAffix = defineHookComponent({ setup(props, { emit }) { const wrapperRef = ref(null); - const parentRef = inject(AFFIX_TARGET_KEY, undefined); + const parentRef = inject(AFFIX_TARGET_KEY, null); const targetRef = useElement(props.target, parentRef); @@ -164,3 +164,9 @@ export const useAffix = defineHookComponent({ export function provideAffixTarget(target: MaybeRefOrGetter) { provide(AFFIX_TARGET_KEY, target); } + +export function useAffixTargetProvider() { + const targetRef = ref(null); + provideAffixTarget(targetRef); + return targetRef; +}