mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-09-06 15:59:45 +08:00
feat(Form): add disabled and readonly prop (#7829)
* feat(Form): add disabled and readonly prop * chore(Field): 使用 getProp 方法 * fix(Field): 将 computed 改为直接取值
This commit is contained in:
parent
6972afffb5
commit
8da1e23d53
@ -37,8 +37,14 @@ export default createComponent({
|
|||||||
...cellProps,
|
...cellProps,
|
||||||
name: String,
|
name: String,
|
||||||
rules: Array,
|
rules: Array,
|
||||||
disabled: Boolean,
|
disabled: {
|
||||||
readonly: Boolean,
|
type: Boolean,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
readonly: {
|
||||||
|
type: Boolean,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
autosize: [Boolean, Object],
|
autosize: [Boolean, Object],
|
||||||
leftIcon: String,
|
leftIcon: String,
|
||||||
rightIcon: String,
|
rightIcon: String,
|
||||||
@ -113,7 +119,9 @@ export default createComponent({
|
|||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
showClear() {
|
showClear() {
|
||||||
if (this.clearable && !this.readonly) {
|
const readonly = this.getProp('readonly');
|
||||||
|
|
||||||
|
if (this.clearable && !readonly) {
|
||||||
const hasValue = isDef(this.value) && this.value !== '';
|
const hasValue = isDef(this.value) && this.value !== '';
|
||||||
const trigger =
|
const trigger =
|
||||||
this.clearTrigger === 'always' ||
|
this.clearTrigger === 'always' ||
|
||||||
@ -339,7 +347,8 @@ export default createComponent({
|
|||||||
|
|
||||||
// readonly not work in lagacy mobile safari
|
// readonly not work in lagacy mobile safari
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (this.readonly) {
|
const readonly = this.getProp('readonly');
|
||||||
|
if (readonly) {
|
||||||
this.blur();
|
this.blur();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -418,6 +427,8 @@ export default createComponent({
|
|||||||
|
|
||||||
genInput() {
|
genInput() {
|
||||||
const { type } = this;
|
const { type } = this;
|
||||||
|
const disabled = this.getProp('disabled');
|
||||||
|
const readonly = this.getProp('readonly');
|
||||||
const inputSlot = this.slots('input');
|
const inputSlot = this.slots('input');
|
||||||
const inputAlign = this.getProp('inputAlign');
|
const inputAlign = this.getProp('inputAlign');
|
||||||
|
|
||||||
@ -441,8 +452,8 @@ export default createComponent({
|
|||||||
attrs: {
|
attrs: {
|
||||||
...this.$attrs,
|
...this.$attrs,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
disabled: this.disabled,
|
disabled,
|
||||||
readonly: this.readonly,
|
readonly,
|
||||||
placeholder: this.placeholder,
|
placeholder: this.placeholder,
|
||||||
},
|
},
|
||||||
on: this.listeners,
|
on: this.listeners,
|
||||||
@ -559,6 +570,7 @@ export default createComponent({
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { slots } = this;
|
const { slots } = this;
|
||||||
|
const disabled = this.getProp('disabled');
|
||||||
const labelAlign = this.getProp('labelAlign');
|
const labelAlign = this.getProp('labelAlign');
|
||||||
|
|
||||||
const scopedSlots = {
|
const scopedSlots = {
|
||||||
@ -591,7 +603,7 @@ export default createComponent({
|
|||||||
arrowDirection={this.arrowDirection}
|
arrowDirection={this.arrowDirection}
|
||||||
class={bem({
|
class={bem({
|
||||||
error: this.showError,
|
error: this.showError,
|
||||||
disabled: this.disabled,
|
disabled,
|
||||||
[`label-${labelAlign}`]: labelAlign,
|
[`label-${labelAlign}`]: labelAlign,
|
||||||
'min-height': this.type === 'textarea' && !this.autosize,
|
'min-height': this.type === 'textarea' && !this.autosize,
|
||||||
})}
|
})}
|
||||||
|
@ -427,6 +427,8 @@ export default {
|
|||||||
|
|
||||||
| Attribute | Description | Type | Default |
|
| Attribute | Description | Type | Default |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
|
| disabled | Whether to disable field | _boolean_ | `false` |
|
||||||
|
| readonly | Whether to be readonly | _boolean_ | `false` |
|
||||||
| label-width | Field label width | _number \| string_ | `6.2em` |
|
| label-width | Field label width | _number \| string_ | `6.2em` |
|
||||||
| label-align | Field label align, can be set to `center` `right` | _string_ | `left` |
|
| label-align | Field label align, can be set to `center` `right` | _string_ | `left` |
|
||||||
| input-align | Field input align, can be set to `center` `right` | _string_ | `left` |
|
| input-align | Field input align, can be set to `center` `right` | _string_ | `left` |
|
||||||
|
@ -458,6 +458,8 @@ export default {
|
|||||||
|
|
||||||
| 参数 | 说明 | 类型 | 默认值 |
|
| 参数 | 说明 | 类型 | 默认值 |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
|
| disabled | 是否禁用输入框 | _boolean_ | `false` |
|
||||||
|
| readonly | 是否只读 | _boolean_ | `false` |
|
||||||
| label-width | 表单项 label 宽度,默认单位为`px` | _number \| string_ | `6.2em` |
|
| label-width | 表单项 label 宽度,默认单位为`px` | _number \| string_ | `6.2em` |
|
||||||
| label-align | 表单项 label 对齐方式,可选值为 `center` `right` | _string_ | `left` |
|
| label-align | 表单项 label 对齐方式,可选值为 `center` `right` | _string_ | `left` |
|
||||||
| input-align | 输入框对齐方式,可选值为 `center` `right` | _string_ | `left` |
|
| input-align | 输入框对齐方式,可选值为 `center` `right` | _string_ | `left` |
|
||||||
|
@ -5,6 +5,8 @@ const [createComponent, bem] = createNamespace('form');
|
|||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
props: {
|
props: {
|
||||||
|
disabled: Boolean,
|
||||||
|
readonly: Boolean,
|
||||||
colon: Boolean,
|
colon: Boolean,
|
||||||
labelWidth: [Number, String],
|
labelWidth: [Number, String],
|
||||||
labelAlign: String,
|
labelAlign: String,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user