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(date-picker): adds closePanelOnSelectYearclosePanelOnSelectMonth prop #5564

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
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

## NEXT_VERSION

### Features

- `n-date-picker` adds `closePanelOnSelectDate` prop.

## 2.37.3

### 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

## NEXT_VERSION

### Features

- `n-date-picker` 新增 `closePanelOnSelectDate` 属性

## 2.37.3

### Fixes
Expand Down
2 changes: 2 additions & 0 deletions src/date-picker/src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const datePickerProps = {
default: undefined
},
clearable: Boolean,
closePanelOnSelectDate: Boolean,
updateValueOnClose: Boolean,
defaultValue: [Number, Array] as PropType<Value | null>,
defaultFormattedValue: [String, Array] as PropType<FormattedValue | null>,
Expand Down Expand Up @@ -1018,6 +1019,7 @@ export default defineComponent({
defaultTime: this.defaultTime,
themeClass: this.themeClass,
panel: this.panel,
closePanelOnSelectDate: this.closePanelOnSelectDate,
onRender: this.onRender,
onNextMonth: this.onNextMonth,
onPrevMonth: this.onPrevMonth,
Expand Down
1 change: 1 addition & 0 deletions src/date-picker/src/panel/date.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default defineComponent({
mergedClsPrefix={mergedClsPrefix}
calendarMonth={this.calendarMonth}
calendarYear={this.calendarYear}
closePanelOnSelectDate={this.closePanelOnSelectDate}
/>
<div
class={`${mergedClsPrefix}-date-panel-month__next`}
Expand Down
2 changes: 2 additions & 0 deletions src/date-picker/src/panel/daterange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default defineComponent({
mergedClsPrefix={mergedClsPrefix}
calendarMonth={this.startCalendarMonth}
calendarYear={this.startCalendarYear}
closePanelOnSelectDate={this.closePanelOnSelectDate}
/>
<div
class={`${mergedClsPrefix}-date-panel-month__next`}
Expand Down Expand Up @@ -157,6 +158,7 @@ export default defineComponent({
mergedClsPrefix={mergedClsPrefix}
calendarMonth={this.endCalendarMonth}
calendarYear={this.endCalendarYear}
closePanelOnSelectDate={this.closePanelOnSelectDate}
/>
<div
class={`${mergedClsPrefix}-date-panel-month__next`}
Expand Down
1 change: 1 addition & 0 deletions src/date-picker/src/panel/datetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default defineComponent({
mergedClsPrefix={mergedClsPrefix}
calendarMonth={this.calendarMonth}
calendarYear={this.calendarYear}
closePanelOnSelectDate={this.closePanelOnSelectDate}
/>
<div
class={`${mergedClsPrefix}-date-panel-month__next`}
Expand Down
2 changes: 2 additions & 0 deletions src/date-picker/src/panel/datetimerange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export default defineComponent({
mergedClsPrefix={mergedClsPrefix}
calendarMonth={this.startCalendarMonth}
calendarYear={this.startCalendarYear}
closePanelOnSelectDate={this.closePanelOnSelectDate}
/>
<div
class={`${mergedClsPrefix}-date-panel-month__next`}
Expand Down Expand Up @@ -240,6 +241,7 @@ export default defineComponent({
mergedClsPrefix={mergedClsPrefix}
calendarMonth={this.endCalendarMonth}
calendarYear={this.endCalendarYear}
closePanelOnSelectDate={this.closePanelOnSelectDate}
/>
<div
class={`${mergedClsPrefix}-date-panel-month__next`}
Expand Down
15 changes: 13 additions & 2 deletions src/date-picker/src/panel/panelHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export default defineComponent({
type: Boolean,
required: true
},
closePanelOnSelectDate: {
type: Boolean,
required: true
pengzhen-developer marked this conversation as resolved.
Show resolved Hide resolved
},
calendarMonth: {
type: String,
required: true
Expand All @@ -35,7 +39,7 @@ export default defineComponent({
required: true
}
},
setup () {
setup (props) {
const triggerRef = ref<HTMLElement | null>(null)
const monthPanelRef = ref<InstanceType<typeof MonthPanel> | null>(null)
const showRef = ref(false)
Expand All @@ -50,12 +54,18 @@ export default defineComponent({
function handleHeaderClick (): void {
showRef.value = !showRef.value
}
function handleClosePanelOnSelectDate (): void {
if (props.closePanelOnSelectDate) {
showRef.value = false
}
}
return {
show: showRef,
triggerRef,
monthPanelRef,
handleHeaderClick,
handleClickOutside
handleClickOutside,
handleClosePanelOnSelectDate
}
},
render () {
Expand Down Expand Up @@ -103,6 +113,7 @@ export default defineComponent({
key="month"
useAsQuickJump
value={this.value}
onClick={this.handleClosePanelOnSelectDate}
/>,
[
[
Expand Down
2 changes: 2 additions & 0 deletions src/date-picker/src/panel/use-panel-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const TIME_FORMAT = 'HH:mm:ss'

const usePanelCommonProps = {
active: Boolean,
closePanelOnSelectDate: Boolean,
pengzhen-developer marked this conversation as resolved.
Show resolved Hide resolved
dateFormat: String,
timeFormat: {
type: String,
Expand All @@ -32,6 +33,7 @@ const usePanelCommonProps = {
},
shortcuts: Object as PropType<Shortcuts>,
defaultTime: [Number, String, Array] as PropType<DefaultTime>,
onClick: Function,
pengzhen-developer marked this conversation as resolved.
Show resolved Hide resolved
onClear: Function,
onConfirm: Function as PropType<(value: Value | null) => void>,
onClose: Function as PropType<OnClose>,
Expand Down