mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-25 02:41:46 +08:00
feat(Picker): add readonly prop (#7105)
This commit is contained in:
parent
f6e3aaebec
commit
3cd200f7c2
@ -31,6 +31,7 @@ export default createComponent({
|
|||||||
|
|
||||||
props: {
|
props: {
|
||||||
valueKey: String,
|
valueKey: String,
|
||||||
|
readonly: Boolean,
|
||||||
allowHtml: Boolean,
|
allowHtml: Boolean,
|
||||||
className: String,
|
className: String,
|
||||||
itemHeight: Number,
|
itemHeight: Number,
|
||||||
@ -99,6 +100,10 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onTouchStart(event) {
|
onTouchStart(event) {
|
||||||
|
if (this.readonly) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.touchStart(event);
|
this.touchStart(event);
|
||||||
|
|
||||||
if (this.moving) {
|
if (this.moving) {
|
||||||
@ -116,6 +121,10 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onTouchMove(event) {
|
onTouchMove(event) {
|
||||||
|
if (this.readonly) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.touchMove(event);
|
this.touchMove(event);
|
||||||
|
|
||||||
if (this.direction === 'vertical') {
|
if (this.direction === 'vertical') {
|
||||||
@ -137,6 +146,10 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onTouchEnd() {
|
onTouchEnd() {
|
||||||
|
if (this.readonly) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const distance = this.offset - this.momentumOffset;
|
const distance = this.offset - this.momentumOffset;
|
||||||
const duration = Date.now() - this.touchStartTime;
|
const duration = Date.now() - this.touchStartTime;
|
||||||
const allowMomentum =
|
const allowMomentum =
|
||||||
@ -164,7 +177,7 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onClickItem(index) {
|
onClickItem(index) {
|
||||||
if (this.moving) {
|
if (this.moving || this.readonly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,6 +249,7 @@ export default {
|
|||||||
| value-key | Key of option text | _string_ | `text` |
|
| value-key | Key of option text | _string_ | `text` |
|
||||||
| toolbar-position | Toolbar position, cat be set to `bottom` | _string_ | `top` |
|
| toolbar-position | Toolbar position, cat be set to `bottom` | _string_ | `top` |
|
||||||
| loading | Whether to show loading prompt | _boolean_ | `false` |
|
| loading | Whether to show loading prompt | _boolean_ | `false` |
|
||||||
|
| readonly `v2.10.5` | Whether to be readonly | _boolean_ | `false` |
|
||||||
| show-toolbar | Whether to show toolbar | _boolean_ | `false` |
|
| show-toolbar | Whether to show toolbar | _boolean_ | `false` |
|
||||||
| allow-html `v2.1.8` | Whether to allow HTML in option text | _boolean_ | `true` |
|
| allow-html `v2.1.8` | Whether to allow HTML in option text | _boolean_ | `true` |
|
||||||
| default-index | Default value index of single column picker | _number \| string_ | `0` |
|
| default-index | Default value index of single column picker | _number \| string_ | `0` |
|
||||||
|
@ -272,6 +272,7 @@ export default {
|
|||||||
| value-key | 选项对象中,选项文字对应的键名 | _string_ | `text` |
|
| value-key | 选项对象中,选项文字对应的键名 | _string_ | `text` |
|
||||||
| toolbar-position | 顶部栏位置,可选值为`bottom` | _string_ | `top` |
|
| toolbar-position | 顶部栏位置,可选值为`bottom` | _string_ | `top` |
|
||||||
| loading | 是否显示加载状态 | _boolean_ | `false` |
|
| loading | 是否显示加载状态 | _boolean_ | `false` |
|
||||||
|
| readonly `v2.10.5` | 是否为只读状态,只读状态下无法切换选项 | _boolean_ | `false` |
|
||||||
| show-toolbar | 是否显示顶部栏 | _boolean_ | `false` |
|
| show-toolbar | 是否显示顶部栏 | _boolean_ | `false` |
|
||||||
| allow-html `v2.1.8` | 是否允许选项内容中渲染 HTML | _boolean_ | `true` |
|
| allow-html `v2.1.8` | 是否允许选项内容中渲染 HTML | _boolean_ | `true` |
|
||||||
| default-index | 单列选择时,默认选中项的索引 | _number \| string_ | `0` |
|
| default-index | 单列选择时,默认选中项的索引 | _number \| string_ | `0` |
|
||||||
|
@ -323,6 +323,7 @@ export default createComponent({
|
|||||||
genColumnItems() {
|
genColumnItems() {
|
||||||
return this.formattedColumns.map((item, columnIndex) => (
|
return this.formattedColumns.map((item, columnIndex) => (
|
||||||
<PickerColumn
|
<PickerColumn
|
||||||
|
readonly={this.readonly}
|
||||||
valueKey={this.valueKey}
|
valueKey={this.valueKey}
|
||||||
allowHtml={this.allowHtml}
|
allowHtml={this.allowHtml}
|
||||||
className={item.className}
|
className={item.className}
|
||||||
|
@ -13,6 +13,7 @@ export const DEFAULT_ITEM_HEIGHT = 44;
|
|||||||
export const pickerProps = {
|
export const pickerProps = {
|
||||||
title: String,
|
title: String,
|
||||||
loading: Boolean,
|
loading: Boolean,
|
||||||
|
readonly: Boolean,
|
||||||
itemHeight: [Number, String],
|
itemHeight: [Number, String],
|
||||||
showToolbar: Boolean,
|
showToolbar: Boolean,
|
||||||
cancelButtonText: String,
|
cancelButtonText: String,
|
||||||
|
@ -279,3 +279,18 @@ test('set rem item-height', async () => {
|
|||||||
|
|
||||||
window.getComputedStyle = originGetComputedStyle;
|
window.getComputedStyle = originGetComputedStyle;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('readonly prop', () => {
|
||||||
|
const wrapper = mount(Picker, {
|
||||||
|
propsData: {
|
||||||
|
columns,
|
||||||
|
readonly: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
triggerDrag(wrapper.find('.van-picker-column'), 0, -100);
|
||||||
|
wrapper.find('.van-picker-column ul').trigger('transitionend');
|
||||||
|
wrapper.findAll('.van-picker-column__item').at(3).trigger('click');
|
||||||
|
|
||||||
|
expect(wrapper.emitted('change')).toBeFalsy();
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user