@@ -44,6 +44,14 @@ export function cloneDeep(data: object) {
44
44
return JSON . parse ( JSON . stringify ( data ) )
45
45
}
46
46
47
+ export function getConfig ( el : HTMLInputElement ) {
48
+ return JSON . parse ( el . dataset . config as string ) as Config
49
+ }
50
+
51
+ export function setConfig ( el : HTMLInputElement , config : any ) {
52
+ el . dataset . config = JSON . stringify ( config )
53
+ }
54
+
47
55
/**
48
56
* Creates a CustomEvent('input') with detail = { facade: true }
49
57
* used as a way to identify our own input event
@@ -161,7 +169,6 @@ export function inputHandler(event: CustomInputEvent) {
161
169
updateCursor ( target , positionFromEnd )
162
170
163
171
if ( oldValue !== target . value ) {
164
- // target.oldValue = masked
165
172
target . dispatchEvent ( InputEvent ( 'input' ) )
166
173
}
167
174
}
@@ -197,8 +204,14 @@ export function keydownHandler(event: KeyboardEvent, el: CustomInputElement) {
197
204
const regExp = new RegExp ( `${ prefix } |${ suffix } ` , 'g' )
198
205
const newValue = el . value . replace ( regExp , '' )
199
206
const canNegativeInput = min === undefined || Number ( min ) < 0 || Number ( min ) !== min
200
- if ( key === decimal && newValue . includes ( decimal ) ) {
201
- event . preventDefault ( )
207
+ if ( key === decimal ) {
208
+ if ( newValue . includes ( decimal ) ) {
209
+ event . preventDefault ( )
210
+ } else if ( ! newValue ) {
211
+ el . value = '0' + decimal
212
+ // trigger input event
213
+ el . dispatchEvent ( new Event ( 'input' ) )
214
+ }
202
215
} else if ( key === MINUS && ! canNegativeInput ) {
203
216
event . preventDefault ( )
204
217
} else if ( key === 'Backspace' ) {
0 commit comments