File tree Expand file tree Collapse file tree 2 files changed +18
-8
lines changed
packages/svelte-ux/src/lib/components Expand file tree Collapse file tree 2 files changed +18
-8
lines changed Original file line number Diff line number Diff line change 13
13
const { format : format_ux } = getSettings ();
14
14
15
15
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 ;
18
18
export let replace = ' dmyh' ;
19
19
export let picker = false ;
20
20
21
+ $ : actualFormat = format ?? $format_ux .settings .formats .dates .baseParsing ?? ' MM/dd/yyyy' ;
22
+ $ : actualMask = mask ?? actualFormat .toLowerCase ();
23
+
21
24
// Field props
22
25
export let label = ' ' ;
23
26
export let error = ' ' ;
38
41
function onInputChange(e : any ) {
39
42
inputValue = e .detail .value ;
40
43
const lastValue = value ;
41
- const parsedValue = parseDate (inputValue ?? ' ' , format , new Date ());
44
+ const parsedValue = parseDate (inputValue ?? ' ' , actualFormat , new Date ());
42
45
value = isNaN (parsedValue .valueOf ()) ? null : parsedValue ;
43
46
if (value != lastValue ) {
44
47
dispatch (' change' , { value });
65
68
let:id
66
69
>
67
70
<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 }
70
73
{replace }
71
74
{id }
72
75
on:change ={onInputChange }
Original file line number Diff line number Diff line change 24
24
export let mask = ' ' ;
25
25
export let replace = ' _' ;
26
26
export let accept: string | RegExp = ' \\ d' ;
27
- export let placeholder = mask ;
27
+ let placeholderProp: string | undefined = undefined ;
28
+ export { placeholderProp as placeholder };
28
29
export let disabled = false ;
29
30
31
+ $ : placeholder = placeholderProp ?? mask ;
32
+
30
33
const settingsClasses = getComponentClasses (' Input' );
31
34
32
35
let isFocused = false ;
61
64
62
65
function onInput(e : Event & { currentTarget: HTMLInputElement }) {
63
66
const el = e .currentTarget ;
67
+ applyMask (el , mask );
68
+ dispatch (' change' , { value });
69
+ }
64
70
71
+ function applyMask(el : HTMLInputElement , mask : string ) {
65
72
if (mask ) {
66
73
// For selection (including just cursor position), ...
67
74
const [i, j] = [el .selectionStart , el .selectionEnd ].map ((i ) => {
75
82
} else {
76
83
value = el .value ;
77
84
}
78
-
79
- dispatch (' change' , { value });
80
85
}
81
86
87
+ $ : if (inputEl ) applyMask (inputEl , mask );
88
+
82
89
onMount (() => {
83
90
// Format on initial to handle partial values as well as different (but compatible) formats (ex. phone numbers)
84
91
if (mask ) {
You can’t perform that action at this time.
0 commit comments