Skip to content

Commit

Permalink
fix(date-picker): separator prop not working, closes #1456
Browse files Browse the repository at this point in the history
  • Loading branch information
07akioni committed Oct 27, 2021
1 parent ea16d5f commit 93f5b4f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- Fix `n-log` `font-size` prop not working, closes [#1416](https://github.com/TuSimple/naive-ui/issues/1416).
- Fix `n-loading-bar` will show once even if `start` is not called when `loading-bar-style` is set.
- Fix `n-date-picker` `separator` prop not working, closes [#1456](https://github.com/TuSimple/naive-ui/issues/1456)

### Feats

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- 修复 `n-log` `font-size` 属性不生效,关闭 [#1416](https://github.com/TuSimple/naive-ui/issues/1416)
- 修复 `n-loading-bar` 设定 `loading-bar-style` 后不调用 `start` 也会显示一次
- 修复 `n-date-picker` `separator` 不生效,关闭 [#1456](https://github.com/TuSimple/naive-ui/issues/1456)

### Feats

Expand Down
19 changes: 11 additions & 8 deletions src/date-picker/src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -799,14 +799,17 @@ export default defineComponent({
{...commonInputProps}
>
{{
separator: () => (
<NBaseIcon
clsPrefix={mergedClsPrefix}
class={`${mergedClsPrefix}-date-picker-icon`}
>
{{ default: () => <ToIcon /> }}
</NBaseIcon>
),
separator: () =>
this.separator === undefined ? (
<NBaseIcon
clsPrefix={mergedClsPrefix}
class={`${mergedClsPrefix}-date-picker-icon`}
>
{{ default: () => <ToIcon /> }}
</NBaseIcon>
) : (
this.separator
),
[clearable ? 'clear' : 'suffix']: () => (
<NBaseIcon
clsPrefix={mergedClsPrefix}
Expand Down
14 changes: 11 additions & 3 deletions src/date-picker/tests/DatePicker.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mount } from '@vue/test-utils'
import { NDatePicker } from '../index'
import { Value } from '../src/interface'
import { format } from 'date-fns'
import { useLocale } from '../../_mixins'
import { dateEnUS } from '../../locales'

describe('n-date-picker', () => {
it('should work with import on demand', () => {
Expand Down Expand Up @@ -198,7 +198,6 @@ describe('n-date-picker', () => {
})

it('should work with `defaultValue` prop', async () => {
const { dateLocaleRef } = useLocale('Time')
const wrapper = mount(NDatePicker, {
props: {
defaultValue: 1183135260000
Expand All @@ -208,7 +207,7 @@ describe('n-date-picker', () => {
const inputEl = await wrapper.find('.n-input__input').find('input')
expect(inputEl.element.value).toEqual(
format(1183135260000, 'yyyy-MM-dd', {
locale: dateLocaleRef.value.locale
locale: dateEnUS.locale
})
)
})
Expand Down Expand Up @@ -283,4 +282,13 @@ describe('n-date-picker', () => {

wrapper.unmount()
})

it('should work with `separator` prop', async () => {
const wrapper = mount(NDatePicker, {
props: { separator: '07akioni', type: 'daterange' }
})
expect(wrapper.text().includes('07akioni')).toBe(true)
await wrapper.setProps({ separator: '08akioni', type: 'datetimerange' })
expect(wrapper.text().includes('08akioni')).toBe(true)
})
})

0 comments on commit 93f5b4f

Please sign in to comment.