feat(Form): add input-align prop

This commit is contained in:
陈嘉涵 2020-02-13 16:25:42 +08:00
parent 2d64458776
commit 7a9d1d7ab6
5 changed files with 12 additions and 8 deletions

View File

@ -326,18 +326,17 @@ export default createComponent({
genInput() { genInput() {
const { type } = this; const { type } = this;
const inputSlot = this.slots('input'); const inputSlot = this.slots('input');
const inputAlign = this.getProp('inputAlign');
if (inputSlot) { if (inputSlot) {
return ( return (
<div class={bem('control', [this.inputAlign, 'custom'])}> <div class={bem('control', [inputAlign, 'custom'])}>{inputSlot}</div>
{inputSlot}
</div>
); );
} }
const inputProps = { const inputProps = {
ref: 'input', ref: 'input',
class: bem('control', this.inputAlign), class: bem('control', inputAlign),
domProps: { domProps: {
value: this.value, value: this.value,
}, },
@ -435,11 +434,13 @@ export default createComponent({
}, },
getProp(key) { getProp(key) {
if (isDef(this[key])) {
return this[key];
}
if (this.vanForm && isDef(this.vanForm[key])) { if (this.vanForm && isDef(this.vanForm[key])) {
return this.vanForm[key]; return this.vanForm[key];
} }
return this[key];
}, },
}, },

View File

@ -406,6 +406,7 @@ export default {
| Attribute | Description | Type | Default | | Attribute | Description | Type | Default |
|------|------|------|------| |------|------|------|------|
| label-align | Label text align, can be set to `center` `right` | *string* | `left` | | label-align | Label text align, can be set to `center` `right` | *string* | `left` |
| input-align | Input text align, can be set to `center` `right` | *string* | `left` |
| validate-first | Whether to stop the validation when a rule fails | *boolean* | `false` | | validate-first | Whether to stop the validation when a rule fails | *boolean* | `false` |
### Events ### Events

View File

@ -437,7 +437,8 @@ export default {
| 参数 | 说明 | 类型 | 默认值 | | 参数 | 说明 | 类型 | 默认值 |
|------|------|------|------| |------|------|------|------|
| label-align | 表单项左侧文本对齐方式,可选值为 `center` `right` | *string* | `left` | | label-align | 表单项文本对齐方式,可选值为 `center` `right` | *string* | `left` |
| input-align | 输入框内容对齐方式,可选值为 `center` `right` | *string* | `left` |
| validate-first | 是否在某一项校验不通过时停止校验 | *boolean* | `false` | | validate-first | 是否在某一项校验不通过时停止校验 | *boolean* | `false` |
### Events ### Events

View File

@ -1,6 +1,6 @@
<template> <template>
<demo-block :title="$t('basicUsage')"> <demo-block :title="$t('basicUsage')">
<van-form ref="form" @submit="onSubmit" @failed="onFailed"> <van-form @submit="onSubmit" @failed="onFailed">
<van-field <van-field
v-model="username" v-model="username"
name="username" name="username"

View File

@ -5,6 +5,7 @@ const [createComponent, bem] = createNamespace('form');
export default createComponent({ export default createComponent({
props: { props: {
labelAlign: String, labelAlign: String,
inputAlign: String,
validateFirst: Boolean, validateFirst: Boolean,
}, },