Skip to content

Commit

Permalink
fix(MdSelect): adjust position when body has margin (#1551)
Browse files Browse the repository at this point in the history
* adjust popper with body position

* fix ci build error
  • Loading branch information
AlbertLucianto authored and marcosmoura committed Feb 28, 2018
1 parent ef0cd2f commit c820b72
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
28 changes: 14 additions & 14 deletions docs/app/pages/Components/Menu/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,20 @@
]
},
events: {
headings: ['Name', 'Description', 'Value'],
props: [
{
name: 'md-opened',
description: 'Triggered when menu opens',
value: 'null'
},
{
name: 'md-closed',
description: 'Triggered when menu closes',
value: 'null'
}
]
}
headings: ['Name', 'Description', 'Value'],
props: [
{
name: 'md-opened',
description: 'Triggered when menu opens',
value: 'null'
},
{
name: 'md-closed',
description: 'Triggered when menu closes',
value: 'null'
}
]
}
})
}
</script>
18 changes: 16 additions & 2 deletions src/components/MdMenu/MdMenuContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,14 @@
this.MdMenu.active = false
},
getOffsets () {
const relativePosition = this.getBodyPosition()
const offsetX = this.MdMenu.offsetX || 0
const offsetY = this.MdMenu.offsetY || 0
return {
offsetX: this.MdMenu.offsetX || 0,
offsetY: this.MdMenu.offsetY || 0
offsetX: offsetX - relativePosition.x,
offsetY: offsetY - relativePosition.y
}
},
hasCustomOffsets () {
Expand Down Expand Up @@ -221,6 +226,15 @@
max-width: ${this.MdMenu.instance.$el.offsetWidth}px
`
}
},
getBodyPosition() {
const body = document.body
const { top, left } = body.getBoundingClientRect()
const scrollLeft = window.pageXOffset !== undefined ? window.pageXOffset : body.scrollLeft
const scrollTop = window.pageYOffset !== undefined ? window.pageYOffset : body.scrollTop
return { x: left + scrollLeft, y: top + scrollTop }
}
},
mounted () {
Expand Down

0 comments on commit c820b72

Please sign in to comment.