@@ -16,12 +16,27 @@ class Preferences extends React.Component {
16
16
super ( props ) ;
17
17
this . handleUpdateAutosave = this . handleUpdateAutosave . bind ( this ) ;
18
18
this . handleUpdateLinewrap = this . handleUpdateLinewrap . bind ( this ) ;
19
- this . handleUpdateFont = this . handleUpdateFont . bind ( this ) ;
20
19
this . handleLintWarning = this . handleLintWarning . bind ( this ) ;
20
+ this . onFontInputChange = this . onFontInputChange . bind ( this ) ;
21
+ this . onFontInputSubmit = this . onFontInputSubmit . bind ( this ) ;
22
+ this . increaseFontSize = this . increaseFontSize . bind ( this ) ;
23
+ this . decreaseFontSize = this . decreaseFontSize . bind ( this ) ;
24
+ this . setFontSize = this . setFontSize . bind ( this ) ;
25
+
26
+ this . state = {
27
+ fontSize : props . fontSize
28
+ } ;
29
+ }
30
+
31
+ onFontInputChange ( event ) {
32
+ this . setState ( {
33
+ fontSize : event . target . value
34
+ } ) ;
21
35
}
22
36
23
- handleUpdateFont ( event ) {
24
- let value = parseInt ( event . target . value , 10 ) ;
37
+ onFontInputSubmit ( event ) {
38
+ event . preventDefault ( ) ;
39
+ let value = parseInt ( this . state . fontSize , 10 ) ;
25
40
if ( Number . isNaN ( value ) ) {
26
41
value = 16 ;
27
42
}
@@ -31,9 +46,24 @@ class Preferences extends React.Component {
31
46
if ( value < 8 ) {
32
47
value = 8 ;
33
48
}
49
+ this . setFontSize ( value ) ;
50
+ }
51
+
52
+ setFontSize ( value ) {
53
+ this . setState ( { fontSize : value } ) ;
34
54
this . props . setFontSize ( value ) ;
35
55
}
36
56
57
+ decreaseFontSize ( ) {
58
+ const newValue = this . state . fontSize - 2 ;
59
+ this . setFontSize ( newValue ) ;
60
+ }
61
+
62
+ increaseFontSize ( ) {
63
+ const newValue = this . state . fontSize + 2 ;
64
+ this . setFontSize ( newValue ) ;
65
+ }
66
+
37
67
handleUpdateAutosave ( event ) {
38
68
const value = event . target . value === 'true' ;
39
69
this . props . setAutosave ( value ) ;
@@ -107,29 +137,31 @@ class Preferences extends React.Component {
107
137
< h4 className = "preference__title" > Text size</ h4 >
108
138
< button
109
139
className = "preference__minus-button"
110
- onClick = { ( ) => this . props . setFontSize ( this . props . fontSize - 2 ) }
140
+ onClick = { this . decreaseFontSize }
111
141
aria-label = "decrease font size"
112
- disabled = { this . props . fontSize <= 8 }
142
+ disabled = { this . state . fontSize <= 8 }
113
143
>
114
144
< InlineSVG src = { minusUrl } alt = "Decrease Font Size" />
115
145
< h6 className = "preference__label" > Decrease</ h6 >
116
146
</ button >
117
- < input
118
- className = "preference__value"
119
- aria-live = "polite"
120
- aria-atomic = "true"
121
- value = { this . props . fontSize }
122
- onChange = { this . handleUpdateFont }
123
- ref = { ( element ) => { this . fontSizeInput = element ; } }
124
- onClick = { ( ) => {
125
- this . fontSizeInput . select ( ) ;
126
- } }
127
- />
147
+ < form onSubmit = { this . onFontInputSubmit } >
148
+ < input
149
+ className = "preference__value"
150
+ aria-live = "polite"
151
+ aria-atomic = "true"
152
+ value = { this . state . fontSize }
153
+ onChange = { this . onFontInputChange }
154
+ ref = { ( element ) => { this . fontSizeInput = element ; } }
155
+ onClick = { ( ) => {
156
+ this . fontSizeInput . select ( ) ;
157
+ } }
158
+ />
159
+ </ form >
128
160
< button
129
161
className = "preference__plus-button"
130
- onClick = { ( ) => this . props . setFontSize ( this . props . fontSize + 2 ) }
162
+ onClick = { this . increaseFontSize }
131
163
aria-label = "increase font size"
132
- disabled = { this . props . fontSize >= 36 }
164
+ disabled = { this . state . fontSize >= 36 }
133
165
>
134
166
< InlineSVG src = { plusUrl } alt = "Increase Font Size" />
135
167
< h6 className = "preference__label" > Increase</ h6 >
0 commit comments