Skip to content

Commit

Permalink
fix(VMenu): improve position when using offset, width and attach props (
Browse files Browse the repository at this point in the history
#6193)

* fix(VMenu): apply correct left position with attach

using attach/max-width/left/offset-x causes menu to not be placed correctly

* fix(VMenu): update totalWidth calculation

fixes #5498

* test(menuable): fix unit tests
  • Loading branch information
johnleider committed Jan 18, 2019
1 parent c38d1d9 commit bfad3d8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/vuetify/src/components/VMenu/VMenu.js
Expand Up @@ -68,12 +68,12 @@ export default Vue.extend({
disabled: Boolean,
fullWidth: Boolean,
maxHeight: { default: 'auto' },
offsetX: Boolean,
offsetY: Boolean,
openOnClick: {
type: Boolean,
default: true
},
offsetX: Boolean,
offsetY: Boolean,
openOnHover: Boolean,
origin: {
type: String,
Expand Down
11 changes: 8 additions & 3 deletions packages/vuetify/src/mixins/menuable.js
Expand Up @@ -110,9 +110,14 @@ export default Vue.extend({
const activatorLeft = (this.isAttached ? a.offsetLeft : a.left) || 0
const minWidth = Math.max(a.width, c.width)
let left = 0

left += this.left ? activatorLeft - (minWidth - a.width) : activatorLeft
if (this.offsetX) left += this.left ? -a.width : a.width
if (this.offsetX) {
const maxWidth = isNaN(this.maxWidth)
? a.width
: Math.min(a.width, this.maxWidth)

left += this.left ? -maxWidth : a.width
}
if (this.nudgeLeft) left -= parseInt(this.nudgeLeft)
if (this.nudgeRight) left += parseInt(this.nudgeRight)

Expand Down Expand Up @@ -191,7 +196,7 @@ export default Vue.extend({
this.dimensions.content.width,
parsedMaxWidth
)
const totalWidth = left + maxWidth
const totalWidth = left + this.dimensions.activator.width
const availableWidth = totalWidth - innerWidth

if ((!this.left || this.right) && availableWidth > 0) {
Expand Down
29 changes: 29 additions & 0 deletions packages/vuetify/test/unit/mixins/menuable.spec.js
Expand Up @@ -31,4 +31,33 @@ test('menuable.js', ({ mount }) => {
await wrapper.vm.$nextTick()
expect(sneakPeek).toHaveBeenCalled()
})

it('should apply maxWidth in left calculations when offset', async () => {
const wrapper = mount({
mixins: [Menuable],
props: {
offsetY: Boolean,
offsetX: Boolean
},
render: h => h('div')
}, {
propsData: {
attach: true,
left: true,
offsetX: true,
maxWidth: 200
}
})

wrapper.setData({
dimensions: {
activator: { width: 300 },
content: { width: 138 }
}
})

await wrapper.vm.$nextTick()

expect(wrapper.vm.computedLeft).toBe(-200)
})
})

0 comments on commit bfad3d8

Please sign in to comment.