fix(Picker): disabled not work in cascade mode (#6580)

This commit is contained in:
neverland 2020-06-20 16:03:30 +08:00 committed by GitHub
parent 8844679a24
commit 76cf64a2bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 12 deletions

View File

@ -1,5 +1,5 @@
// Utils
import { createNamespace, isDef, isObject } from '../utils';
import { createNamespace, isDef } from '../utils';
import { preventDefault } from '../utils/dom/event';
import { BORDER_UNSET_TOP_BOTTOM } from '../utils/constant';
import { pickerProps, DEFAULT_ITEM_HEIGHT } from './shared';
@ -91,7 +91,7 @@ export default createComponent({
: +this.defaultIndex;
formatted.push({
values: cursor.children.map((item) => item[this.valueKey]),
values: cursor.children,
className: cursor.className,
defaultIndex,
});
@ -106,7 +106,16 @@ export default createComponent({
if (this.dataType === 'text') {
this.$emit(event, this.getColumnValue(0), this.getColumnIndex(0));
} else {
this.$emit(event, this.getValues(), this.getIndexes());
let values = this.getValues();
// compatible with old version of wrong parameters
// should be removed in next major version
// see: https://github.com/youzan/vant/issues/5905
if (this.dataType === 'cascade') {
values = values.map((item) => item[this.valueKey]);
}
this.$emit(event, values, this.getIndexes());
}
},
@ -138,7 +147,16 @@ export default createComponent({
this.getColumnIndex(0)
);
} else {
this.$emit('change', this, this.getValues(), columnIndex);
let values = this.getValues();
// compatible with old version of wrong parameters
// should be removed in next major version
// see: https://github.com/youzan/vant/issues/5905
if (this.dataType === 'cascade') {
values = values.map((item) => item[this.valueKey]);
}
this.$emit('change', this, values, columnIndex);
}
},
@ -200,14 +218,7 @@ export default createComponent({
const column = this.children[index];
if (column) {
if (this.dataType === 'cascade') {
// map should be removed in next major version
column.setOptions(
options.map((item) => (isObject(item) ? item[this.valueKey] : item))
);
} else {
column.setOptions(options);
}
column.setOptions(options);
}
},

View File

@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`disabled in cascade 1`] = `
<li role="button" tabindex="-1" class="van-picker-column__item van-picker-column__item--disabled">
<div class="van-ellipsis">A2</div>
</li>
`;

View File

@ -108,3 +108,20 @@ test('setIndexes of cascade columns', () => {
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[0][0]).toEqual(['A2', 'B3', 'C6']);
});
test('disabled in cascade', () => {
const wrapper = mount(Picker, {
propsData: {
showToolbar: true,
columns: [
COLUMNS[0],
{
...COLUMNS[1],
disabled: true,
},
],
},
});
expect(wrapper.find('.van-picker-column__item--disabled')).toMatchSnapshot();
});