@@ -26,18 +26,6 @@ export function FacadeChangeEvent() {
2626 } )
2727}
2828
29- /**
30- * Creates a CustomEvent('blur') with detail = { facade: true }
31- * used as a way to identify our own blur event
32- */
33- export function FacadeBlurEvent ( ) {
34- return new CustomEvent ( 'blur' , {
35- bubbles : true ,
36- cancelable : true ,
37- detail : { facade : true } ,
38- } )
39- }
40-
4129/**
4230 * ensure that the element we're attaching to is an input element
4331 * if not try to find an input element in this elements childrens
@@ -90,36 +78,33 @@ export function updateValue(
9078 oldValue = oldValue || ''
9179 currentValue = currentValue || ''
9280
93- const number = new NumberFormat ( config ) . clean ( clean && ! config . reverseFill )
94- let masked = number . format ( currentValue )
95- let unmasked = number . clean ( ! config . reverseFill ) . unformat ( currentValue )
96-
97- // check value with in range max and min value
98- if ( clean ) {
99- if ( Number ( config . max ) && unmasked > Number ( config . max ) ) {
100- masked = number . format ( config . max )
101- unmasked = number . unformat ( config . max )
102- } else if ( Number ( config . min ) && unmasked < Number ( config . min ) ) {
103- masked = number . format ( config . min )
104- unmasked = number . unformat ( config . min )
81+ if ( force || oldValue !== currentValue ) {
82+ const number = new NumberFormat ( config ) . clean ( clean && ! config . reverseFill )
83+ let masked = number . format ( currentValue )
84+ let unmasked = number . clean ( ! config . reverseFill ) . unformat ( currentValue )
85+
86+ // check value with in range max and min value
87+ if ( clean ) {
88+ if ( Number ( config . max ) && unmasked > Number ( config . max ) ) {
89+ masked = number . format ( config . max )
90+ unmasked = number . unformat ( config . max )
91+ } else if ( Number ( config . min ) && unmasked < Number ( config . min ) ) {
92+ masked = number . format ( config . min )
93+ unmasked = number . unformat ( config . min )
94+ }
10595 }
106- }
10796
108- if ( force || oldValue !== currentValue ) {
10997 el [ CONFIG_KEY ] . oldValue = masked
11098 el . unmaskedValue = unmasked
99+
111100 // safari makes the cursor jump to the end if el.value gets assign even if to the same value
112101 if ( el . value !== masked ) {
113102 el . value = masked
114103 }
115104
116105 // this part needs to be outside the above IF statement for vuetify in firefox
117106 // drawback is that we endup with two's input events in firefox
118- return (
119- emit &&
120- el . dispatchEvent ( FacadeInputEvent ( ) ) &&
121- el . dispatchEvent ( FacadeChangeEvent ( ) )
122- )
107+ return emit && el . dispatchEvent ( FacadeInputEvent ( ) )
123108 }
124109}
125110
@@ -130,8 +115,9 @@ export function updateValue(
130115 */
131116export function inputHandler ( event ) {
132117 const { target, detail } = event
118+
133119 // We dont need to run this method on the event we emit (prevent event loop)
134- if ( detail && detail . facade ) {
120+ if ( detail ? .facade ) {
135121 return false
136122 }
137123
@@ -143,6 +129,7 @@ export function inputHandler(event) {
143129 const { oldValue, config } = target [ CONFIG_KEY ]
144130
145131 updateValue ( target , null , { emit : false } , event )
132+
146133 // updated cursor position
147134 positionFromEnd = Math . max ( positionFromEnd , config . suffix . length )
148135 positionFromEnd = target . value . length - positionFromEnd
@@ -161,16 +148,17 @@ export function inputHandler(event) {
161148 */
162149export function blurHandler ( event ) {
163150 const { target, detail } = event
151+
164152 // We dont need to run this method on the event we emit (prevent event loop)
165- if ( detail && detail . facade ) {
153+ if ( detail ? .facade ) {
166154 return false
167155 }
168156
169157 const { oldValue } = target [ CONFIG_KEY ]
170158
171- updateValue ( target , null , { force : true , clean : true } , event )
159+ updateValue ( target , null , { force : true , emit : false , clean : true } , event )
172160
173161 if ( oldValue !== target . value ) {
174- target . dispatchEvent ( FacadeBlurEvent ( ) )
162+ target . dispatchEvent ( FacadeChangeEvent ( ) )
175163 }
176164}
0 commit comments