From 33c6e40b7026858be52f804c726b9a1ef41647d3 Mon Sep 17 00:00:00 2001 From: fragosti Date: Thu, 13 Dec 2018 12:45:38 -0800 Subject: simplify scaling input logic --- .../src/components/scaling_amount_input.tsx | 1 + packages/instant/src/components/scaling_input.tsx | 65 ++++++---------------- packages/instant/src/components/ui/input.tsx | 2 +- 3 files changed, 18 insertions(+), 50 deletions(-) diff --git a/packages/instant/src/components/scaling_amount_input.tsx b/packages/instant/src/components/scaling_amount_input.tsx index 86aca5a65..4feb0502d 100644 --- a/packages/instant/src/components/scaling_amount_input.tsx +++ b/packages/instant/src/components/scaling_amount_input.tsx @@ -58,6 +58,7 @@ export class ScalingAmountInput extends React.Component { +export class ScalingInput extends React.Component { public static defaultProps = { onChange: util.boundNoop, onFontSizeChange: util.boundNoop, @@ -54,9 +49,6 @@ export class ScalingInput extends React.Component(); public static getPhase(textLengthThreshold: number, value: string): ScalingInputPhase { if (value.length <= textLengthThreshold) { @@ -93,36 +85,15 @@ export class ScalingInput extends React.Component { return ScalingInput.calculateFontSizeFromProps(this.props, phase); @@ -178,4 +137,12 @@ export class ScalingInput extends React.Component): void => { + const value = event.target.value; + const { maxLength } = this.props; + if (!_.isUndefined(value) && !_.isUndefined(maxLength) && value.length > maxLength) { + return; + } + this.props.onChange(event); + }; } diff --git a/packages/instant/src/components/ui/input.tsx b/packages/instant/src/components/ui/input.tsx index 1e476bed3..697bfaf0f 100644 --- a/packages/instant/src/components/ui/input.tsx +++ b/packages/instant/src/components/ui/input.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { ColorOption, styled } from '../../style/theme'; -export interface InputProps { +export interface InputProps extends React.HTMLAttributes { tabIndex?: number; className?: string; value?: string; -- cgit