Skip to content

Commit

Permalink
feat: add useAffixTargetProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
chizukicn committed Oct 20, 2023
1 parent f190456 commit ce212a9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/core/src/affix/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const useAffix = defineHookComponent({
setup(props, { emit }) {
const wrapperRef = ref<HTMLElement | null>(null);

const parentRef = inject(AFFIX_TARGET_KEY, undefined);
const parentRef = inject(AFFIX_TARGET_KEY, null);

const targetRef = useElement(props.target, parentRef);

Expand Down Expand Up @@ -164,3 +164,9 @@ export const useAffix = defineHookComponent({
export function provideAffixTarget(target: MaybeRefOrGetter<Element | null | undefined>) {
provide(AFFIX_TARGET_KEY, target);
}

export function useAffixTargetProvider<E extends Element = Element>() {
const targetRef = ref<E | null>(null);
provideAffixTarget(targetRef);
return targetRef;
}

0 comments on commit ce212a9

Please sign in to comment.