@@ -44,6 +44,14 @@ export function cloneDeep(data: object) {
4444 return JSON . parse ( JSON . stringify ( data ) )
4545}
4646
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+
4755/**
4856 * Creates a CustomEvent('input') with detail = { facade: true }
4957 * used as a way to identify our own input event
@@ -161,7 +169,6 @@ export function inputHandler(event: CustomInputEvent) {
161169 updateCursor ( target , positionFromEnd )
162170
163171 if ( oldValue !== target . value ) {
164- // target.oldValue = masked
165172 target . dispatchEvent ( InputEvent ( 'input' ) )
166173 }
167174}
@@ -197,8 +204,14 @@ export function keydownHandler(event: KeyboardEvent, el: CustomInputElement) {
197204 const regExp = new RegExp ( `${ prefix } |${ suffix } ` , 'g' )
198205 const newValue = el . value . replace ( regExp , '' )
199206 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+ }
202215 } else if ( key === MINUS && ! canNegativeInput ) {
203216 event . preventDefault ( )
204217 } else if ( key === 'Backspace' ) {
0 commit comments