From dde045687429ae898374e541ba0f469a64cc701d Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Tue, 25 Feb 2020 13:49:00 -0800 Subject: [PATCH] fix(core/presentation): Fix controlled/uncontrolled warning for number inputs (#7953) this reverts https://github.com/spinnaker/deck/pull/7881 and fixes it in the `orEmptyString` helper method Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- .../core/src/presentation/forms/inputs/NumberInput.tsx | 2 +- .../modules/core/src/presentation/forms/inputs/utils.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/scripts/modules/core/src/presentation/forms/inputs/NumberInput.tsx b/app/scripts/modules/core/src/presentation/forms/inputs/NumberInput.tsx index 7b959beacbf..6c90ed14e3b 100644 --- a/app/scripts/modules/core/src/presentation/forms/inputs/NumberInput.tsx +++ b/app/scripts/modules/core/src/presentation/forms/inputs/NumberInput.tsx @@ -26,5 +26,5 @@ export function NumberInput(props: INumberInputProps) { useInternalValidator(validation, minMaxValidator); const className = `NumberInput form-control ${orEmptyString(inputClassName)} ${validationClassName(validation)}`; - return ; + return ; } diff --git a/app/scripts/modules/core/src/presentation/forms/inputs/utils.ts b/app/scripts/modules/core/src/presentation/forms/inputs/utils.ts index c03089416cb..c0735c47d3f 100644 --- a/app/scripts/modules/core/src/presentation/forms/inputs/utils.ts +++ b/app/scripts/modules/core/src/presentation/forms/inputs/utils.ts @@ -1,11 +1,11 @@ import classNames from 'classnames'; -import { isString } from 'lodash'; +import { isString, isNil } from 'lodash'; import { noop } from 'core/utils'; import { IFormInputValidation } from './interface'; -export const orEmptyString = (val: any) => val || ''; +export const orEmptyString = (val: any) => (isNil(val) ? '' : val); export const validationClassName = (validation = {} as IFormInputValidation) => { return classNames({