From 7d7a80ddcbd727f48037ad1e6e8d55529be00563 Mon Sep 17 00:00:00 2001 From: Gilad Gray Date: Fri, 30 Nov 2018 15:24:51 -0800 Subject: [PATCH] total render refactor - FIX: css class is applied when buttons=none - renderButtons() and renderInput() - conditionals to place buttons before or after input - remove special-casing for buttons=none --- .../src/components/forms/numericInput.tsx | 169 +++++++----------- 1 file changed, 64 insertions(+), 105 deletions(-) diff --git a/packages/core/src/components/forms/numericInput.tsx b/packages/core/src/components/forms/numericInput.tsx index 73e3cc4b4c..1431efd137 100644 --- a/packages/core/src/components/forms/numericInput.tsx +++ b/packages/core/src/components/forms/numericInput.tsx @@ -25,6 +25,7 @@ import * as Errors from "../../common/errors"; import { ButtonGroup } from "../button/buttonGroup"; import { Button } from "../button/buttons"; +import { ControlGroup } from "./controlGroup"; import { InputGroup } from "./inputGroup"; export interface INumericInputProps extends IIntentProps, IProps { @@ -140,6 +141,21 @@ enum IncrementDirection { UP = +1, } +const NON_HTML_PROPS = [ + "allowNumericCharactersOnly", + "buttonPosition", + "clampValueOnBlur", + "className", + "large", + "majorStepSize", + "minorStepSize", + "onButtonClick", + "onValueChange", + "selectAllOnFocus", + "selectAllOnIncrement", + "stepSize", +]; + export class NumericInput extends AbstractPureComponent { public static displayName = `${DISPLAYNAME_PREFIX}.NumericInput`; @@ -159,12 +175,6 @@ export class NumericInput extends AbstractPureComponent + const containerClasses = classNames(Classes.NUMERIC_INPUT, { [Classes.LARGE]: large }, className); + const buttons = this.renderButtons(); + return ( + + {buttonPosition === Position.LEFT && buttons} + {this.renderInput()} + {buttonPosition === Position.RIGHT && buttons} + ); - - // the strict null check here is intentional; an undefined value should - // fall back to the default button position on the right side. - if (buttonPosition === "none" || buttonPosition === null) { - // If there are no buttons, then the control group will render the - // text field with squared border-radii on the left side, causing it - // to look weird. This problem goes away if we simply don't nest within - // a control group. - return
{inputGroup}
; - } else { - const incrementButton = this.renderButton( - NumericInput.INCREMENT_KEY, - NumericInput.INCREMENT_ICON_NAME, - this.handleIncrementButtonMouseDown, - this.handleIncrementButtonKeyDown, - this.handleIncrementButtonKeyUp, - ); - const decrementButton = this.renderButton( - NumericInput.DECREMENT_KEY, - NumericInput.DECREMENT_ICON_NAME, - this.handleDecrementButtonMouseDown, - this.handleDecrementButtonKeyDown, - this.handleDecrementButtonKeyUp, - ); - - const buttonGroup = ( - - {incrementButton} - {decrementButton} - - ); - - const inputElems = buttonPosition === Position.LEFT ? [buttonGroup, inputGroup] : [inputGroup, buttonGroup]; - - const classes = classNames( - Classes.NUMERIC_INPUT, - Classes.CONTROL_GROUP, - { - [Classes.FILL]: fill, - [Classes.LARGE]: large, - }, - className, - ); - - return
{inputElems}
; - } } public componentDidUpdate() { @@ -345,24 +280,48 @@ export class NumericInput extends AbstractPureComponent, - onKeyDown: React.KeyboardEventHandler, - onKeyUp: React.KeyboardEventHandler, - ) { + private renderButtons() { + const { intent } = this.props; + const disabled = this.props.disabled || this.props.readOnly; + return ( + +