Skip to content

Commit

Permalink
feat(quasar): Add use-observer for QMenu to watch changes in target
Browse files Browse the repository at this point in the history
  • Loading branch information
pdanpdan committed Jul 9, 2019
1 parent eb26103 commit 4352bab
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ui/dev/components/form/field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
:class="{ 'rotate-180': $refs.menu1 !== void 0 && $refs.menu1.showing === true }"
/>
</template>
<q-popup-proxy fit auto-close ref="menu1">
<q-popup-proxy fit auto-close use-observer ref="menu1">
<q-tree
:nodes="props"
default-expand-all
Expand All @@ -207,7 +207,7 @@
:class="{ 'rotate-180': $refs.menu2 !== void 0 && $refs.menu2.showing === true }"
/>
</template>
<q-popup-proxy fit ref="menu2">
<q-popup-proxy fit use-observer ref="menu2">
<q-tree
:nodes="props"
default-expand-all
Expand Down
18 changes: 18 additions & 0 deletions ui/src/components/menu/QMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export default Vue.extend({

touchPosition: Boolean,

useObserver: Boolean,

maxHeight: {
type: String,
default: null
Expand Down Expand Up @@ -125,6 +127,17 @@ export default Vue.extend({
? document.activeElement
: void 0

if (this.useObserver === true) {
this.touchTargetObserver = new MutationObserver(() => {
this.updatePosition()
})
this.touchTargetObserver.observe(this.anchorEl, {
childList: true,
characterData: true,
subtree: true
})
}

this.scrollTarget = getScrollTarget(this.anchorEl)
this.scrollTarget.addEventListener('scroll', this.updatePosition, listenOpts.passive)
if (this.scrollTarget !== window) {
Expand Down Expand Up @@ -202,6 +215,11 @@ export default Vue.extend({
EscapeKey.pop(this)
this.__unregisterTree()

if (this.touchTargetObserver !== void 0) {
this.touchTargetObserver.disconnect()
this.touchTargetObserver = void 0
}

this.scrollTarget.removeEventListener('scroll', this.updatePosition, listenOpts.passive)
if (this.scrollTarget !== window) {
window.removeEventListener('scroll', this.updatePosition, listenOpts.passive)
Expand Down
6 changes: 6 additions & 0 deletions ui/src/components/menu/QMenu.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@
"extends": "transition",
"default": "fade",
"category": "behavior"
},

"use-observer": {
"type": "Boolean",
"desc": "Use observers to reposition on changes on anchor or menu height",
"category": "behavior"
}
},

Expand Down

0 comments on commit 4352bab

Please sign in to comment.