Merge pull request #202 from TuSimple/main

sync main
This commit is contained in:
07akioni 2021-06-19 16:41:11 +08:00 committed by GitHub
commit 1662605688
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 115 additions and 19 deletions

View File

@ -1,6 +1,12 @@
# CHANGELOG
## 2.12.1
## 2.12.2 (2021-06-19)
### Fixes
- Fix `n-form-item` always show require mark.
## 2.12.1 (2021-06-19)
### Feats

View File

@ -1,6 +1,12 @@
# CHANGELOG
## 2.12.1
## 2.12.2 (2021-06-19)
### Fixes
- 修复 `n-form-item` 始终展示必需的星号
## 2.12.1 (2021-06-19)
### Feats

View File

@ -34,8 +34,10 @@
- 新增属性
```
- `n-xxx` add xxx prop.
- `n-xxx` 新增 xxx 属性
- `n-xxx` add `xxx` prop.
- `n-xxx` 新增 `xxx` 属性
注意 `xxx` 属性必须是 kebab-case不能是 camelCase。
```
- 修复 Bug

View File

@ -1,6 +1,6 @@
{
"name": "naive-ui",
"version": "2.12.1",
"version": "2.12.2",
"description": "A Vue 3 Component Library. Fairly Complete, Customizable Themes, Uses TypeScript, Not Too Slow",
"main": "lib/index.js",
"module": "es/index.js",

View File

@ -41,7 +41,7 @@ const formProps = {
size: String as PropType<'small' | 'medium' | 'large'>,
showRequireMark: {
type: [Boolean, String] as PropType<'left' | 'right' | boolean>,
default: 'right'
default: undefined
},
showFeedback: {
type: Boolean,

View File

@ -401,6 +401,7 @@ export default defineComponent({
class={`${mergedClsPrefix}-form-item-label`}
style={this.mergedLabelStyle as any}
>
{/* undefined || 'right' || true || false */}
{this.mergedShowRequireMark !== 'left'
? renderSlot($slots, 'label', undefined, () => [this.label])
: null}

View File

@ -57,10 +57,7 @@ export function formItemMisc (props: FormItemSetupProps) {
const mergedShowRequireMarkRef = computed(() => {
const { showRequireMark } = props
if (showRequireMark !== undefined) return showRequireMark
if (NForm?.showRequireMark !== undefined) {
return NForm.showRequireMark
}
return undefined
return NForm?.showRequireMark
})
const validationErroredRef = ref(false)
const mergedValidationStatusRef = computed(() => {

View File

@ -1,8 +0,0 @@
import { mount } from '@vue/test-utils'
import { NForm } from '../index'
describe('n-form', () => {
it('should work with import on demand', () => {
mount(NForm)
})
})

View File

@ -0,0 +1,92 @@
import { mount } from '@vue/test-utils'
import { h } from 'vue'
import { NInput } from '../../input'
import { NForm, NFormItem } from '../index'
describe('n-form', () => {
it('should work with import on demand', () => {
mount(NForm)
})
describe('require mark', () => {
it("doesn't show by default", () => {
const wrapper = mount(() => (
<NForm>
{{
default: () => {
return (
<NFormItem label="star kirby">
{{
default: () => <NInput />
}}
</NFormItem>
)
}
}}
</NForm>
))
expect(wrapper.find('.n-form-item-label__asterisk').exists()).toEqual(
false
)
})
it('shows when props.showRequireMark is set', () => {
const wrapper = mount(() => (
<NForm>
{{
default: () => {
return (
<NFormItem showRequireMark label="star kirby">
{{
default: () => <NInput />
}}
</NFormItem>
)
}
}}
</NForm>
))
expect(wrapper.find('.n-form-item-label__asterisk').exists()).toEqual(
true
)
})
it('shows when required rule is set in form', () => {
const wrapper = mount(() => (
<NForm rules={{ starKirby: { required: true } }}>
{{
default: () => {
return (
<NFormItem label="star kirby" path="starKirby">
{{
default: () => <NInput />
}}
</NFormItem>
)
}
}}
</NForm>
))
expect(wrapper.find('.n-form-item-label__asterisk').exists()).toEqual(
true
)
})
it('shows when required rule is set in form item', () => {
const wrapper = mount(() => (
<NForm>
{{
default: () => {
return (
<NFormItem label="star kirby" rule={{ required: true }}>
{{
default: () => <NInput />
}}
</NFormItem>
)
}
}}
</NForm>
))
expect(wrapper.find('.n-form-item-label__asterisk').exists()).toEqual(
true
)
})
})
})

View File

@ -1 +1 @@
export default '2.12.1'
export default '2.12.2'