Skip to content

Commit

Permalink
Fix resize observer disconnect in sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed Jul 25, 2022
1 parent 9437135 commit ecb85e2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
1 change: 1 addition & 0 deletions changelog/unreleased/bugfix-repair-navigtion-highlighter
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ We've refactored the navigation highlighter to fix several small glitches.

https://github.com/owncloud/web/pull/7210
https://github.com/owncloud/web/pull/7270
https://github.com/owncloud/web/pull/7324
47 changes: 25 additions & 22 deletions packages/web-runtime/src/components/SidebarNav/SidebarNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,6 @@ export default {
required: true
}
},
mounted() {
const navItem = document.getElementsByClassName('oc-sidebar-nav-item-link')[0]
const highlighter = document.getElementById('nav-highlighter')
if (!highlighter || !navItem) {
return
}
const resizeObserver = new ResizeObserver((data) => {
const width = data[0].borderBoxSize[0].inlineSize
highlighter.style.setProperty('transition-duration', `0.05s`)
if (width === 0) return
highlighter.style.setProperty('width', `${width}px`)
}).observe(navItem)
if (navItem.clientWidth === 0) return
highlighter.style.setProperty('width', `${navItem.clientWidth}px`)
highlighter.style.setProperty('height', `${navItem.clientHeight}px`)
this.$on('beforeDestroy', () => {
resizeObserver.disconnect()
})
},
computed: {
...mapState(['navigation']),
Expand All @@ -95,6 +73,31 @@ export default {
return this.navItems.some((i) => i.active === true)
}
},
mounted() {
const navItem = document.getElementsByClassName('oc-sidebar-nav-item-link')[0]
const highlighter = document.getElementById('nav-highlighter')
if (!highlighter || !navItem) {
return
}
const resizeObserver = new ResizeObserver((data) => {
const width = data[0].borderBoxSize[0].inlineSize
highlighter.style.setProperty('transition-duration', `0.05s`)
if (width) {
highlighter.style.setProperty('width', `${width}px`)
}
})
resizeObserver.observe(navItem)
if (navItem.clientWidth) {
highlighter.style.setProperty('width', `${navItem.clientWidth}px`)
highlighter.style.setProperty('height', `${navItem.clientHeight}px`)
}
this.$on('beforeDestroy', () => {
resizeObserver.disconnect()
})
},
methods: {
...mapActions(['openNavigation', 'closeNavigation']),
Expand Down

0 comments on commit ecb85e2

Please sign in to comment.