mirror of
https://github.com/youzan/vant.git
synced 2025-10-21 19:24:16 +00:00
fix(DropdownMenu): incorrect menu position when scroll (#5313)
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
import { createNamespace } from '../utils';
|
import { createNamespace } from '../utils';
|
||||||
|
import { PortalMixin } from '../mixins/portal';
|
||||||
|
import { ChildrenMixin } from '../mixins/relation';
|
||||||
|
import { on, off } from '../utils/dom/event';
|
||||||
import Cell from '../cell';
|
import Cell from '../cell';
|
||||||
import Icon from '../icon';
|
import Icon from '../icon';
|
||||||
import Popup from '../popup';
|
import Popup from '../popup';
|
||||||
import { PortalMixin } from '../mixins/portal';
|
|
||||||
import { ChildrenMixin } from '../mixins/relation';
|
|
||||||
|
|
||||||
const [createComponent, bem] = createNamespace('dropdown-item');
|
const [createComponent, bem] = createNamespace('dropdown-item');
|
||||||
|
|
||||||
@@ -40,6 +41,12 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
showPopup(val) {
|
||||||
|
this.bindScroll(val);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
beforeCreate() {
|
beforeCreate() {
|
||||||
const createEmitter = eventName => () => this.$emit(eventName);
|
const createEmitter = eventName => () => this.$emit(eventName);
|
||||||
|
|
||||||
@@ -63,6 +70,16 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
bindScroll(bind) {
|
||||||
|
const { scroller } = this.parent;
|
||||||
|
const action = bind ? on : off;
|
||||||
|
action(scroller, 'scroll', this.onScroll, true);
|
||||||
|
},
|
||||||
|
|
||||||
|
onScroll() {
|
||||||
|
this.parent.updateOffset();
|
||||||
|
},
|
||||||
|
|
||||||
onClickWrapper(event) {
|
onClickWrapper(event) {
|
||||||
// prevent being identified as clicking outside and closed when use get-contaienr
|
// prevent being identified as clicking outside and closed when use get-contaienr
|
||||||
if (this.getContainer) {
|
if (this.getContainer) {
|
||||||
|
@@ -2,6 +2,7 @@ import { createNamespace } from '../utils';
|
|||||||
import { BORDER_TOP_BOTTOM } from '../utils/constant';
|
import { BORDER_TOP_BOTTOM } from '../utils/constant';
|
||||||
import { ParentMixin } from '../mixins/relation';
|
import { ParentMixin } from '../mixins/relation';
|
||||||
import { ClickOutsideMixin } from '../mixins/click-outside';
|
import { ClickOutsideMixin } from '../mixins/click-outside';
|
||||||
|
import { getScrollEventTarget } from '../utils/dom/scroll';
|
||||||
|
|
||||||
const [createComponent, bem] = createNamespace('dropdown-menu');
|
const [createComponent, bem] = createNamespace('dropdown-menu');
|
||||||
|
|
||||||
@@ -44,6 +45,12 @@ export default createComponent({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
scroller() {
|
||||||
|
return getScrollEventTarget(this.$el);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
updateOffset() {
|
updateOffset() {
|
||||||
const { menu } = this.$refs;
|
const { menu } = this.$refs;
|
||||||
|
@@ -32,7 +32,7 @@ test('error loaded, click error-text and reload', async () => {
|
|||||||
expect(wrapper.emitted('load')).toBeFalsy();
|
expect(wrapper.emitted('load')).toBeFalsy();
|
||||||
expect(wrapper.emitted('input')).toBeFalsy();
|
expect(wrapper.emitted('input')).toBeFalsy();
|
||||||
|
|
||||||
// 模拟点击error-text的行为
|
// simulate the behavior of clicking error-text
|
||||||
wrapper.vm.$on('update:error', val => {
|
wrapper.vm.$on('update:error', val => {
|
||||||
wrapper.setProps({
|
wrapper.setProps({
|
||||||
error: val
|
error: val
|
||||||
|
Reference in New Issue
Block a user