Skip to content

Commit ca8bdfd

Browse files
committed
make DateField format and mask reactive to locale changes
1 parent 250b407 commit ca8bdfd

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/svelte-ux/src/lib/components/DateField.svelte

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
const { format: format_ux } = getSettings();
1414
1515
export let value: Date | null = null;
16-
export let format = $format_ux.settings.formats.dates.baseParsing ?? 'MM/dd/yyyy';
17-
export let mask = format.toLowerCase();
16+
export let format: string | undefined = undefined;
17+
export let mask: string | undefined = undefined;
1818
export let replace = 'dmyh';
1919
export let picker = false;
2020
21+
$: actualFormat = format ?? $format_ux.settings.formats.dates.baseParsing ?? 'MM/dd/yyyy';
22+
$: actualMask = mask ?? actualFormat.toLowerCase();
23+
2124
// Field props
2225
export let label = '';
2326
export let error = '';
@@ -38,7 +41,7 @@
3841
function onInputChange(e: any) {
3942
inputValue = e.detail.value;
4043
const lastValue = value;
41-
const parsedValue = parseDate(inputValue ?? '', format, new Date());
44+
const parsedValue = parseDate(inputValue ?? '', actualFormat, new Date());
4245
value = isNaN(parsedValue.valueOf()) ? null : parsedValue;
4346
if (value != lastValue) {
4447
dispatch('change', { value });
@@ -65,8 +68,8 @@
6568
let:id
6669
>
6770
<Input
68-
value={value ? $format_ux(value, PeriodType.Day, { custom: format }) : inputValue}
69-
{mask}
71+
value={value ? $format_ux(value, PeriodType.Day, { custom: actualFormat }) : inputValue}
72+
mask={actualMask}
7073
{replace}
7174
{id}
7275
on:change={onInputChange}

0 commit comments

Comments
 (0)