mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-26 19:36:36 +08:00
fix(Picker): disabled not work in cascade mode (#6580)
This commit is contained in:
parent
8844679a24
commit
76cf64a2bf
@ -1,5 +1,5 @@
|
|||||||
// Utils
|
// Utils
|
||||||
import { createNamespace, isDef, isObject } from '../utils';
|
import { createNamespace, isDef } from '../utils';
|
||||||
import { preventDefault } from '../utils/dom/event';
|
import { preventDefault } from '../utils/dom/event';
|
||||||
import { BORDER_UNSET_TOP_BOTTOM } from '../utils/constant';
|
import { BORDER_UNSET_TOP_BOTTOM } from '../utils/constant';
|
||||||
import { pickerProps, DEFAULT_ITEM_HEIGHT } from './shared';
|
import { pickerProps, DEFAULT_ITEM_HEIGHT } from './shared';
|
||||||
@ -91,7 +91,7 @@ export default createComponent({
|
|||||||
: +this.defaultIndex;
|
: +this.defaultIndex;
|
||||||
|
|
||||||
formatted.push({
|
formatted.push({
|
||||||
values: cursor.children.map((item) => item[this.valueKey]),
|
values: cursor.children,
|
||||||
className: cursor.className,
|
className: cursor.className,
|
||||||
defaultIndex,
|
defaultIndex,
|
||||||
});
|
});
|
||||||
@ -106,7 +106,16 @@ export default createComponent({
|
|||||||
if (this.dataType === 'text') {
|
if (this.dataType === 'text') {
|
||||||
this.$emit(event, this.getColumnValue(0), this.getColumnIndex(0));
|
this.$emit(event, this.getColumnValue(0), this.getColumnIndex(0));
|
||||||
} else {
|
} 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)
|
this.getColumnIndex(0)
|
||||||
);
|
);
|
||||||
} else {
|
} 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];
|
const column = this.children[index];
|
||||||
|
|
||||||
if (column) {
|
if (column) {
|
||||||
if (this.dataType === 'cascade') {
|
column.setOptions(options);
|
||||||
// map should be removed in next major version
|
|
||||||
column.setOptions(
|
|
||||||
options.map((item) => (isObject(item) ? item[this.valueKey] : item))
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
column.setOptions(options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
7
src/picker/test/__snapshots__/cascade.spec.js.snap
Normal file
7
src/picker/test/__snapshots__/cascade.spec.js.snap
Normal 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>
|
||||||
|
`;
|
@ -108,3 +108,20 @@ test('setIndexes of cascade columns', () => {
|
|||||||
wrapper.find('.van-picker__confirm').trigger('click');
|
wrapper.find('.van-picker__confirm').trigger('click');
|
||||||
expect(wrapper.emitted('confirm')[0][0]).toEqual(['A2', 'B3', 'C6']);
|
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();
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user