-
Notifications
You must be signed in to change notification settings - Fork 599
feat(DatePicker): add onClear disableTime range and panelActiveDate API
#6316
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
Merged
+826
−166
Merged
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2b2ef40
feat: onClear and disableTime and range API docs
Wesley-0808 333e14a
fix: lint
Wesley-0808 0d45e53
feat: range
Wesley-0808 c131092
chore: update demo
Wesley-0808 9906c40
Merge branch 'develop' of github.com:Tencent/tdesign-vue-next into we…
uyarn 9fdca7e
Merge branch 'develop' of github.com:Tencent/tdesign-vue-next into we…
uyarn d1c635f
chore: resolve conflict
uyarn 1d8459c
chore: revert change
uyarn b62a5be
chore: revert api
Wesley-0808 ef6e3ad
chore: api desc
Wesley-0808 1e30756
chore: panelActiveDate get affect
uyarn 428acb0
fix: range picker
Wesley-0808 a264d01
chore: update common
Wesley-0808 7c384f6
feat: demo
Wesley-0808 8063594
chore: rangePicker panelActiveDate get affect
Wesley-0808 ac636ee
chore: remove unused demo
Wesley-0808 3535fcc
feat: presets support jsx
uyarn 797b7e6
chore: revert props change
uyarn 45ecbff
chore: complete
uyarn 3f15d21
chore: demo order
uyarn 8d4bd08
chore: update common
github-actions[bot] 8ab62a0
Update packages/components/date-picker/date-picker.md
uyarn c1a1d96
chore: stash changelog [ci skip]
tdesign-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| <template> | ||
| <t-space direction="vertical" :size="24"> | ||
| <div> | ||
| <div>week 模式:range = ['2025-03-15','2025-12-01'],默认值 2025-02-20(越界,应为错误态)</div> | ||
| <t-date-picker | ||
| v-model="weekVal" | ||
| mode="week" | ||
| allow-input | ||
| :first-day-of-week="firstDayOfWeek" | ||
| :range="periodRange" | ||
| clearable | ||
| placeholder="选择一周" | ||
| /> | ||
| </div> | ||
|
|
||
| <div> | ||
| <div>month 模式:range = ['2025-03-15','2025-12-01'],默认值 2025-02(越界,应为错误态)</div> | ||
| <t-date-picker | ||
| v-model="monthVal" | ||
| mode="month" | ||
| allow-input | ||
| :range="periodRange" | ||
| clearable | ||
| placeholder="选择月份" | ||
| /> | ||
| </div> | ||
|
|
||
| <div> | ||
| <div>quarter 模式:range = ['2025-03-15','2025-12-01'],默认值 2024-Q4(越界,应为错误态)</div> | ||
| <t-date-picker | ||
| v-model="quarterVal" | ||
| mode="quarter" | ||
| allow-input | ||
| :range="periodRange" | ||
| clearable | ||
| placeholder="选择季度" | ||
| /> | ||
| </div> | ||
|
|
||
| <div> | ||
| <div>year 模式:range = ['2025-03-15','2025-12-01'],默认值 2024(越界,应为错误态)</div> | ||
| <t-date-picker v-model="yearVal" mode="year" allow-input :range="periodRange" clearable placeholder="选择年份" /> | ||
| </div> | ||
| </t-space> | ||
| </template> | ||
|
|
||
| <script setup> | ||
| import { ref } from 'vue'; | ||
|
|
||
| // 统一的范围:按月/季/年粒度比较 | ||
| const periodRange = ['2025-03-15', '2025-12-01']; | ||
|
|
||
| // 周起始(与 dayjs 同步使用时可一并设置) | ||
| const firstDayOfWeek = 1; | ||
|
|
||
| // 设定越界默认值以演示错误态 | ||
| const weekVal = ref(new Date(2025, 1, 20)); // 2025-02-20,周不与 range 相交 → 错误 | ||
| const monthVal = ref(new Date(2025, 1, 1)); // 2025-02 → 错误 | ||
| const quarterVal = ref(new Date(2024, 10, 1)); // 2024-11 → Q4 2024 → 错误 | ||
| const yearVal = ref(new Date(2024, 0, 1)); // 2024 → 错误 | ||
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| <template> | ||
| <t-space direction="vertical"> | ||
| <!-- 受控面板 + 函数范围:仅允许未来 90 天 --> | ||
| <t-date-picker | ||
| v-model="valueFn" | ||
| v-model:panelActiveDate="panelActiveDate" | ||
| mode="date" | ||
| format="YYYY-MM-DD" | ||
| :range="rangeFn" | ||
| :need-confirm="false" | ||
| placeholder="选择未来90天内的日期" | ||
| @panel-active-date="handlePanelActiveDate" | ||
| @change="handleChange" | ||
| @month-change="handleMonthChange" | ||
| @year-change="handleYearChange" | ||
| /> | ||
|
|
||
| <!-- 数组范围 + 默认面板日期:仅允许 2026 年 --> | ||
| <t-date-picker | ||
| v-model="valueArr" | ||
| mode="date" | ||
| format="YYYY-MM-DD" | ||
| :range="rangeArr" | ||
| :default-panel-active-date="defaultPanelActiveDate" | ||
| placeholder="仅可选 2026 年内的日期,同时禁用周六" | ||
| :disable-date="disableDate" | ||
| @change="handleChange" | ||
| @month-change="handleMonthChange" | ||
| @year-change="handleYearChange" | ||
| /> | ||
|
|
||
| 年选择:2019 到 2024: | ||
| <t-date-picker mode="year" clearable :range="['2019', '2024']" /> | ||
|
|
||
| 月份选择:2022-10 到 2025-01: | ||
| <t-date-picker mode="month" clearable :range="['2022-10', '2025-01']" /> | ||
|
|
||
| 季度选择:2022-10 到 2025-01: | ||
| <t-date-picker mode="quarter" clearable :range="['2022-10', '2025-01']" /> | ||
|
|
||
| 周选择:2000-10 到 2025-01: | ||
| <t-date-picker mode="week" clearable :range="['2000-10', '2025-01']" /> | ||
| </t-space> | ||
| </template> | ||
|
|
||
| <script setup> | ||
| import { ref } from 'vue'; | ||
| import dayjs from 'dayjs'; | ||
|
|
||
| const disableDate = (date) => dayjs(date).day() === 6; | ||
|
|
||
| // 示例1:函数范围 + 受控面板 | ||
| const valueFn = ref(''); | ||
| const panelActiveDate = ref({ | ||
| year: dayjs().year() - 5, | ||
| month: 10, // 0-11 | ||
uyarn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| // 仅允许今天到未来 90 天(返回 true 表示可选) | ||
| const rangeFn = (d) => { | ||
| const now = dayjs().startOf('day'); | ||
| const target = dayjs(d).startOf('day'); | ||
| const diff = target.diff(now, 'day'); | ||
| return diff >= 0 && diff <= 90; | ||
| }; | ||
|
|
||
| function handlePanelActiveDate(val, ctx) { | ||
| // ctx.trigger: 'year-select' | 'month-select' | 'today' | 'year-arrow-next' | 'year-arrow-previous' | ... | ||
| if (String(ctx?.trigger).includes('year')) { | ||
| panelActiveDate.value.year = typeof val === 'number' ? val : dayjs(val).year(); | ||
| } | ||
| if (String(ctx?.trigger).includes('month') || ctx?.trigger === 'today') { | ||
| panelActiveDate.value.month = typeof val === 'number' ? val : dayjs(val).month(); | ||
| } | ||
| } | ||
|
|
||
| // 示例2:数组范围 + 默认面板日期 | ||
| const valueArr = ref(''); | ||
| const rangeArr = ['2026-01-01', '2026-11-20']; | ||
| const defaultPanelActiveDate = { year: 2026, month: 5 }; // 0-11,5 表示 6 月 | ||
|
|
||
| function handleChange(value, context) { | ||
| console.log('onChange:', value, context); | ||
| } | ||
| function handleMonthChange(context) { | ||
| console.log('onMonthChange:', context); | ||
| } | ||
| function handleYearChange(context) { | ||
| console.log('onYearChange:', context); | ||
| } | ||
| </script> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.