Skip to content

Commit

Permalink
fix(calendar): on-update:value prop type
Browse files Browse the repository at this point in the history
  • Loading branch information
07akioni committed Jun 12, 2021
1 parent 7033bf9 commit 5a7b2fa
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## Pending

### Fixes

- Fix `n-calendar`'s `on-update:value` prop type.

## 2.11.7

### Fixes
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## Pending

### Fixes

- 修复 `n-calendar``on-update:value` 属性类型

## 2.11.7

### Fixes
Expand Down
16 changes: 4 additions & 12 deletions src/calendar/src/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useConfig, useLocale, useTheme } from '../../_mixins'
import type { ThemeProps } from '../../_mixins'
import { calendarLight } from '../styles'
import type { CalendarTheme } from '../styles'
import type { OnUpdateValue, DateItem } from './interface'
import style from './styles/index.cssr'

const calendarProps = {
Expand All @@ -31,22 +32,12 @@ const calendarProps = {
type: Number as PropType<number | null>,
defualt: null
},
'onUpdate:value': [Function, Array] as PropType<
MaybeArray<(value: number) => void>
>,
onUpdateValue: [Function, Array] as PropType<
MaybeArray<(value: number) => void>
>
'onUpdate:value': [Function, Array] as PropType<MaybeArray<OnUpdateValue>>,
onUpdateValue: [Function, Array] as PropType<MaybeArray<OnUpdateValue>>
} as const

export type CalendarProps = ExtractPublicPropTypes<typeof calendarProps>

interface DateItem {
year: number
month: number
date: number
}

export default defineComponent({
name: 'Calendar',
props: calendarProps,
Expand Down Expand Up @@ -78,6 +69,7 @@ export default defineComponent({
if (_onUpdateValue) {
call(_onUpdateValue, value, time)
}
console.log(time)
uncontrolledValueRef.value = value
}

Expand Down
7 changes: 7 additions & 0 deletions src/calendar/src/interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type OnUpdateValue = (value: number, time: DateItem) => void

export interface DateItem {
year: number
month: number
date: number
}
21 changes: 21 additions & 0 deletions src/calendar/tests/Calendar.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { h } from 'vue'
import { mount } from '@vue/test-utils'
import { NCalendar } from '../index'

describe('n-button', () => {
it('should work with import on demand', () => {
mount(NCalendar)
})
it('props.onUpdate has correct type', () => {
;<NCalendar
onUpdateValue={(
value: number,
time: {
date: number
month: number
year: number
}
) => {}}
/>
})
})

1 comment on commit 5a7b2fa

@vercel
Copy link

@vercel vercel bot commented on 5a7b2fa Jun 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.