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(CalendarPickerView): title support boolean value to control whether to hide #6676

Merged
merged 7 commits into from
Jul 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Only the simplest content area is shown here, and other more usages can be consu
| renderBottom | The bottom information of date render function. | `(date: Date) => ReactNode \| null \| undefined` | - |
| selectionMode | The selection mode. Disable selection when this prop is not set. | `'single' \| 'range'` | - |
| shouldDisableDate | Set whether the date is disable selection. The min and max Settings are ignored | `(date: Date) => boolean` | - |
| title | The title of calendar | `React.ReactNode` | `Date selection` |
| title | The title of calendar | `React.ReactNode \| false` | `Date selection` |
| value | The selected date or date range. | `Date \| null` when selection mode is "single". `[Date, Date] \| null` when selection mode is "range" | - |
| weekStartsOn | Week starts on which day. | `'Monday' \| 'Sunday'` | `'Sunday'` |
| renderDate | Custom date rendering. | `(date: Date) => ReactNode` | - | 5.28.0 |
Expand Down
6 changes: 4 additions & 2 deletions src/components/calendar-picker-view/calendar-picker-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type CalendarPickerViewRef = {
}

export type CalendarPickerViewProps = {
title?: React.ReactNode
title?: React.ReactNode | false
confirmText?: string
weekStartsOn?: 'Monday' | 'Sunday'
renderTop?: (date: Date) => React.ReactNode
Expand Down Expand Up @@ -117,6 +117,8 @@ export const CalendarPickerView = forwardRef<
dayjs(dateRange ? dateRange[0] : today).date(1)
)

const showHeader = props.title !== false

// =============================== Scroll ===============================
const context = useContext(Context)
const scrollTo = useSyncScroll(current, context.visible, bodyRef)
Expand Down Expand Up @@ -356,7 +358,7 @@ export const CalendarPickerView = forwardRef<
return withNativeProps(
props,
<div className={classPrefix}>
{header}
{showHeader && header}
{mark}
{body}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CalendarPickerView 是 [CalendarPicker](/zh/components/calendar-picker) 的内
| renderBottom | 日期底部信息的渲染函数 | `(date: Date) => ReactNode \| null \| undefined` | - |
| selectionMode | 选择模式,不设置的话表示不支持选择 | `'single' \| 'range'` | - |
| shouldDisableDate | 判断日期是否可选,使用后会忽略 min 和 max 设置 | `(date: Date) => boolean` | - |
| title | 日期选择器的标题 | `React.ReactNode` | `日期选择` |
| title | 日期选择器的标题 | `React.ReactNode \| false` | `日期选择` |
| value | 选择的日期 | 单选模式下为 `Date \| null`,多选模式下为 `[Date, Date] \| null` | - |
| weekStartsOn | 每周以周几作为第一天 | `'Monday' \| 'Sunday'` | `'Sunday'` |
| renderDate | 自定义日期渲染 | `(date: Date) => ReactNode` | - | 5.28.0 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ describe('Calendar', () => {
expect(document.getElementsByClassName('custom-cell').length).toBe(31)
})

test('title hidden', () => {
render(<CalendarPickerView title={false} />)

expect(document.querySelector(`.${classPrefix}-header`)).toBeNull()
})

test('not fill empty cells if unnecessary', () => {
const { container } = render(
<CalendarPickerView
Expand Down
Loading