Skip to content

Commit 4bd081b

Browse files
authored
fixes #924 (#1107)
1 parent 81cc10d commit 4bd081b

File tree

1 file changed

+50
-18
lines changed

1 file changed

+50
-18
lines changed

client/modules/IDE/components/Preferences.jsx

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,27 @@ class Preferences extends React.Component {
1616
super(props);
1717
this.handleUpdateAutosave = this.handleUpdateAutosave.bind(this);
1818
this.handleUpdateLinewrap = this.handleUpdateLinewrap.bind(this);
19-
this.handleUpdateFont = this.handleUpdateFont.bind(this);
2019
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+
});
2135
}
2236

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);
2540
if (Number.isNaN(value)) {
2641
value = 16;
2742
}
@@ -31,9 +46,24 @@ class Preferences extends React.Component {
3146
if (value < 8) {
3247
value = 8;
3348
}
49+
this.setFontSize(value);
50+
}
51+
52+
setFontSize(value) {
53+
this.setState({ fontSize: value });
3454
this.props.setFontSize(value);
3555
}
3656

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+
3767
handleUpdateAutosave(event) {
3868
const value = event.target.value === 'true';
3969
this.props.setAutosave(value);
@@ -107,29 +137,31 @@ class Preferences extends React.Component {
107137
<h4 className="preference__title">Text size</h4>
108138
<button
109139
className="preference__minus-button"
110-
onClick={() => this.props.setFontSize(this.props.fontSize - 2)}
140+
onClick={this.decreaseFontSize}
111141
aria-label="decrease font size"
112-
disabled={this.props.fontSize <= 8}
142+
disabled={this.state.fontSize <= 8}
113143
>
114144
<InlineSVG src={minusUrl} alt="Decrease Font Size" />
115145
<h6 className="preference__label">Decrease</h6>
116146
</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>
128160
<button
129161
className="preference__plus-button"
130-
onClick={() => this.props.setFontSize(this.props.fontSize + 2)}
162+
onClick={this.increaseFontSize}
131163
aria-label="increase font size"
132-
disabled={this.props.fontSize >= 36}
164+
disabled={this.state.fontSize >= 36}
133165
>
134166
<InlineSVG src={plusUrl} alt="Increase Font Size" />
135167
<h6 className="preference__label">Increase</h6>

0 commit comments

Comments
 (0)