change the way to handle submenu collapse when accordion is true
This commit is contained in:
parent
b924d14da3
commit
2b24fcceed
7 changed files with 147 additions and 12 deletions
|
@ -2,7 +2,7 @@
|
|||
<ul :class="classes" :style="styles"><slot></slot></ul>
|
||||
</template>
|
||||
<script>
|
||||
import { oneOf, findComponentsDownward, findBrothersComponents } from '../../utils/assist';
|
||||
import { oneOf, findComponentsDownward, findComponentsUpward } from '../../utils/assist';
|
||||
import Emitter from '../../mixins/emitter';
|
||||
|
||||
const prefixCls = 'ivu-menu';
|
||||
|
@ -84,17 +84,18 @@
|
|||
} else {
|
||||
if (this.accordion) {
|
||||
let currentSubmenu = null;
|
||||
names = [];
|
||||
findComponentsDownward(this, 'Submenu').forEach(item => {
|
||||
if (item.name === name) currentSubmenu = item;
|
||||
});
|
||||
findBrothersComponents(currentSubmenu, 'Submenu').forEach(item => {
|
||||
let i = names.indexOf(item.name);
|
||||
if (i >= 0) names.splice(i, 1);
|
||||
findComponentsUpward(currentSubmenu, 'Submenu').forEach(item => {
|
||||
names.push(item.name);
|
||||
});
|
||||
}
|
||||
names.push(name);
|
||||
}
|
||||
this.openedNames = names;
|
||||
this.updateOpened();
|
||||
this.$emit('on-open-change', this.openedNames);
|
||||
},
|
||||
updateOpened () {
|
||||
|
|
|
@ -16,4 +16,4 @@ export default {
|
|||
return this.menu.mode;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -234,7 +234,9 @@ export function findBrothersComponents (context, componentName, exceptMe = true)
|
|||
let res = context.$parent.$children.filter(item => {
|
||||
return item.$options.name === componentName;
|
||||
});
|
||||
let index = res.indexOf(context);
|
||||
let index = res.findIndex(item => {
|
||||
return item._uid === context._uid;
|
||||
});
|
||||
if (exceptMe) res.splice(index, 1);
|
||||
return res;
|
||||
}
|
||||
|
@ -322,3 +324,15 @@ export function setMatchMedia () {
|
|||
window.matchMedia = window.matchMedia || matchMediaPolyfill;
|
||||
}
|
||||
}
|
||||
|
||||
export function getCommonString (arr1, arr2) {
|
||||
const len1 = arr1.length;
|
||||
const len2 = arr2.length;
|
||||
let i = -1;
|
||||
const len = Math.min(len1, len2);
|
||||
let res = [];
|
||||
while (++i < len) {
|
||||
if (arr1.indexOf(arr2[i]) >= 0) res.push(arr2[i]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue