Browse Source

fix: cascader keydown not work in search #958

pull/3972/head
tangjinzhou 4 years ago
parent
commit
97167fdb7a
  1. 7
      components/vc-cascader/Cascader.jsx
  2. 5
      components/vc-cascader/Menus.jsx

7
components/vc-cascader/Cascader.jsx

@ -9,6 +9,7 @@ import { hasProp, getEvents } from '../_util/props-util';
import BaseMixin from '../_util/BaseMixin';
import { cloneElement } from '../_util/vnode';
import { defineComponent } from 'vue';
import isEqual from 'lodash-es/isEqual';
const BUILT_IN_PLACEMENTS = {
bottomLeft: {
@ -134,7 +135,7 @@ export default defineComponent({
const { options = [], sActiveValue = [] } = this;
const result = arrayTreeFilter(
options,
(o, level) => o[this.getFieldName('value')] === sActiveValue[level],
(o, level) => isEqual(o[this.getFieldName('value')], sActiveValue[level]),
{ childrenKeyName: this.getFieldName('children') },
);
if (result[result.length - 2]) {
@ -145,7 +146,7 @@ export default defineComponent({
getActiveOptions(activeValue) {
return arrayTreeFilter(
this.options || [],
(o, level) => o[this.getFieldName('value')] === activeValue[level],
(o, level) => isEqual(o[this.getFieldName('value')], activeValue[level]),
{ childrenKeyName: this.getFieldName('children') },
);
},
@ -244,7 +245,7 @@ export default defineComponent({
const currentOptions = this.getCurrentLevelOptions();
const currentIndex = currentOptions
.map(o => o[this.getFieldName('value')])
.indexOf(activeValue[currentLevel]);
.findIndex(val => isEqual(activeValue[currentLevel], val));
if (
e.keyCode !== KeyCode.DOWN &&
e.keyCode !== KeyCode.UP &&

5
components/vc-cascader/Menus.jsx

@ -2,6 +2,7 @@ import { getComponent, findDOMNode } from '../_util/props-util';
import PropTypes from '../_util/vue-types';
import arrayTreeFilter from 'array-tree-filter';
import BaseMixin from '../_util/BaseMixin';
import isEqual from 'lodash-es/isEqual';
export default {
name: 'CascaderMenus',
@ -116,7 +117,7 @@ export default {
const options = this.options;
return arrayTreeFilter(
options,
(o, level) => o[this.getFieldName('value')] === activeValue[level],
(o, level) => isEqual(o[this.getFieldName('value')], activeValue[level]),
{ childrenKeyName: this.getFieldName('children') },
);
},
@ -157,7 +158,7 @@ export default {
isActiveOption(option, menuIndex) {
const { activeValue = [] } = this;
return activeValue[menuIndex] === option[this.getFieldName('value')];
return isEqual(activeValue[menuIndex], option[this.getFieldName('value')]);
},
saveMenuItem(index) {
return node => {

Loading…
Cancel
Save