Skip to content

Commit

Permalink
fix: 受控模式下返回的selectedOptions进行校验处理
Browse files Browse the repository at this point in the history
  • Loading branch information
irisSong committed Jan 15, 2025
1 parent 2571c8d commit 1800f12
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/packages/datepicker/datepicker.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,20 @@ export const DatePicker: FunctionComponent<
Number(formatDate[2]),
getMonthEndDay(Number(formatDate[0]), Number(formatDate[1]))
)

if (
selectedOptions.length >= 2 &&
(rangeType === 'date' ||
rangeType === 'month-day' ||
rangeType === 'datetime')
) {
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
14 changes: 14 additions & 0 deletions src/packages/datepicker/datepicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,20 @@ export const DatePicker: FunctionComponent<
Number(formatDate[2]),
getMonthEndDay(Number(formatDate[0]), Number(formatDate[1]))
)

if (
selectedOptions.length >= 2 &&
(rangeType === 'date' ||
rangeType === 'month-day' ||
rangeType === 'datetime')
) {
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 1800f12

Please sign in to comment.