From 498f0ca219ed7e9aff497042ce34744b7b7461f3 Mon Sep 17 00:00:00 2001 From: Konstantin Schaper Date: Thu, 10 Sep 2020 10:48:37 +0200 Subject: [PATCH] update filter value on props change --- scm-ui/ui-components/src/forms/FilterInput.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scm-ui/ui-components/src/forms/FilterInput.tsx b/scm-ui/ui-components/src/forms/FilterInput.tsx index 9c77f50d0f..c891ffd786 100644 --- a/scm-ui/ui-components/src/forms/FilterInput.tsx +++ b/scm-ui/ui-components/src/forms/FilterInput.tsx @@ -21,10 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -import React, { ChangeEvent, FormEvent } from "react"; -import { WithTranslation, withTranslation } from "react-i18next"; +import React, {ChangeEvent, FormEvent} from "react"; +import {WithTranslation, withTranslation} from "react-i18next"; import styled from "styled-components"; -import { createAttributesForTesting } from "../devBuild"; +import {createAttributesForTesting} from "../devBuild"; type Props = WithTranslation & { filter: (p: string) => void; @@ -59,6 +59,16 @@ class FilterInput extends React.Component { event.preventDefault(); }; + componentDidUpdate = (prevProps: Props) => { + const { value } = this.props; + const { value: stateValue } = this.state; + if (prevProps.value !== value && value !== stateValue) { + this.setState({ + value: value || "" + }); + } + }; + render() { const { t, testId } = this.props; return (