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

[MdSelect] Adjust position when body has margin #1551

Merged
merged 2 commits into from
Feb 28, 2018
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
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