mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Picker): update cascade after setColumnIndex (#5807)
This commit is contained in:
parent
9c55056b0a
commit
68f5d3d69b
@ -176,7 +176,14 @@ export default createComponent({
|
|||||||
// set column option index by column index
|
// set column option index by column index
|
||||||
setColumnIndex(columnIndex, optionIndex) {
|
setColumnIndex(columnIndex, optionIndex) {
|
||||||
const column = this.getColumn(columnIndex);
|
const column = this.getColumn(columnIndex);
|
||||||
column && column.setIndex(optionIndex);
|
|
||||||
|
if (column) {
|
||||||
|
column.setIndex(optionIndex);
|
||||||
|
|
||||||
|
if (this.dataType === 'cascade') {
|
||||||
|
this.onCascadeChange(columnIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// @exposed-api
|
// @exposed-api
|
||||||
|
@ -1,59 +1,84 @@
|
|||||||
import Picker from '..';
|
import Picker from '..';
|
||||||
import { mount, triggerDrag } from '../../../test';
|
import { mount, triggerDrag } from '../../../test';
|
||||||
import { cascadeColumns } from '../demo/data';
|
|
||||||
|
const COLUMNS = [
|
||||||
|
{
|
||||||
|
text: 'A1',
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
text: 'B1',
|
||||||
|
children: [{ text: 'C1' }, { text: 'C2' }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'B2',
|
||||||
|
children: [{ text: 'C3' }, { text: 'C4' }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'A2',
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
text: 'B3',
|
||||||
|
children: [{ text: 'C5' }, { text: 'C6' }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'B4',
|
||||||
|
children: [{ text: 'C7' }, { text: 'C8' }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
test('cascade columns', () => {
|
test('cascade columns', () => {
|
||||||
const wrapper = mount(Picker, {
|
const wrapper = mount(Picker, {
|
||||||
propsData: {
|
propsData: {
|
||||||
showToolbar: true,
|
showToolbar: true,
|
||||||
columns: cascadeColumns['en-US'],
|
columns: COLUMNS,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
wrapper.find('.van-picker__confirm').trigger('click');
|
wrapper.find('.van-picker__confirm').trigger('click');
|
||||||
expect(wrapper.emitted('confirm')[0][0]).toEqual([
|
expect(wrapper.emitted('confirm')[0][0]).toEqual(['A1', 'B1', 'C1']);
|
||||||
'Zhejiang',
|
|
||||||
'Hangzhou',
|
|
||||||
'Xihu',
|
|
||||||
]);
|
|
||||||
|
|
||||||
triggerDrag(wrapper.find('.van-picker-column'), 0, -100);
|
triggerDrag(wrapper.find('.van-picker-column'), 0, -100);
|
||||||
wrapper.find('.van-picker-column ul').trigger('transitionend');
|
wrapper.find('.van-picker-column ul').trigger('transitionend');
|
||||||
expect(wrapper.emitted('change')[0][1]).toEqual([
|
expect(wrapper.emitted('change')[0][1]).toEqual(['A2', 'B3', 'C5']);
|
||||||
'Fujian',
|
|
||||||
'Fuzhou',
|
|
||||||
'Gulou',
|
|
||||||
]);
|
|
||||||
|
|
||||||
wrapper.find('.van-picker__confirm').trigger('click');
|
wrapper.find('.van-picker__confirm').trigger('click');
|
||||||
expect(wrapper.emitted('confirm')[1][0]).toEqual([
|
expect(wrapper.emitted('confirm')[1][0]).toEqual(['A2', 'B3', 'C5']);
|
||||||
'Fujian',
|
|
||||||
'Fuzhou',
|
|
||||||
'Gulou',
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('setColumnValue of cascade columns', () => {
|
test('setColumnValue of cascade columns', () => {
|
||||||
const wrapper = mount(Picker, {
|
const wrapper = mount(Picker, {
|
||||||
propsData: {
|
propsData: {
|
||||||
showToolbar: true,
|
showToolbar: true,
|
||||||
columns: cascadeColumns['en-US'],
|
columns: COLUMNS,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
wrapper.vm.setColumnValue(0, 'Fujian');
|
wrapper.vm.setColumnValue(0, 'A2');
|
||||||
wrapper.find('.van-picker__confirm').trigger('click');
|
wrapper.find('.van-picker__confirm').trigger('click');
|
||||||
expect(wrapper.emitted('confirm')[0][0]).toEqual([
|
expect(wrapper.emitted('confirm')[0][0]).toEqual(['A2', 'B3', 'C5']);
|
||||||
'Fujian',
|
|
||||||
'Fuzhou',
|
|
||||||
'Gulou',
|
|
||||||
]);
|
|
||||||
|
|
||||||
wrapper.vm.setColumnValue(1, 'Xiamen');
|
wrapper.vm.setColumnValue(1, 'B4');
|
||||||
wrapper.find('.van-picker__confirm').trigger('click');
|
wrapper.find('.van-picker__confirm').trigger('click');
|
||||||
expect(wrapper.emitted('confirm')[1][0]).toEqual([
|
expect(wrapper.emitted('confirm')[1][0]).toEqual(['A2', 'B4', 'C7']);
|
||||||
'Fujian',
|
});
|
||||||
'Xiamen',
|
|
||||||
'Siming',
|
test('setColumnIndex of cascade columns', () => {
|
||||||
]);
|
const wrapper = mount(Picker, {
|
||||||
|
propsData: {
|
||||||
|
showToolbar: true,
|
||||||
|
columns: COLUMNS,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.vm.setColumnIndex(0, 1);
|
||||||
|
wrapper.find('.van-picker__confirm').trigger('click');
|
||||||
|
expect(wrapper.emitted('confirm')[0][0]).toEqual(['A2', 'B3', 'C5']);
|
||||||
|
|
||||||
|
wrapper.vm.setColumnIndex(1, 1);
|
||||||
|
wrapper.find('.van-picker__confirm').trigger('click');
|
||||||
|
expect(wrapper.emitted('confirm')[1][0]).toEqual(['A2', 'B4', 'C7']);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user