Skip to content

Commit

Permalink
fix: 受控模式下返回的selectedOptions进行校验处理 (#2951)
Browse files Browse the repository at this point in the history
* fix: 受控模式下返回的selectedOptions进行校验处理

* fix: added the datehour judgment
  • Loading branch information
irisSong authored Jan 23, 2025
1 parent 399ceb2 commit 3300424
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/packages/datepicker/datepicker.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,18 @@ export const DatePicker: FunctionComponent<
Number(formatDate[2]),
getMonthEndDay(Number(formatDate[0]), Number(formatDate[1]))
)

if (
selectedOptions.length >= 2 &&
['date', 'datehour', 'datetime', 'month-day'].includes(rangeType)
) {
const dayOption = formatOption('day', day)
if (rangeType === 'month-day') {
selectedOptions[1] = dayOption
} else {
selectedOptions[2] = dayOption
}
}
let date: Date | null = null
if (
rangeType === 'date' ||
Expand Down
12 changes: 12 additions & 0 deletions src/packages/datepicker/datepicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,18 @@ export const DatePicker: FunctionComponent<
Number(formatDate[2]),
getMonthEndDay(Number(formatDate[0]), Number(formatDate[1]))
)

if (
selectedOptions.length >= 2 &&
['date', 'datehour', 'datetime', 'month-day'].includes(rangeType)
) {
const dayOption = formatOption('day', day)
if (rangeType === 'month-day') {
selectedOptions[1] = dayOption
} else {
selectedOptions[2] = dayOption
}
}
let date: Date | null = null
if (
rangeType === 'date' ||
Expand Down

0 comments on commit 3300424

Please sign in to comment.