mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Picker): update cascade after setColumnValue (#5807)
This commit is contained in:
parent
0a3ed53187
commit
9c55056b0a
@ -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
|
||||
|
59
src/picker/test/cascade.spec.js
Normal file
59
src/picker/test/cascade.spec.js
Normal 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',
|
||||
]);
|
||||
});
|
@ -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: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user