Skip to content
This repository was archived by the owner on Apr 17, 2022. It is now read-only.

Commit 0ab9b9d

Browse files
committed
fix: Can't combine text input and range with dash used in format (fixes #101)
1 parent ace4f96 commit 0ab9b9d

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

src/Vue3DatePicker/Vue3DatePicker.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@
349349
formatLocaleRef,
350350
props.multiDates,
351351
props.utc,
352+
props.textInputOptions,
352353
emit,
353354
);
354355

src/Vue3DatePicker/components/composition/external-internal-mapper.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
setDateMonthOrYear,
1010
setDateTime,
1111
} from '../../utils/date-utils';
12-
import { IFormat, ModelValue, VueEmit } from '../../interfaces';
12+
import { IFormat, ITextInputOptions, ModelValue, VueEmit } from '../../interfaces';
1313
import { isMonth, isRangeArray, isSingle, isTime, isTimeArray } from '../../utils/type-guard';
1414
import { getMonthVal } from '../../utils/date-utils';
1515
import { Locale } from 'date-fns';
@@ -38,6 +38,7 @@ export const useExternalInternalMapper = (
3838
formatLocale: ComputedRef<Locale>,
3939
multiDates: boolean,
4040
utc: boolean,
41+
textInputOptions: ITextInputOptions,
4142
emit: VueEmit,
4243
): IExternalInternalMapper => {
4344
const inputValue = ref('');
@@ -103,7 +104,12 @@ export const useExternalInternalMapper = (
103104
.map((date) => formatDate(date, pattern, formatLocale?.value))
104105
.join('; ');
105106
} else {
106-
inputValue.value = formatDate(internalModelValue.value, pattern, formatLocale?.value);
107+
inputValue.value = formatDate(
108+
internalModelValue.value,
109+
pattern,
110+
formatLocale?.value,
111+
textInputOptions.rangeSeparator,
112+
);
107113
}
108114
} else if (timePicker) {
109115
inputValue.value = format(getTImeForExternal(internalModelValue.value));

src/Vue3DatePicker/utils/date-utils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,16 @@ const formatFn = (value: Date, pattern: string, locale?: Locale | null): string
141141
return format(value, pattern);
142142
};
143143

144-
export const formatDate = (value: Date | Date[], pattern: string, locale?: Locale | null): string => {
144+
export const formatDate = (
145+
value: Date | Date[],
146+
pattern: string,
147+
locale?: Locale | null,
148+
textInputSeparator?: string,
149+
): string => {
145150
if (Array.isArray(value)) {
146-
return `${formatFn(value[0], pattern, locale)} - ${value[1] ? formatFn(value[1], pattern, locale) : ''}`;
151+
return `${formatFn(value[0], pattern, locale)} ${textInputSeparator ? textInputSeparator : '-'} ${
152+
value[1] ? formatFn(value[1], pattern, locale) : ''
153+
}`;
147154
}
148155

149156
return formatFn(value, pattern, locale);

src/Vue3DatePicker/utils/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export const getDefaultTextInputOptions = (): ITextInputOptions => ({
129129
enterSubmit: true,
130130
tabSubmit: true,
131131
openMenu: true,
132-
rangeSeparator: '-',
132+
rangeSeparator: ' - ',
133133
});
134134

135135
/**

0 commit comments

Comments
 (0)