From 9a25a4fd88bfeee192aa0a26373e87e076ec0b46 Mon Sep 17 00:00:00 2001 From: Eiinu Date: Wed, 13 Mar 2024 16:27:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(calendarcard):=20=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E8=8C=83=E5=9B=B4=E6=97=B6=E6=94=AF=E6=8C=81=E4=BB=85=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=8D=95=E4=B8=AA=E6=97=A5=E6=9C=9F=20(#2009)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(calendarcard): 选择范围时支持仅选择单个日期 * test(calendarcard): update --- .../__tests__/calendarcard.spec.tsx | 7 ++++- src/packages/calendarcard/calendarcard.scss | 28 ++++++++++--------- .../calendarcard/calendarcard.taro.tsx | 2 +- src/packages/calendarcard/calendarcard.tsx | 2 +- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/packages/calendarcard/__tests__/calendarcard.spec.tsx b/src/packages/calendarcard/__tests__/calendarcard.spec.tsx index 48cc4fccb9..a78b57fc7e 100644 --- a/src/packages/calendarcard/__tests__/calendarcard.spec.tsx +++ b/src/packages/calendarcard/__tests__/calendarcard.spec.tsx @@ -91,7 +91,12 @@ test('test type range', async () => { const currentDays = container.querySelectorAll( '.nut-calendarcard-day.current' ) - fireEvent.click(currentDays[1]) // 0102 + fireEvent.click(currentDays[24]) // 0125 + const startAndEnd = container.querySelectorAll( + '.nut-calendarcard-day.start.end' + ) + expect(startAndEnd.length).toBe(1) + fireEvent.click(currentDays[3]) // 0104 fireEvent.click(currentDays[8]) // 0109 const start = container.querySelector( diff --git a/src/packages/calendarcard/calendarcard.scss b/src/packages/calendarcard/calendarcard.scss index 7b209bb632..a6760f5177 100644 --- a/src/packages/calendarcard/calendarcard.scss +++ b/src/packages/calendarcard/calendarcard.scss @@ -61,22 +61,28 @@ line-height: 12px; } - &.active, + &.weekend { + color: $calendar-choose-color; + } + + &.active { + background-color: $calendar-active-background-color; + color: $color-primary-text; + border-radius: $calendar-day-active-border-radius; + } + &.start, &.end { background-color: $calendar-active-background-color; - color: $color-primary-text !important; - border-radius: $calendar-day-active-border-radius; + color: $color-primary-text; } &.start { - border-radius: 0px; border-top-left-radius: $calendar-day-active-border-radius; border-bottom-left-radius: $calendar-day-active-border-radius; } &.end { - border-radius: 0px; border-top-right-radius: $calendar-day-active-border-radius; border-bottom-right-radius: $calendar-day-active-border-radius; } @@ -86,10 +92,6 @@ color: $calendar-choose-color; } - &.weekend { - color: $calendar-choose-color; - } - .nut-calendar-day-info { color: $color-primary-text; } @@ -127,17 +129,17 @@ } } &-day { + &.start, + &.end { + border-radius: 0; + } &.start { - border-top-left-radius: 0; border-top-right-radius: $calendar-day-active-border-radius; - border-bottom-left-radius: 0; border-bottom-right-radius: $calendar-day-active-border-radius; } &.end { - border-top-right-radius: 0; border-top-left-radius: $calendar-day-active-border-radius; - border-bottom-right-radius: 0; border-bottom-left-radius: $calendar-day-active-border-radius; } } diff --git a/src/packages/calendarcard/calendarcard.taro.tsx b/src/packages/calendarcard/calendarcard.taro.tsx index 2a552e3515..cbfe00697d 100644 --- a/src/packages/calendarcard/calendarcard.taro.tsx +++ b/src/packages/calendarcard/calendarcard.taro.tsx @@ -353,7 +353,7 @@ export const CalendarCard = React.forwardRef< change([day]) } else if (len === 1) { const t = compareDay(innerValue[0], day) - if (t === 0 || t === null || t === undefined) { + if (t === null || t === undefined) { change([]) } else if (t < 0) { change([innerValue[0], day]) diff --git a/src/packages/calendarcard/calendarcard.tsx b/src/packages/calendarcard/calendarcard.tsx index 456f244365..ab0b10888a 100644 --- a/src/packages/calendarcard/calendarcard.tsx +++ b/src/packages/calendarcard/calendarcard.tsx @@ -353,7 +353,7 @@ export const CalendarCard = React.forwardRef< change([day]) } else if (len === 1) { const t = compareDay(innerValue[0], day) - if (t === 0 || t === null || t === undefined) { + if (t === null || t === undefined) { change([]) } else if (t < 0) { change([innerValue[0], day])