diff --git a/src/useComputedStyle/useComputedStyle.ts b/src/useComputedStyle/useComputedStyle.ts index bf452cc5..f18d6400 100644 --- a/src/useComputedStyle/useComputedStyle.ts +++ b/src/useComputedStyle/useComputedStyle.ts @@ -13,7 +13,7 @@ export function useComputedStyle(element: Element | Ref): T Object.assign(style, window.getComputedStyle(element, null)) mutationObserver.disconnect() - mutationObserver.observe(elementRef) + mutationObserver.observe(elementRef, { attributes: true }) resizeObserver.disconnect() resizeObserver.observe(elementRef) } diff --git a/src/useMutationObserver/README.md b/src/useMutationObserver/README.md index 364dec32..b2bd0a7a 100644 --- a/src/useMutationObserver/README.md +++ b/src/useMutationObserver/README.md @@ -17,6 +17,7 @@ const observer = useMutationObserver(callback) | Name | Type | |----------|-----------------------------| | callback | `MutationCallback` | +| options | `MutationObserverInit` | ## Returns `UseMutationObserverResponse` diff --git a/src/useMutationObserver/useMutationObserver.ts b/src/useMutationObserver/useMutationObserver.ts index 0cbb3955..06d6ff08 100644 --- a/src/useMutationObserver/useMutationObserver.ts +++ b/src/useMutationObserver/useMutationObserver.ts @@ -1,21 +1,21 @@ import { onMounted, onUnmounted, ref, Ref } from 'vue' export type UseMutationObserverResponse = { - observe: (element: Element | Ref) => void, + observe: (element: Element | Ref, options: MutationObserverInit) => void, disconnect: () => void, - check: (element: Element | Ref) => void, + check: (element: Element | Ref, options: MutationObserverInit) => void, } export function useMutationObserver(callback: MutationCallback): UseMutationObserverResponse { let mutationObserver: MutationObserver | null = null - const observe: UseMutationObserverResponse['observe'] = (element) => { + const observe: UseMutationObserverResponse['observe'] = (element, options) => { const elementRef = ref(element) const observer = getObserver() if (elementRef.value) { - observer.observe(elementRef.value) + observer.observe(elementRef.value, options) } } @@ -25,7 +25,7 @@ export function useMutationObserver(callback: MutationCallback): UseMutationObse observer.disconnect() } - const check: UseMutationObserverResponse['check'] = (element) => { + const check: UseMutationObserverResponse['check'] = (element, options) => { const elementRef = ref(element) if (!elementRef.value) { return @@ -33,7 +33,7 @@ export function useMutationObserver(callback: MutationCallback): UseMutationObse const observer = new MutationObserver(callback) - observer.observe(elementRef.value) + observer.observe(elementRef.value, options) setTimeout(() => observer.disconnect(), 100) }