Skip to content

feat(DatePicker): add onClear disableTime range and panelActiveDate API#6316

Merged
uyarn merged 23 commits intodevelopfrom
wesley/feat/datepicker-range
Feb 4, 2026
Merged

feat(DatePicker): add onClear disableTime range and panelActiveDate API#6316
uyarn merged 23 commits intodevelopfrom
wesley/feat/datepicker-range

Conversation

@Wesley-0808
Copy link
Collaborator

@Wesley-0808 Wesley-0808 commented Jan 5, 2026

🤔 这个 PR 的性质是?

  • 日常 bug 修复
  • 新特性提交
  • 文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • CI/CD 改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他

🔗 相关 Issue

💡 需求背景和解决方案

  1. API生成有onCleardisableTime,实际未实现,对齐实现

相关PR:
onClear:

disableTime:

  1. range
  1. demo文档

📝 更新日志

  • 本条 PR 不需要纳入 Changelog

tdesign-vue-next

  • feat(DatePicker): 新增 onClear 清空按钮点击时触发事件
  • feat(DatePicker): presets 支持自定义渲染,用于配置精确时分秒等预设场景
  • feat(DatePicker): 新增 disableTime API,用于配置时间选择器中被禁用的时间
  • feat(DatePicker): 新增 rangepanelActiveDate API,用于支持定义日期选择范围,具体使用请参考示例
  • feat(DateRangePicker): 新增 rangepanelActiveDate API,用于支持定义日期选择范围,具体使用请参考示例

@tdesign-vue-next/chat

@tdesign-vue-next/auto-import-resolver

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

@tdesign-bot
Copy link
Collaborator

tdesign-bot commented Jan 5, 2026

TDesign Component Site Preview Open

Component Preview
tdesign-vue-next 完成
@tdesign-vue-next/chat 完成

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 5, 2026

  • tdesign-vue-next-demo

    npm i https://pkg.pr.new/Tencent/tdesign-vue-next/@tdesign-vue-next/auto-import-resolver@6316
    
    npm i https://pkg.pr.new/Tencent/tdesign-vue-next@6316
    
    npm i https://pkg.pr.new/Tencent/tdesign-vue-next/@tdesign-vue-next/chat@6316
    

commit: 8ab62a0

@Wesley-0808 Wesley-0808 changed the title feat: onClear and disableTime and range API docs feat(DatePicker): add onClear disableTime range API Jan 5, 2026
@Wesley-0808 Wesley-0808 added the WIP label Jan 7, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds three new API features to the DatePicker component to align with other TDesign framework implementations (tdesign-react, tdesign-vue):

Changes:

  • Added onClear event callback that triggers when the clear button is clicked
  • Added disableTime API to configure disabled time items in date-time picker mode
  • Added range API to define selectable date ranges with array or function-based configuration
  • Added panelActiveDate API to control the active year/month in the date picker panel
  • Added onPanelActiveDate event to track year/month dropdown selection changes

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
packages/components/date-picker/type.ts Added type definitions for new APIs: disableTime, range, panelActiveDate, onClear, onPanelActiveDate, and supporting types
packages/components/date-picker/props.ts Added prop definitions for the new DatePicker APIs
packages/components/date-picker/date-range-picker-props.ts Added prop definitions for DateRangePicker including range and panelActiveDate
packages/components/date-picker/hooks/useTableData.tsx Implemented range logic to compute disabled dates based on range restrictions
packages/components/date-picker/hooks/useSelectRange.ts New utility module providing range validation and pagination control functions
packages/components/date-picker/hooks/index.ts Exported new useSelectRange hook
packages/components/date-picker/components/panel/SinglePanel.tsx Pass range and disableTime props to panel components
packages/components/date-picker/components/panel/PanelContent.tsx Handle disableTime for both single and range pickers
packages/components/date-picker/components/base/Header.tsx Integrate range restrictions into year/month selection UI
packages/components/date-picker/DatePicker.tsx Implement onClear event callback
packages/components/date-picker/date-picker.md Documentation updates for new APIs (Chinese)
packages/components/date-picker/date-picker.en-US.md Documentation updates for new APIs (English)
packages/components/date-picker/_example/range.vue Example demonstrating new range and panelActiveDate APIs
packages/components/date-picker/_example/range-status.vue Example demonstrating range validation in different picker modes
Comments suppressed due to low confidence (1)

packages/components/date-picker/type.ts:448

  • The onClear event was added to TdDatePickerProps but not to TdDateRangePickerProps. Since both components have a clearable prop that allows users to clear the selected date, it would be more consistent to also add the onClear event to TdDateRangePickerProps. This would allow developers to handle clear actions uniformly across both picker types.
export interface TdDateRangePickerProps {
  /**
   * 是否允许输入日期
   * @default false
   */
  allowInput?: boolean;
  /**
   * 无边框模式
   * @default false
   */
  borderless?: boolean;
  /**
   * 默认的日期选择交互是根据点击前后日期的顺序来决定并且会加以限制。比如:用户先点击开始时间输入框,选择了一个日期例如2020-05-15,紧接着交互会自动将焦点跳到结束日期输入框,等待用户选择结束时间。此时用户只能选择大于2020-05-15的日期(之前的日期会被灰态禁止点击,限制用户的点击)。当该值传递`true`时,则取消该限制
   * @default false
   */
  cancelRangeSelectLimit?: boolean;
  /**
   * 是否显示清除按钮
   * @default false
   */
  clearable?: boolean;
  /**
   * 时间选择器默认值,当 value/defaultValue 未设置值时有效
   * @default ["00:00:00", "23:59:59"]
   */
  defaultTime?: string[];
  /**
   * 禁用日期,示例:['A', 'B'] 表示日期 A 和日期 B 会被禁用。{ from: 'A', to: 'B' } 表示在 A 到 B 之间的日期会被禁用。{ before: 'A', after: 'B' } 表示在 A 之前和在 B 之后的日期都会被禁用。其中 A = '2021-01-01',B = '2021-02-01'。值类型为 Function 则表示返回值为 true 的日期会被禁用
   */
  disableDate?: DisableRangeDate;
  /**
   * 禁用时间项的配置函数,仅在日期区间选择器中开启时间展示时可用
   */
  disableTime?: (
    times: Array<Date | null>,
    context: { partial: DateRangePickerPartial },
  ) => Partial<{ hour: Array<number>; minute: Array<number>; second: Array<number> }>;
  /**
   * 是否禁用组件
   */
  disabled?: boolean;
  /**
   * 是否显示时间选择
   * @default false
   */
  enableTimePicker?: boolean;
  /**
   * 第一天从星期几开始
   */
  firstDayOfWeek?: number;
  /**
   * 用于格式化日期,[详细文档](https://day.js.org/docs/en/display/format)
   * @default ''
   */
  format?: string;
  /**
   * 左侧文本
   */
  label?: string | TNode;
  /**
   * 选择器模式
   * @default date
   */
  mode?: 'year' | 'quarter' | 'month' | 'week' | 'date';
  /**
   * 决定在日期时间区间选择器的场景下是否需要点击确认按钮才完成选择动作,默认为 `true`
   * @default true
   */
  needConfirm?: boolean;
  /**
   * 日期选择器中年月下拉框的选中值
   */
  panelActiveDate?: PanelActiveDate | [PanelActiveDate, PanelActiveDate];
  /**
   * 日期选择器中年月下拉框的选中值,非受控属性
   */
  defaultPanelActiveDate?: PanelActiveDate | [PanelActiveDate, PanelActiveDate];
  /**
   * 在开始日期选中之前,面板是否显示预选状态,即是否高亮预选日期
   * @default true
   */
  panelPreselection?: boolean;
  /**
   * 占位符,值为数组表示可分别为开始日期和结束日期设置占位符
   */
  placeholder?: string | Array<string>;
  /**
   * 透传 Popup 组件全部属性
   */
  popupProps?: PopupProps;
  /**
   * 组件前置图标
   */
  prefixIcon?: TNode;
  /**
   * 预设快捷日期选择,示例:{ '特定日期范围': ['2021-01-01', '2022-01-01'], '本月': [dayjs().startOf('month'), dayjs().endOf('month')] }
   */
  presets?: PresetRange;
  /**
   * 预设面板展示区域(包含确定按钮)
   * @default bottom
   */
  presetsPlacement?: 'left' | 'top' | 'right' | 'bottom';
  /**
   * 日期可选择范围。值为数组则第一项是开始面板的可选范围,第二项是结束面板的可选范围。示例:['2025-01-01', '2025-12-31'] 表示'2025-01-01'至'2025-12-31'为可选日期。值为`null`表示不限制,例如['2025-01-01', null]表示可选日期从'2025-01-01'开始,不限制结束。值类型为 Function 则表示返回值为 true 的日期为可选。 与`disableDate`共用时,`disableDate`优先级更高。
   */
  range?: PickerDateRange | PickerDateRange[];
  /**
   * 透传给范围输入框 RangeInput 组件的参数
   */
  rangeInputProps?: RangeInputProps;
  /**
   * 是否只读,优先级大于 `allowInput`
   */
  readonly?: boolean;
  /**
   * 日期分隔符,支持全局配置,默认为 '-'
   * @default ''
   */
  separator?: string;
  /**
   * 输入框尺寸
   * @default medium
   */
  size?: SizeEnum;
  /**
   * 输入框状态
   * @default default
   */
  status?: 'default' | 'success' | 'warning' | 'error';
  /**
   * 组件后置图标
   */
  suffixIcon?: TNode;
  /**
   * 透传 TimePicker 组件属性
   */
  timePickerProps?: TimePickerProps;
  /**
   * 输入框下方提示文本,会根据不同的 `status` 呈现不同的样式
   */
  tips?: string | TNode;
  /**
   * 选中值
   * @default []
   */
  value?: DateRangeValue;
  /**
   * 选中值,非受控属性
   * @default []
   */
  defaultValue?: DateRangeValue;
  /**
   * 选中值
   * @default []
   */
  modelValue?: DateRangeValue;
  /**
   * 用于格式化日期的值,仅支持部分格式,时间戳、日期等。⚠️ `YYYYMMDD` 这种格式不支持,请勿使用,如果希望支持可以给 `dayjs` 提个 PR。注意和 `format` 的区别,`format` 仅用于处理日期在页面中呈现的格式
   */
  valueType?:
    | 'time-stamp'
    | 'Date'
    | 'YYYY'
    | 'YYYY-MM'
    | 'YYYY-MM-DD'
    | 'YYYY-MM-DD HH'
    | 'YYYY-MM-DD HH:mm'
    | 'YYYY-MM-DD HH:mm:ss'
    | 'YYYY-MM-DD HH:mm:ss:SSS';
  /**
   * 当输入框失去焦点时触发
   */
  onBlur?: (context: { value: DateRangeValue; partial: DateRangePickerPartial; e: FocusEvent }) => void;
  /**
   * 选中值发生变化时触发
   */
  onChange?: (value: DateRangeValue, context: { dayjsValue?: Dayjs[]; trigger?: DatePickerTriggerSource }) => void;
  /**
   * 如果存在“确定”按钮,则点击“确定”按钮时触发
   */
  onConfirm?: (context: { date: Date[]; e: MouseEvent; partial: DateRangePickerPartial }) => void;
  /**
   * 输入框获得焦点时触发
   */
  onFocus?: (context: { value: DateRangeValue; partial: DateRangePickerPartial; e: FocusEvent }) => void;
  /**
   * 输入框数据发生变化时触发,参数 input 表示输入内容,value 表示组件当前有效值
   */
  onInput?: (context: { input: string; value: DateRangeValue; partial: DateRangePickerPartial; e: InputEvent }) => void;
  /**
   * 月份切换发生变化时触发
   */
  onMonthChange?: (context: {
    month: number;
    date: Date[];
    partial: DateRangePickerPartial;
    e?: MouseEvent;
    trigger: DatePickerMonthChangeTrigger;
  }) => void;
  /**
   * 年月下拉框选中值变化时触发
   */
  onPanelActiveDate?: (
    value: number | Date,
    context: { partial: DateRangePickerPartial; trigger: DatePickerPanelActiveDate; e?: MouseEvent },
  ) => void;
  /**
   * 选中日期时触发,可能是开始日期,也可能是结束日期,第二个参数可以区分是开始日期或是结束日期
   */
  onPick?: (value: DateValue, context: PickContext) => void;
  /**
   * 点击预设按钮后触发
   */
  onPresetClick?: (context: { preset: PresetDate; e: MouseEvent }) => void;
  /**
   * 年份切换发生变化时触发
   */
  onYearChange?: (context: {
    year: number;
    date: Date[];
    partial: DateRangePickerPartial;
    trigger: DatePickerYearChangeTrigger;
    e?: MouseEvent;
  }) => void;
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@uyarn uyarn marked this pull request as ready for review January 30, 2026 08:13
@uyarn uyarn removed the WIP label Feb 2, 2026
@uyarn uyarn changed the title feat(DatePicker): add onClear disableTime range API feat(DatePicker): add onClear disableTime range and panelActiveDate API Feb 3, 2026
@Wesley-0808
Copy link
Collaborator Author

/update-common

@Wesley-0808 Wesley-0808 requested a review from Copilot February 4, 2026 05:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@uyarn uyarn merged commit 54429a7 into develop Feb 4, 2026
1 check passed
@uyarn uyarn deleted the wesley/feat/datepicker-range branch February 4, 2026 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants