From 66bf764d744db2a7414bc52d953a1d28f5be1b19 Mon Sep 17 00:00:00 2001 From: emyarod Date: Tue, 18 Jun 2019 08:09:48 -0500 Subject: [PATCH 1/4] fix: set default `defaultValue` for TextInput and TextArea --- packages/react/src/components/TextArea/TextArea.js | 1 + packages/react/src/components/TextInput/TextInput.js | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/react/src/components/TextArea/TextArea.js b/packages/react/src/components/TextArea/TextArea.js index ed5ee9807924..e564e94b61a5 100644 --- a/packages/react/src/components/TextArea/TextArea.js +++ b/packages/react/src/components/TextArea/TextArea.js @@ -266,6 +266,7 @@ TextArea.defaultProps = { invalidText: '', helperText: '', light: false, + defaultValue: '', }; export default TextArea; diff --git a/packages/react/src/components/TextInput/TextInput.js b/packages/react/src/components/TextInput/TextInput.js index 78ece438ff7b..47e415a04bb2 100644 --- a/packages/react/src/components/TextInput/TextInput.js +++ b/packages/react/src/components/TextInput/TextInput.js @@ -258,6 +258,7 @@ TextInput.defaultProps = { invalidText: '', helperText: '', light: false, + defaultValue: '', }; export default TextInput; From da3b1ad77d4208cc9eba92909b4c3a50a535b47c Mon Sep 17 00:00:00 2001 From: emyarod Date: Tue, 18 Jun 2019 08:16:09 -0500 Subject: [PATCH 2/4] chore: update snapshots --- .../ModalWrapper/__snapshots__/ModalWrapper-test.js.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react/src/components/ModalWrapper/__snapshots__/ModalWrapper-test.js.snap b/packages/react/src/components/ModalWrapper/__snapshots__/ModalWrapper-test.js.snap index 29538b2d58ef..16e3226dc114 100644 --- a/packages/react/src/components/ModalWrapper/__snapshots__/ModalWrapper-test.js.snap +++ b/packages/react/src/components/ModalWrapper/__snapshots__/ModalWrapper-test.js.snap @@ -71,8 +71,8 @@ exports[`ModalWrapper should render 1`] = ` className="bx--modal bx--modal-tall" id="modal" onBlur={[Function]} - onClick={[Function]} onKeyDown={[Function]} + onMouseDown={[Function]} role="presentation" tabIndex={-1} > From b80110630df5ebb026f0fbe727d215b60000992a Mon Sep 17 00:00:00 2001 From: emyarod Date: Tue, 18 Jun 2019 09:49:54 -0500 Subject: [PATCH 3/4] fix: use value or defaultValue props for input value --- packages/react/src/components/TextArea/TextArea.js | 2 +- packages/react/src/components/TextInput/TextInput.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react/src/components/TextArea/TextArea.js b/packages/react/src/components/TextArea/TextArea.js index e564e94b61a5..27419f6f7d66 100644 --- a/packages/react/src/components/TextArea/TextArea.js +++ b/packages/react/src/components/TextArea/TextArea.js @@ -50,7 +50,7 @@ const TextArea = ({ renderCharCounter: CharCounter = DefaultCharCounter, ...other }) => { - const [textareaVal, setInput] = useState(defaultValue); + const [textareaVal, setInput] = useState(other.value || defaultValue); const textareaProps = { id, onChange: evt => { diff --git a/packages/react/src/components/TextInput/TextInput.js b/packages/react/src/components/TextInput/TextInput.js index 47e415a04bb2..f5b1ea517d31 100644 --- a/packages/react/src/components/TextInput/TextInput.js +++ b/packages/react/src/components/TextInput/TextInput.js @@ -56,7 +56,7 @@ const TextInput = React.forwardRef(function TextInput( }, ref ) { - const [inputVal, setInput] = useState(defaultValue); + const [inputVal, setInput] = useState(other.value || defaultValue); const errorId = id + '-error-msg'; const textInputClasses = classNames(`${prefix}--text-input`, className, { [`${prefix}--text-input--light`]: light, From 2d365454e530db7c322c2acf65ec28bb844a8f41 Mon Sep 17 00:00:00 2001 From: emyarod Date: Tue, 18 Jun 2019 10:20:40 -0500 Subject: [PATCH 4/4] fix: useEffect prop state sync --- packages/react/src/components/TextArea/TextArea.js | 6 +++++- packages/react/src/components/TextInput/TextInput.js | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/react/src/components/TextArea/TextArea.js b/packages/react/src/components/TextArea/TextArea.js index 27419f6f7d66..11a6ebc9f56a 100644 --- a/packages/react/src/components/TextArea/TextArea.js +++ b/packages/react/src/components/TextArea/TextArea.js @@ -6,7 +6,7 @@ */ import PropTypes from 'prop-types'; -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import classNames from 'classnames'; import { settings } from 'carbon-components'; import WarningFilled16 from '@carbon/icons-react/lib/warning--filled/16'; @@ -142,6 +142,10 @@ const TextArea = ({ /> ); + useEffect(() => { + setInput(other.value || defaultValue); + }, [other, defaultValue]); + return (
{label} diff --git a/packages/react/src/components/TextInput/TextInput.js b/packages/react/src/components/TextInput/TextInput.js index f5b1ea517d31..6ec25b92759b 100644 --- a/packages/react/src/components/TextInput/TextInput.js +++ b/packages/react/src/components/TextInput/TextInput.js @@ -6,7 +6,7 @@ */ import PropTypes from 'prop-types'; -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import classNames from 'classnames'; import { settings } from 'carbon-components'; import WarningFilled16 from '@carbon/icons-react/lib/warning--filled/16'; @@ -140,6 +140,10 @@ const TextInput = React.forwardRef(function TextInput( return helperContent; })(); + useEffect(() => { + setInput(other.value || defaultValue); + }, [other, defaultValue]); + return (
{label}