From e26064694040319fe836e76344d6b508df3a9367 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Thu, 18 Oct 2018 17:23:47 +0100 Subject: [PATCH] Text fields with inputs do the right thing --- src/codecs/resize/options.tsx | 27 +++++++++++++++------------ src/components/range/index.tsx | 14 +++++++++++--- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/codecs/resize/options.tsx b/src/codecs/resize/options.tsx index 1a0b5896..95d5387b 100644 --- a/src/codecs/resize/options.tsx +++ b/src/codecs/resize/options.tsx @@ -26,7 +26,7 @@ export default class ResizerOptions extends Component { form?: HTMLFormElement; - reportOptions() { + private reportOptions() { const width = this.form!.width as HTMLInputElement; const height = this.form!.height as HTMLInputElement; @@ -42,7 +42,7 @@ export default class ResizerOptions extends Component { } @bind - onChange(event: Event) { + private onChange() { this.reportOptions(); } @@ -54,19 +54,23 @@ export default class ResizerOptions extends Component { } @bind - onWidthInput(event: Event) { - if (!this.state.maintainAspect) return; + private onWidthInput() { + if (this.state.maintainAspect) { + const width = inputFieldValueAsNumber(this.form!.width); + this.form!.height.value = Math.round(width / this.props.aspect); + } - const width = inputFieldValueAsNumber(this.form!.width); - this.form!.height.value = Math.round(width / this.props.aspect); + this.reportOptions(); } @bind - onHeightInput(event: Event) { - if (!this.state.maintainAspect) return; + private onHeightInput() { + if (this.state.maintainAspect) { + const height = inputFieldValueAsNumber(this.form!.height); + this.form!.width.value = Math.round(height * this.props.aspect); + } - const height = inputFieldValueAsNumber(this.form!.height); - this.form!.width.value = Math.round(height * this.props.aspect); + this.reportOptions(); } render({ options, isVector }: Props, { maintainAspect }: State) { @@ -95,7 +99,6 @@ export default class ResizerOptions extends Component { type="number" min="1" value={'' + options.width} - onChange={this.onChange} onInput={this.onWidthInput} /> @@ -108,7 +111,7 @@ export default class ResizerOptions extends Component { type="number" min="1" value={'' + options.height} - onChange={this.onChange} + onInput={this.onHeightInput} />