Skip to content

Commit

Permalink
fix(NcReferenceWidget): useElementSize
Browse files Browse the repository at this point in the history
It does exactly what we want.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed May 13, 2024
1 parent a780d1d commit bc0a150
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions src/components/NcRichText/NcReferenceWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</div>
</template>
<script>
import { useIntersectionObserver, useResizeObserver } from '@vueuse/core'
import { useElementSize, useIntersectionObserver } from '@vueuse/core'
import { nextTick, ref } from 'vue'
import { RouterLink } from 'vue-router'
Expand Down Expand Up @@ -62,33 +62,17 @@ export default {
},
setup() {
const width = ref(0)
const isVisible = ref(false)
// This is the widget root node
const widgetRoot = ref()
const { width } = useElementSize(widgetRoot)
useIntersectionObserver(widgetRoot, () => {
nextTick(() => {
isVisible.value = widgetRoot.value?.isIntersecting ?? false
})
})
/**
* Measure the width of the widgetRoot after a resize
*/
useResizeObserver(widgetRoot, () => {
/**
* Wait till the next tick to allow the resize to finish first
* and avoid triggering content updates during the resize.
*
* Without the nextTick we were seeing crashing browsers
* in cypress tests.
*/
nextTick(() => {
width.value = widgetRoot.value?.contentRect.width ?? 0
})
})
return {
width,
isVisible,
Expand Down

0 comments on commit bc0a150

Please sign in to comment.