@@ -6,6 +6,9 @@ import { html, customElement } from 'lit-element';
66import styles from './pl-viewport-size.scss?external' ;
77import { store } from '../../store.js' ; // connect to redux
88
9+ const nRegex = / \D + / g;
10+ const fpRegex = / [ ^ 0 - 9 \. ] + / g;
11+
912function round ( value , decimals ) {
1013 return Number ( Math . round ( value + 'e' + decimals ) + 'e-' + decimals ) ;
1114}
@@ -63,25 +66,21 @@ class ViewportSize extends BaseLitComponent {
6366 }
6467 }
6568
66- handlePixelUpdatePress ( e ) {
67- const nRegex = / \D + / g;
69+ handlePixelUpdateUp ( e ) {
70+ this . setState (
71+ { inputPixelValue : e . target . value . replace ( nRegex , '' ) } ,
72+ ( ) => { }
73+ ) ;
74+ }
6875
76+ handlePixelUpdatePress ( e ) {
6977 if ( e . key . match ( nRegex ) ) {
70- console . log ( e ) ;
71-
7278 // Prevent inserting letters or symbols
7379 e . preventDefault ( ) ;
74- } else {
75- this . setState (
76- { inputPixelValue : e . target . value . replace ( nRegex , '' ) } ,
77- ( ) => { }
78- ) ;
7980 }
8081 }
8182
82- handlePixelUpdateUp ( e ) {
83- const nRegex = / \D + / g;
84-
83+ handlePixelUpdateDown ( e ) {
8584 if ( e . key === 'Enter' ) {
8685 event . preventDefault ( ) ;
8786 this . iframe . sizeiframe ( this . state . inputPixelValue , true ) ;
@@ -111,25 +110,21 @@ class ViewportSize extends BaseLitComponent {
111110 e . target . value = this . state . inputPixelValue ;
112111 }
113112
114- handleEmUpdatePress ( e ) {
115- const fpRegex = / [ ^ 0 - 9 \. ] + / g;
113+ handleEmUpdateUp ( e ) {
114+ this . setState (
115+ { inputEmValue : e . target . value . replace ( fpRegex , '' ) } ,
116+ ( ) => { }
117+ ) ;
118+ }
116119
120+ handleEmUpdatePress ( e ) {
117121 if ( e . key . match ( fpRegex ) ) {
118- console . log ( e ) ;
119-
120122 // Prevent inserting letters or symbols
121123 e . preventDefault ( ) ;
122- } else {
123- this . setState (
124- { inputEmValue : e . target . value . replace ( fpRegex , '' ) } ,
125- ( ) => { }
126- ) ;
127124 }
128125 }
129126
130- handleEmUpdateUp ( e ) {
131- const fpRegex = / [ ^ 0 - 9 \. ] + / g;
132-
127+ handleEmUpdateDown ( e ) {
133128 if ( e . key === 'Enter' ) {
134129 event . preventDefault ( ) ;
135130 this . iframe . sizeiframe ( this . toPixelValue ( ) , true ) ;
@@ -182,7 +177,8 @@ class ViewportSize extends BaseLitComponent {
182177 id ="pl-viewport-pixel-width "
183178 .value ="${ this . state . inputPixelValue } "
184179 @keypress =${ this . handlePixelUpdatePress }
185- @keydown =${ this . handlePixelUpdateUp }
180+ @keyup =${ this . handlePixelUpdateUp }
181+ @keydown=${ this . handlePixelUpdateDown }
186182 @blur=${ this . handlePixelBlur }
187183 /> px</ label
188184 > / < label
@@ -194,7 +190,8 @@ class ViewportSize extends BaseLitComponent {
194190 id ="pl-viewport-em-width "
195191 .value ="${ this . state . inputEmValue } "
196192 @keypress =${ this . handleEmUpdatePress }
197- @keydown =${ this . handleEmUpdateUp }
193+ @keyup =${ this . handleEmUpdateUp }
194+ @keydown=${ this . handleEmUpdateDown }
198195 @blur=${ this . handleEmBlur }
199196 /> em
200197 </ label >
0 commit comments