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

fix: 修复 DatePicker seperator 问题 #1805

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/date-picker/DateRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,22 @@ export default defineComponent({
}).month;
} else if (value.value.length === 2 && !props.enableTimePicker) {
// 确保右侧面板月份比左侧大 避免两侧面板月份一致
const nextMonth = value.value.map((v: string) => parseToDayjs(v || new Date(), formatRef.value.format).month());
const nextMonth = value.value.map((v: string) => parseToDayjs(v, formatRef.value.format).month());
if (year.value[0] === year.value[1] && nextMonth[0] === nextMonth[1]) {
nextMonth[0] === 11 ? (nextMonth[0] -= 1) : (nextMonth[1] += 1);
}
month.value = nextMonth;
year.value = value.value.map((v: string) => parseToDayjs(v || new Date(), formatRef.value.format).year());
year.value = value.value.map((v: string) => parseToDayjs(v, formatRef.value.format).year());
// 月份季度选择时需要确保右侧面板年份比左侧大
if ((props.mode === 'month' || props.mode === 'quarter') && year.value[0] === year.value[1]) {
year.value = [year.value[0], year.value[0] + 1];
}
} else {
year.value = value.value.map((v: string) => parseToDayjs(v || new Date(), formatRef.value.format).year());
month.value = value.value.map((v: string) => parseToDayjs(v || new Date(), formatRef.value.format).month());
year.value = value.value.map((v: string) => parseToDayjs(v, formatRef.value.format).year());
if (year.value.length === 1) year.value = [year.value[0], year.value[0]];

month.value = value.value.map((v: string) => parseToDayjs(v, formatRef.value.format).month());
if (month.value.length === 1) month.value = [month.value[0], Math.min(month.value[0] + 1, 11)];
}
} else {
isHoverCell.value = false;
Expand Down
4 changes: 2 additions & 2 deletions src/date-picker/hooks/useRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function useRange(props: TdDateRangePickerProps, { emit }: any) {
const popupVisible = ref(false);
const isHoverCell = ref(false);
const activeIndex = ref(0); // 确定当前选中的输入框序号
const inputValue = ref(formatDate(props.value, { format: formatRef.value.format })); // 未真正选中前可能不断变更输入框的内容
const inputValue = ref(formatDate(value.value, { format: formatRef.value.format })); // 未真正选中前可能不断变更输入框的内容

// input 设置
const rangeInputProps = computed(() => ({
Expand All @@ -40,7 +40,7 @@ export default function useRange(props: TdDateRangePickerProps, { emit }: any) {
clearable: props.clearable,
prefixIcon: props.prefixIcon,
readonly: !props.allowInput,
separator: props.separator,
separator: props.separator || global.value.rangeSeparator,
placeholder: props.placeholder || global.value.placeholder[props.mode],
activeIndex: popupVisible.value ? activeIndex.value : undefined,
class: {
Expand Down
4 changes: 2 additions & 2 deletions src/slider/slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export default mixins(classPrefixMixins).extend({
<div>
<div class={`${this.componentName}__stops`}>
{this.markList.map((item, index) => {
if (item.position === 0 || item.position === 1) return null;
if (item.position === 0 || item.position === 100) return null;
return (
<div
class={[`${this.componentName}__stop`, `${this.componentName}__mark-stop`]}
Expand Down Expand Up @@ -466,7 +466,7 @@ export default mixins(classPrefixMixins).extend({
{this.showSteps && (
<div class={`${this.componentName}__stops`}>
{this.steps.map((item: any, key) => {
if (item.position === 0 || item.position === 1) return null;
if (item.position === 0 || item.position === 100) return null;
return <div class={`${this.componentName}__stop`} key={key} style={this.getStopStyle(item)}></div>;
})}
</div>
Expand Down
66 changes: 29 additions & 37 deletions test/snap/__snapshots__/csr.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34383,7 +34383,9 @@ exports[`csr snapshot test > csr test ./src/date-picker/_example/date-presets-al
</div>
<div
class="t-range-input__inner-separator"
/>
>
-
</div>
<div
class="t-input__wrap t-range-input__inner-right"
>
Expand Down Expand Up @@ -34455,7 +34457,9 @@ exports[`csr snapshot test > csr test ./src/date-picker/_example/date-presets-al
</div>
<div
class="t-range-input__inner-separator"
/>
>
-
</div>
<div
class="t-input__wrap t-range-input__inner-right"
>
Expand Down Expand Up @@ -34534,7 +34538,9 @@ exports[`csr snapshot test > csr test ./src/date-picker/_example/date-range.vue
</div>
<div
class="t-range-input__inner-separator"
/>
>
-
</div>
<div
class="t-input__wrap t-range-input__inner-right"
>
Expand Down Expand Up @@ -34604,7 +34610,9 @@ exports[`csr snapshot test > csr test ./src/date-picker/_example/date-range.vue
</div>
<div
class="t-range-input__inner-separator"
/>
>
-
</div>
<div
class="t-input__wrap t-range-input__inner-right"
>
Expand Down Expand Up @@ -34997,7 +35005,9 @@ exports[`csr snapshot test > csr test ./src/date-picker/_example/disable-date.vu
</div>
<div
class="t-range-input__inner-separator"
/>
>
-
</div>
<div
class="t-input__wrap t-range-input__inner-right"
>
Expand Down Expand Up @@ -35309,7 +35319,9 @@ exports[`csr snapshot test > csr test ./src/date-picker/_example/month.vue 1`] =
</div>
<div
class="t-range-input__inner-separator"
/>
>
-
</div>
<div
class="t-input__wrap t-range-input__inner-right"
>
Expand Down Expand Up @@ -38560,7 +38572,9 @@ exports[`csr snapshot test > csr test ./src/date-picker/_example/quarter.vue 1`]
</div>
<div
class="t-range-input__inner-separator"
/>
>
-
</div>
<div
class="t-input__wrap t-range-input__inner-right"
>
Expand Down Expand Up @@ -38681,7 +38695,9 @@ exports[`csr snapshot test > csr test ./src/date-picker/_example/week.vue 1`] =
</div>
<div
class="t-range-input__inner-separator"
/>
>
-
</div>
<div
class="t-input__wrap t-range-input__inner-right"
>
Expand Down Expand Up @@ -38802,7 +38818,9 @@ exports[`csr snapshot test > csr test ./src/date-picker/_example/year.vue 1`] =
</div>
<div
class="t-range-input__inner-separator"
/>
>
-
</div>
<div
class="t-input__wrap t-range-input__inner-right"
>
Expand Down Expand Up @@ -83865,10 +83883,6 @@ exports[`csr snapshot test > csr test ./src/slider/_example/marks.vue 1`] = `
class="t-slider__stop t-slider__mark-stop"
style="left: 80%;"
/>
<div
class="t-slider__stop t-slider__mark-stop"
style="left: 100%;"
/>
</div>
<div
class="t-slider__mark"
Expand Down Expand Up @@ -83985,10 +83999,6 @@ exports[`csr snapshot test > csr test ./src/slider/_example/marks.vue 1`] = `
class="t-slider__stop t-slider__mark-stop"
style="left: 80%;"
/>
<div
class="t-slider__stop t-slider__mark-stop"
style="left: 100%;"
/>
</div>
<div
class="t-slider__mark"
Expand Down Expand Up @@ -84082,12 +84092,7 @@ exports[`csr snapshot test > csr test ./src/slider/_example/min-and-max.vue 1`]
<div>
<div
class="t-slider__stops"
>
<div
class="t-slider__stop t-slider__mark-stop"
style="left: 100%;"
/>
</div>
/>
<div
class="t-slider__mark"
>
Expand Down Expand Up @@ -84154,12 +84159,7 @@ exports[`csr snapshot test > csr test ./src/slider/_example/min-and-max.vue 1`]
<div>
<div
class="t-slider__stops"
>
<div
class="t-slider__stop t-slider__mark-stop"
style="left: 100%;"
/>
</div>
/>
<div
class="t-slider__mark"
>
Expand Down Expand Up @@ -84428,10 +84428,6 @@ exports[`csr snapshot test > csr test ./src/slider/_example/vertical-marks.vue 1
class="t-slider__stop t-slider__mark-stop"
style="top: calc(20% - 1px);"
/>
<div
class="t-slider__stop t-slider__mark-stop"
style="top: calc(0% - 1px);"
/>
</div>
<div
class="t-slider__mark"
Expand Down Expand Up @@ -84550,10 +84546,6 @@ exports[`csr snapshot test > csr test ./src/slider/_example/vertical-marks.vue 1
class="t-slider__stop t-slider__mark-stop"
style="top: calc(20% - 1px);"
/>
<div
class="t-slider__stop t-slider__mark-stop"
style="top: calc(0% - 1px);"
/>
</div>
<div
class="t-slider__mark"
Expand Down
Loading