Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: n-date-picker adds close-panel-on-select-dateclose-panel-on-select-yearclose-panel-on-select-month props. #6741

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## NEXT_VERSION

### Feats

- `n-date-picker` adds `close-panel-on-select-date` prop.
- `n-date-picker` adds `close-panel-on-select-year` prop.
- `n-date-picker` adds `close-panel-on-select-month` prop.

## 2.41.0

`2025-01-05`
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## NEXT_VERSION

### Feats

- `n-date-picker` 新增 `close-panel-on-select-date` 参数
- `n-date-picker` 新增 `close-panel-on-select-year` 参数
- `n-date-picker` 新增 `close-panel-on-select-month` 参数

## 2.41.0

`2025-01-05`
Expand Down
80 changes: 80 additions & 0 deletions src/date-picker/demos/enUS/close-panel-on-select.demo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<markdown>
# Close panel after selecting year or month.
</markdown>

<script lang="ts">
import { defineComponent, ref } from 'vue'

export default defineComponent({
setup() {
return {
timestamp: ref(1183135260000),
range: ref<[number, number]>([1183135260000, Date.now()])
}
}
})
</script>

<template>
<NSpace vertical>
<div>
<div>Close panel after selecting year.</div>
<n-date-picker
v-model:value="timestamp"
type="date"
close-panel-on-select-year
/>
<n-date-picker
v-model:value="range"
type="daterange"
close-panel-on-select-year
/>
<n-date-picker
v-model:value="range"
type="datetimerange"
close-panel-on-select-year
/>
<pre>{{ JSON.stringify(timestamp) }}</pre>
</div>

<div>
<div>Close panel after selecting month.</div>
<n-date-picker
v-model:value="timestamp"
type="date"
close-panel-on-select-month
/>
<n-date-picker
v-model:value="range"
type="daterange"
close-panel-on-select-month
/>
<n-date-picker
v-model:value="range"
type="datetimerange"
close-panel-on-select-month
/>
<pre>{{ JSON.stringify(timestamp) }}</pre>
</div>

<div>
<div>Close panel after selecting year or month.</div>
<n-date-picker
v-model:value="timestamp"
type="date"
close-panel-on-select-date
/>
<n-date-picker
v-model:value="range"
type="daterange"
close-panel-on-select-date
/>
<n-date-picker
v-model:value="range"
type="datetimerange"
close-panel-on-select-date
/>
<pre>{{ JSON.stringify(timestamp) }}</pre>
</div>
</NSpace>
</template>
13 changes: 13 additions & 0 deletions src/date-picker/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ focus.vue
status.vue
icon.vue
panel.vue
close-panel-on-select.vue
```

## API
Expand Down Expand Up @@ -85,6 +86,9 @@ panel.vue
| format | `string` | `'yyyy-MM-dd'` | Format of the input. For detail please see [format](https://date-fns.org/v2.23.0/docs/format). | |
| is-date-disabled | `(current: number, detail: { type: 'date', year: number, month: number, date: number } \| { type: 'month', year: number, month: number } \| { type: 'year', year: number } \| { type: 'quarter', year: number, quarter: number } \| { type: 'input' }) => boolean` | `() => false` | Validator of the date. | `detail` 2.37.1 |
| placeholder | `string` | `'Select Date'` | Placeholder. | |
| close-panel-on-select-date | `boolean` | `undefined` | Close year and month panel after selecting year or month. | NEXT_VERSION |
| close-panel-on-select-year | `boolean` | `undefined` | Close year and month panel after selecting year. | NEXT_VERSION |
| close-panel-on-select-month | `boolean` | `undefined` | Close year and month panel after selecting month. | NEXT_VERSION |
| on-update:formatted-value | `(value: string \| null, timestampValue: number \| null) => void` | `undefined` | Date selected callback. | 2.24.0 |
| on-update:value | `(value: number \| null, formattedValue: string \| null) => void` | `undefined` | Date selected callback. | `formattedValue` 2.24.0 |

Expand All @@ -99,6 +103,9 @@ panel.vue
| is-date-disabled | `(current: number, detail: { type: 'date', year: number, month: number, date: number } \| { type: 'month', year: number, month: number } \| { type: 'year', year: number } \| { type: 'quarter', year: number, quarter: number } \| { type: 'input' }) => boolean` | `() => false` | Validator of the date. | `detail` 2.37.1 |
| is-time-disabled | `(current: number) => { isHourDisabled?: () => boolean, isMinuteDisabled?: () => boolean, isSecondDisabled?: () => boolean }` | `undefined` | Validator of the time. | |
| placeholder | `string` | `'Select Date and Time'` | Placeholder. | |
| close-panel-on-select-date | `boolean` | `undefined` | Close year and month panel after selecting year or month. | NEXT_VERSION |
| close-panel-on-select-year | `boolean` | `undefined` | Close year and month panel after selecting year. | NEXT_VERSION |
| close-panel-on-select-month | `boolean` | `undefined` | Close year and month panel after selecting month. | NEXT_VERSION |
| time-picker-props | `TimePickerProps` | `undefined` | Time picker props in the panel. | 2.27.0 |
| update-value-on-close | `boolean` | `false` | Whether to update value on close. | |
| on-update:formatted-value | `(value: string \| null, timestampValue: number \| null) => void` | `undefined` | Date selected callback. | MEXT_VERSION |
Expand All @@ -114,6 +121,9 @@ panel.vue
| default-calendar-end-time | `number` | `undefined` | Default panel calendar end month timestamp. | 2.28.3 |
| end-placeholder | `string` | `'End Date'` | Placeholder at end part of the input. | |
| format | `string` | `'yyyy-MM-dd'` | Format of the input. For detail please see [format](https://date-fns.org/v2.23.0/docs/format). | |
| close-panel-on-select-date | `boolean` | `undefined` | Close year and month panel after selecting year or month. | NEXT_VERSION |
| close-panel-on-select-year | `boolean` | `undefined` | Close year and month panel after selecting year. | NEXT_VERSION |
| close-panel-on-select-month | `boolean` | `undefined` | Close year and month panel after selecting month. | NEXT_VERSION |
| is-date-disabled | `(current: number, phase: 'start' \| 'end', value: [number, number] \| null) => boolean` | `undefined` | Validator of the date. | `detail` 2.37.1 |
| is-time-disabled | `(current: number, phase: 'start' \| 'end', value: [number, number]) => { isHourDisabled?: (hour: number) => boolean, isMinuteDisabled?: (minute: number, hour: number \| null) => boolean, isSecondDisabled?: (second: number, minute: number \| null, hour: number \| null) => boolean }` | `undefined` | Validator of the time. `null` in validators means value of picker is empty. | |
| close-on-select | `boolean` | `false` | Whether to close the panel after the user has selected a time range. | |
Expand All @@ -134,6 +144,9 @@ panel.vue
| default-time | `string \| Array<string \| undefined>` | `undefined` | Default time of the selected date. It's format is `HH:mm:ss`. | 2.22.0 |
| end-placeholder | `string` | `'End Date and Time'` | Placeholder at end part of the input. | |
| format | `string` | `'yyyy-MM-dd HH:mm:ss'` | Format of the input. For detail please see [format](https://date-fns.org/v2.23.0/docs/format). | |
| close-panel-on-select-date | `boolean` | `undefined` | Close year and month panel after selecting year or month. | NEXT_VERSION |
| close-panel-on-select-year | `boolean` | `undefined` | Close year and month panel after selecting year. | NEXT_VERSION |
| close-panel-on-select-month | `boolean` | `undefined` | Close year and month panel after selecting month. | NEXT_VERSION |
| is-date-disabled | `(current: number, phase: 'start' \| 'end', value: [number, number] \| null) => boolean` | `undefined` | Validator of the date. | |
| is-time-disabled | `(current: number, phase: 'start' \| 'end', value: [number, number]) => { isHourDisabled?: (hour: number) => boolean, isMinuteDisabled?: (minute: number, hour: number \| null) => boolean, isSecondDisabled?: (second: number, minute: number \| null, hour: number \| null) => boolean }` | `undefined` | Validator of the time. `null` in validators means value of picker is empty. | |
| separator | `string` | internal icon | The separator between the start input and the end input. | |
Expand Down
95 changes: 95 additions & 0 deletions src/date-picker/demos/zhCN/close-panel-on-select.demo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<markdown>
# 当选择年、月后,关闭年月面板
</markdown>

<script lang="ts">
import { defineComponent, ref } from 'vue'

export default defineComponent({
setup() {
return {
timestamp: ref(1183135260000),
range: ref<[number, number]>([1183135260000, Date.now()])
}
}
})
</script>

<template>
<NSpace vertical>
<div>
<div>选择年份后,关闭面板</div>
<n-date-picker
v-model:value="timestamp"
type="date"
close-panel-on-select-year
/>
<n-date-picker
v-model:value="timestamp"
type="datetime"
close-panel-on-select-year
/>
<n-date-picker
v-model:value="range"
type="daterange"
close-panel-on-select-year
/>
<n-date-picker
v-model:value="range"
type="datetimerange"
close-panel-on-select-year
/>
<pre>{{ JSON.stringify(timestamp) }}</pre>
</div>

<div>
<div>选择月份后,关闭面板</div>
<n-date-picker
v-model:value="timestamp"
type="date"
close-panel-on-select-month
/>
<n-date-picker
v-model:value="timestamp"
type="datetime"
close-panel-on-select-month
/>
<n-date-picker
v-model:value="range"
type="daterange"
close-panel-on-select-month
/>
<n-date-picker
v-model:value="range"
type="datetimerange"
close-panel-on-select-month
/>
<pre>{{ JSON.stringify(timestamp) }}</pre>
</div>

<div>
<div>选择年份或月份后,关闭面板</div>
<n-date-picker
v-model:value="timestamp"
type="date"
close-panel-on-select-date
/>
<n-date-picker
v-model:value="timestamp"
type="datetime"
close-panel-on-select-date
/>
<n-date-picker
v-model:value="range"
type="daterange"
close-panel-on-select-date
/>
<n-date-picker
v-model:value="range"
type="datetimerange"
close-panel-on-select-date
/>
<pre>{{ JSON.stringify(timestamp) }}</pre>
</div>
</NSpace>
</template>
13 changes: 13 additions & 0 deletions src/date-picker/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ footerslot.vue
status.vue
icon.vue
panel.vue
close-panel-on-select.vue
panel-debug.vue
form-debug.vue
```
Expand Down Expand Up @@ -86,6 +87,9 @@ form-debug.vue
| format | `string` | `'yyyy-MM-dd'` | 时间格式化字符串,详情见 [format](https://date-fns.org/v2.23.0/docs/format) | |
| is-date-disabled | `(current: number, detail: { type: 'date', year: number, month: number, date: number } \| { type: 'month', year: number, month: number } \| { type: 'year', year: number } \| { type: 'quarter', year: number, quarter: number } \| { type: 'input' }) => boolean` | `undefined` | 日期禁用的校验函数 | `detail` 2.37.1 |
| placeholder | `string` | `'选择日期'` | 没有值时的占位信息 | |
| close-panel-on-select-date | `boolean` | `undefined` | 为 `true` 时,选择年、月后,关闭年月面板 | NEXT_VERSION |
| close-panel-on-select-year | `boolean` | `undefined` | 为 `true` 时,选择年份后,关闭年月面板 | NEXT_VERSION |
| close-panel-on-select-month | `boolean` | `undefined` | 为 `true` 时,选择月份后,关闭年月面板 | NEXT_VERSION |
| on-update:formatted-value | `(value: string \| null, timestampValue: number \| null) => void` | `undefined` | 受控数据更新时触发的回调函数 | 2.24.0 |
| on-update:value | `(value: number \| null, formattedValue: string \| null) => void` | `undefined` | 受控数据更新时触发的回调函数 | `formattedValue` 2.24.0 |

Expand All @@ -100,6 +104,9 @@ form-debug.vue
| is-date-disabled | `(current: number, detail: { type: 'date', year: number, month: number, date: number } \| { type: 'month', year: number, month: number } \| { type: 'year', year: number } \| { type: 'quarter', year: number, quarter: number } \| { type: 'input' }) => boolean` | `undefined` | 日期禁用的校验函数 | `detail` 2.37.1 |
| is-time-disabled | `(current: number) => { isHourDisabled: boolean, isMinuteDisabled: boolean, isSecondDisabled: boolean }` | `undefined` | 时间禁用的校验函数 | |
| placeholder | `string` | `'选择日期时间'` | 提示信息 | |
| close-panel-on-select-date | `boolean` | `undefined` | 为 `true` 时,选择年、月后,关闭年月面板 | NEXT_VERSION |
| close-panel-on-select-year | `boolean` | `undefined` | 为 `true` 时,选择年份后,关闭年月面板 | NEXT_VERSION |
| close-panel-on-select-month | `boolean` | `undefined` | 为 `true` 时,选择月份后,关闭年月面板 | NEXT_VERSION |
| time-picker-props | `TimePickerProps` | `undefined` | 面板中时间选择器的属性 | 2.27.0 |
| update-value-on-close | `boolean` | `false` | 关闭面板时更新值 | |
| on-update:formatted-value | `(value: string \| null, timestampValue: number \| null) => void` | `undefined` | 数据更新时触发的回调函数 | 2.24.0 |
Expand All @@ -114,6 +121,9 @@ form-debug.vue
| default-calendar-start-time | `number` | `undefined` | 面板日历默认开始的月份时间戳 | 2.28.3 |
| default-calendar-end-time | `number` | `undefined` | 面板日历默认结束的月份时间戳 | 2.28.3 |
| format | `string` | `'yyyy-MM-dd'` | 时间格式化字符串,详情见 [format](https://date-fns.org/v2.23.0/docs/format) | |
| close-panel-on-select-date | `boolean` | `undefined` | 为 `true` 时,选择年、月后,关闭年月面板 | NEXT_VERSION |
| close-panel-on-select-year | `boolean` | `undefined` | 为 `true` 时,选择年份后,关闭年月面板 | NEXT_VERSION |
| close-panel-on-select-month | `boolean` | `undefined` | 为 `true` 时,选择月份后,关闭年月面板 | NEXT_VERSION |
| is-date-disabled | `(current: number, phase: 'start' \| 'end', value: [number, number] \| null) => boolean` | `undefined` | 日期禁用的校验函数 | |
| is-time-disabled | `(current: number, phase: 'start' \| 'end', value: [number, number]) => { isHourDisabled?: (hour: number) => boolean, isMinuteDisabled?: (minute: number, hour: number \| null) => boolean, isSecondDisabled?: (second: number, minute: number \| null, hour: number \| null) => boolean }` | `undefined` | 时间禁用的校验函数,校验函数中的 `null` 表示当前没有选中值 | |
| close-on-select | `boolean` | `false` | 用户选择时间范围后是否自动关闭面板 | |
Expand All @@ -134,6 +144,9 @@ form-debug.vue
| default-time | `string \| Array<string \| undefined>` | `undefined` | 默认时间,格式为 `HH:mm:ss` | 2.22.0 |
| end-placeholder | `string` | `'结束日期时间'` | DateTimeRange 中 end 选框的提示信息 | |
| format | `string` | `'yyyy-MM-dd HH:mm:ss'` | 时间格式化字符串,详情见 [format](https://date-fns.org/v2.23.0/docs/format) | |
| close-panel-on-select-date | `boolean` | `undefined` | 为 `true` 时,选择年、月后,关闭年月面板 | NEXT_VERSION |
| close-panel-on-select-year | `boolean` | `undefined` | 为 `true` 时,选择年份后,关闭年月面板 | NEXT_VERSION |
| close-panel-on-select-month | `boolean` | `undefined` | 为 `true` 时,选择月份后,关闭年月面板 | NEXT_VERSION |
| is-date-disabled | `(current: number, phase: 'start' \| 'end', value: [number, number] \| null) => boolean` | `undefined` | 日期禁用的校验函数 | |
| is-time-disabled | `(current: number, phase: 'start' \| 'end', value: [number, number]) => { isHourDisabled?: (hour: number) => boolean, isMinuteDisabled?: (minute: number, hour: number \| null) => boolean, isSecondDisabled?: (second: number, minute: number \| null, hour: number \| null) => boolean }` | `undefined` | 时间禁用的校验函数,校验函数中的 `null` 表示当前没有选中值 | |
| separator | `string` | 内置图标 | start 选框与 end 选框之间的分隔符 | |
Expand Down
3 changes: 3 additions & 0 deletions src/date-picker/src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,9 @@ export default defineComponent({
onPrevYear: this.onPrevYear,
timerPickerFormat: this.timerPickerFormat,
dateFormat: this.dateFormat,
closePanelOnSelectDate: this.closePanelOnSelectDate,
closePanelOnSelectYear: this.closePanelOnSelectYear,
closePanelOnSelectMonth: this.closePanelOnSelectMonth,
calendarDayFormat: this.calendarDayFormat,
calendarHeaderYearFormat: this.calendarHeaderYearFormat,
calendarHeaderMonthFormat: this.calendarHeaderMonthFormat,
Expand Down
3 changes: 3 additions & 0 deletions src/date-picker/src/panel/date.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ export default defineComponent({
])}
</div>
<PanelHeader
closePanelOnSelectDate={this.closePanelOnSelectDate}
closePanelOnSelectYear={this.closePanelOnSelectYear}
closePanelOnSelectMonth={this.closePanelOnSelectMonth}
monthYearSeparator={this.calendarHeaderMonthYearSeparator}
monthBeforeYear={this.calendarMonthBeforeYear}
value={this.calendarValue}
Expand Down
6 changes: 6 additions & 0 deletions src/date-picker/src/panel/daterange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export default defineComponent({
])}
</div>
<PanelHeader
closePanelOnSelectDate={this.closePanelOnSelectDate}
closePanelOnSelectYear={this.closePanelOnSelectYear}
closePanelOnSelectMonth={this.closePanelOnSelectMonth}
monthYearSeparator={this.calendarHeaderMonthYearSeparator}
monthBeforeYear={this.calendarMonthBeforeYear}
value={this.startCalendarDateTime}
Expand Down Expand Up @@ -179,6 +182,9 @@ export default defineComponent({
])}
</div>
<PanelHeader
closePanelOnSelectDate={this.closePanelOnSelectDate}
closePanelOnSelectYear={this.closePanelOnSelectYear}
closePanelOnSelectMonth={this.closePanelOnSelectMonth}
monthYearSeparator={this.calendarHeaderMonthYearSeparator}
monthBeforeYear={this.calendarMonthBeforeYear}
value={this.endCalendarDateTime}
Expand Down
3 changes: 3 additions & 0 deletions src/date-picker/src/panel/datetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ export default defineComponent({
])}
</div>
<PanelHeader
closePanelOnSelectDate={this.closePanelOnSelectDate}
closePanelOnSelectYear={this.closePanelOnSelectYear}
closePanelOnSelectMonth={this.closePanelOnSelectMonth}
monthYearSeparator={this.calendarHeaderMonthYearSeparator}
monthBeforeYear={this.calendarMonthBeforeYear}
value={this.calendarValue}
Expand Down
6 changes: 6 additions & 0 deletions src/date-picker/src/panel/datetimerange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ export default defineComponent({
])}
</div>
<PanelHeader
closePanelOnSelectDate={this.closePanelOnSelectDate}
closePanelOnSelectYear={this.closePanelOnSelectYear}
closePanelOnSelectMonth={this.closePanelOnSelectMonth}
monthYearSeparator={this.calendarHeaderMonthYearSeparator}
monthBeforeYear={this.calendarMonthBeforeYear}
value={this.startCalendarDateTime}
Expand Down Expand Up @@ -258,6 +261,9 @@ export default defineComponent({
])}
</div>
<PanelHeader
closePanelOnSelectDate={this.closePanelOnSelectDate}
closePanelOnSelectYear={this.closePanelOnSelectYear}
closePanelOnSelectMonth={this.closePanelOnSelectMonth}
monthBeforeYear={this.calendarMonthBeforeYear}
value={this.endCalendarDateTime}
onUpdateValue={this.onUpdateEndCalendarValue}
Expand Down
7 changes: 7 additions & 0 deletions src/date-picker/src/panel/month.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ export default defineComponent({
&& `${mergedClsPrefix}-date-panel-month-calendar__picker-col-item--disabled`
]}
onClick={() => {
if (item.type === 'year') {
props.onSelectYear?.()
}
else if (item.type === 'month') {
props.onSelectMonth?.()
}

if (useAsQuickJump) {
handleQuickMonthClick(item, (value) => {
;(props.onUpdateValue as OnPanelUpdateValueImpl)(value, false)
Expand Down
Loading