Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resize observer disconnect in sidebar highlighter #7324

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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