-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(form): add
show-label
prop (#865)
* feat(form): add show-label prop and test (#858) * docs(form): add show-label doc and fix form item label desc (#858) * Update CHANGELOG.en-US.md Co-authored-by: Yugang Cao <[email protected]> * Update CHANGELOG.zh-CN.md Co-authored-by: Yugang Cao <[email protected]> * feat(form): rewrite show-label and add tests (#858) * docs(form): add show-label demo (#858) * feat(form): change show-label computed (#858) * feat(form): fix show-label (#858) * feat(form): fix bug (#858) * feat(form): update show-label scripts (#858) * docs(form): update show-label order and label description (#858) * Apply suggestions from code review Co-authored-by: kev1nzh <[email protected]> Co-authored-by: Yugang Cao <[email protected]> Co-authored-by: kev1nzh_ark <[email protected]> Co-authored-by: 07akioni <[email protected]>
- Loading branch information
1 parent
19282b6
commit b401ff4
Showing
10 changed files
with
184 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Show/hide Label | ||
|
||
`show-label`: When the value is `false`, the `label` element and placeholder for `n-form-item` will be hidden. | ||
|
||
`n-form-item` will use the `show-label` of the enclosing `n-form` if it is not set, or default to `true` if neither is set. | ||
|
||
```html | ||
<div :style="switchStyle"> | ||
<label>n-form:</label> | ||
<n-switch v-model:value="formShowLabel" /> | ||
</div> | ||
<div :style="switchStyle"> | ||
<label>n-form-item:</label> | ||
<n-switch v-model:value="formItemShowLabel" /> | ||
</div> | ||
|
||
<n-form :model="formValue" ref="formRef" :show-label="formShowLabel"> | ||
<n-form-item label="Name" path="user.name" :show-label="formItemShowLabel"> | ||
<n-input v-model:value="formValue.user.name" placeholder="Input Name" /> | ||
</n-form-item> | ||
<n-form-item label="Age" path="user.age"> | ||
<n-input placeholder="Input Age" v-model:value="formValue.user.age" /> | ||
</n-form-item> | ||
<n-form-item label="Phone" path="user.phone"> | ||
<n-input placeholder="Input Phone" v-model:value="formValue.phone" /> | ||
</n-form-item> | ||
</n-form> | ||
``` | ||
|
||
```js | ||
import { defineComponent, ref } from 'vue' | ||
|
||
export default defineComponent({ | ||
setup () { | ||
const formRef = ref(null) | ||
const formShowLabel = ref(true) | ||
const formItemShowLabel = ref(true) | ||
return { | ||
formRef, | ||
formValue: ref({ | ||
user: { | ||
name: '', | ||
age: '' | ||
}, | ||
phone: '' | ||
}), | ||
formShowLabel, | ||
formItemShowLabel, | ||
switchStyle: { | ||
marginBottom: '12px' | ||
} | ||
} | ||
} | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# 显示/隐藏标签 | ||
|
||
`show-label`: 当值为 `false` 时,会隐藏 `n-form-item` 的 `label` 元素和占位。 | ||
|
||
`n-form-item` 若未被设定,则会使用外层 `n-form` 的 `show-label`, 若都未被设定,则默认为 `true`。 | ||
|
||
```html | ||
<div :style="switchStyle"> | ||
<label>n-form:</label> | ||
<n-switch v-model:value="formShowLabel" /> | ||
</div> | ||
<div :style="switchStyle"> | ||
<label>n-form-item:</label> | ||
<n-switch v-model:value="formItemShowLabel" /> | ||
</div> | ||
|
||
<n-form :model="formValue" ref="formRef" :show-label="formShowLabel"> | ||
<n-form-item label="姓名" path="user.name" :show-label="formItemShowLabel"> | ||
<n-input v-model:value="formValue.user.name" placeholder="输入姓名" /> | ||
</n-form-item> | ||
<n-form-item label="年龄" path="user.age"> | ||
<n-input placeholder="输入年龄" v-model:value="formValue.user.age" /> | ||
</n-form-item> | ||
<n-form-item label="电话号码" path="user.phone"> | ||
<n-input placeholder="电话号码" v-model:value="formValue.phone" /> | ||
</n-form-item> | ||
</n-form> | ||
``` | ||
|
||
```js | ||
import { defineComponent, ref } from 'vue' | ||
|
||
export default defineComponent({ | ||
setup () { | ||
const formRef = ref(null) | ||
const formShowLabel = ref(true) | ||
const formItemShowLabel = ref(true) | ||
return { | ||
formRef, | ||
formValue: ref({ | ||
user: { | ||
name: '', | ||
age: '' | ||
}, | ||
phone: '' | ||
}), | ||
formShowLabel, | ||
formItemShowLabel, | ||
switchStyle: { | ||
marginBottom: '12px' | ||
} | ||
} | ||
} | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters