@@ -6,6 +6,9 @@ import { html, customElement } from 'lit-element';
6
6
import styles from './pl-viewport-size.scss?external' ;
7
7
import { store } from '../../store.js' ; // connect to redux
8
8
9
+ const nRegex = / \D + / g;
10
+ const fpRegex = / [ ^ 0 - 9 \. ] + / g;
11
+
9
12
function round ( value , decimals ) {
10
13
return Number ( Math . round ( value + 'e' + decimals ) + 'e-' + decimals ) ;
11
14
}
@@ -63,25 +66,21 @@ class ViewportSize extends BaseLitComponent {
63
66
}
64
67
}
65
68
66
- handlePixelUpdatePress ( e ) {
67
- const nRegex = / \D + / g;
69
+ handlePixelUpdateUp ( e ) {
70
+ this . setState (
71
+ { inputPixelValue : e . target . value . replace ( nRegex , '' ) } ,
72
+ ( ) => { }
73
+ ) ;
74
+ }
68
75
76
+ handlePixelUpdatePress ( e ) {
69
77
if ( e . key . match ( nRegex ) ) {
70
- console . log ( e ) ;
71
-
72
78
// Prevent inserting letters or symbols
73
79
e . preventDefault ( ) ;
74
- } else {
75
- this . setState (
76
- { inputPixelValue : e . target . value . replace ( nRegex , '' ) } ,
77
- ( ) => { }
78
- ) ;
79
80
}
80
81
}
81
82
82
- handlePixelUpdateUp ( e ) {
83
- const nRegex = / \D + / g;
84
-
83
+ handlePixelUpdateDown ( e ) {
85
84
if ( e . key === 'Enter' ) {
86
85
event . preventDefault ( ) ;
87
86
this . iframe . sizeiframe ( this . state . inputPixelValue , true ) ;
@@ -111,25 +110,21 @@ class ViewportSize extends BaseLitComponent {
111
110
e . target . value = this . state . inputPixelValue ;
112
111
}
113
112
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
+ }
116
119
120
+ handleEmUpdatePress ( e ) {
117
121
if ( e . key . match ( fpRegex ) ) {
118
- console . log ( e ) ;
119
-
120
122
// Prevent inserting letters or symbols
121
123
e . preventDefault ( ) ;
122
- } else {
123
- this . setState (
124
- { inputEmValue : e . target . value . replace ( fpRegex , '' ) } ,
125
- ( ) => { }
126
- ) ;
127
124
}
128
125
}
129
126
130
- handleEmUpdateUp ( e ) {
131
- const fpRegex = / [ ^ 0 - 9 \. ] + / g;
132
-
127
+ handleEmUpdateDown ( e ) {
133
128
if ( e . key === 'Enter' ) {
134
129
event . preventDefault ( ) ;
135
130
this . iframe . sizeiframe ( this . toPixelValue ( ) , true ) ;
@@ -182,7 +177,8 @@ class ViewportSize extends BaseLitComponent {
182
177
id ="pl-viewport-pixel-width "
183
178
.value ="${ this . state . inputPixelValue } "
184
179
@keypress =${ this . handlePixelUpdatePress }
185
- @keydown =${ this . handlePixelUpdateUp }
180
+ @keyup =${ this . handlePixelUpdateUp }
181
+ @keydown=${ this . handlePixelUpdateDown }
186
182
@blur=${ this . handlePixelBlur }
187
183
/> px</ label
188
184
> / < label
@@ -194,7 +190,8 @@ class ViewportSize extends BaseLitComponent {
194
190
id ="pl-viewport-em-width "
195
191
.value ="${ this . state . inputEmValue } "
196
192
@keypress =${ this . handleEmUpdatePress }
197
- @keydown =${ this . handleEmUpdateUp }
193
+ @keyup =${ this . handleEmUpdateUp }
194
+ @keydown=${ this . handleEmUpdateDown }
198
195
@blur=${ this . handleEmBlur }
199
196
/> em
200
197
</ label >
0 commit comments