fix(Picker): update cascade after setColumnValue (#5807)

This commit is contained in:
chenjiahan 2020-03-17 19:52:55 +08:00
parent 0a3ed53187
commit 9c55056b0a
3 changed files with 67 additions and 33 deletions

View File

@ -156,7 +156,14 @@ export default createComponent({
// set column value by index
setColumnValue(index, value) {
const column = this.getColumn(index);
column && column.setValue(value);
if (column) {
column.setValue(value);
if (this.dataType === 'cascade') {
this.onCascadeChange(index);
}
}
},
// @exposed-api

View File

@ -0,0 +1,59 @@
import Picker from '..';
import { mount, triggerDrag } from '../../../test';
import { cascadeColumns } from '../demo/data';
test('cascade columns', () => {
const wrapper = mount(Picker, {
propsData: {
showToolbar: true,
columns: cascadeColumns['en-US'],
},
});
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[0][0]).toEqual([
'Zhejiang',
'Hangzhou',
'Xihu',
]);
triggerDrag(wrapper.find('.van-picker-column'), 0, -100);
wrapper.find('.van-picker-column ul').trigger('transitionend');
expect(wrapper.emitted('change')[0][1]).toEqual([
'Fujian',
'Fuzhou',
'Gulou',
]);
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[1][0]).toEqual([
'Fujian',
'Fuzhou',
'Gulou',
]);
});
test('setColumnValue of cascade columns', () => {
const wrapper = mount(Picker, {
propsData: {
showToolbar: true,
columns: cascadeColumns['en-US'],
},
});
wrapper.vm.setColumnValue(0, 'Fujian');
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[0][0]).toEqual([
'Fujian',
'Fuzhou',
'Gulou',
]);
wrapper.vm.setColumnValue(1, 'Xiamen');
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[1][0]).toEqual([
'Fujian',
'Xiamen',
'Siming',
]);
});

View File

@ -1,6 +1,5 @@
import Picker from '..';
import PickerColumn from '../PickerColumn';
import { cascadeColumns } from '../demo/data';
import { mount, triggerDrag, later } from '../../../test';
const simpleColumn = ['1990', '1991', '1992', '1993', '1994', '1995'];
@ -232,37 +231,6 @@ test('columns-top、columns-bottom prop', () => {
expect(wrapper).toMatchSnapshot();
});
test('cascade columns', () => {
const wrapper = mount(Picker, {
propsData: {
showToolbar: true,
columns: cascadeColumns['en-US'],
},
});
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[0][0]).toEqual([
'Zhejiang',
'Hangzhou',
'Xihu',
]);
triggerDrag(wrapper.find('.van-picker-column'), 0, -100);
wrapper.find('.van-picker-column ul').trigger('transitionend');
expect(wrapper.emitted('change')[0][1]).toEqual([
'Fujian',
'Fuzhou',
'Gulou',
]);
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[1][0]).toEqual([
'Fujian',
'Fuzhou',
'Gulou',
]);
});
test('watch columns change', () => {
const wrapper = mount(Picker, {
propsData: {