diff --git a/CHANGELOG.md b/CHANGELOG.md index a94ef342..f8c0d784 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,13 @@ # Changelog -## 3.0.30 +## 3.0.31 - Fix linting error and warnings +## 3.0.30 + +- updated the default value logic of SelectList component to handle onChange function + ## 3.0.29 - updated status tag color and also updated theme and chip with 'deleted' property diff --git a/package.json b/package.json index 8cecc5fc..bd987e68 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@catena-x/portal-shared-components", - "version": "3.0.30", + "version": "3.0.31", "description": "Catena-X Portal Shared Components", "author": "Catena-X Contributors", "license": "Apache-2.0", diff --git a/src/components/basic/SelectList/index.tsx b/src/components/basic/SelectList/index.tsx index 96648991..a6b012dc 100644 --- a/src/components/basic/SelectList/index.tsx +++ b/src/components/basic/SelectList/index.tsx @@ -26,7 +26,7 @@ import { SelectInput } from '../MultiSelectList/Components/SelectInput' import { SelectOptions } from '../MultiSelectList/Components/SelectOptions' import uniqueId from 'lodash/uniqueId' import isEqual from 'lodash/isEqual' -import { useState } from 'react' +import { useEffect, useState } from 'react' interface SelectListProps extends Omit { // eslint-disable-next-line @@ -66,6 +66,19 @@ export const SelectList = ({ // Add an ESLint exception until there is a solution // eslint-disable-next-line const [selected, setSelected] = useState(defaultValue || {}) + + useEffect(() => { + setSelected(defaultValue) + }, [defaultValue]) + + // eslint-disable-next-line + const handleChange = (newValue: any) => { + if (newValue.target.value) { + setSelected(newValue) + onChangeItem(newValue) + } + } + return ( item)} // eslint-disable-next-line getOptionLabel={(option) => option[keyTitle] || ''} - onChange={(_, reason) => { - setSelected(reason) - - onChangeItem(reason) + onChange={(_event, nextValue) => { + handleChange(nextValue) }} isOptionEqualToValue={(option, value) => isEqual(option, value)} renderOption={(props, option, { inputValue }) => (