Skip to content

Commit

Permalink
fix: fix selected values not being saved or being reset to default (#257
Browse files Browse the repository at this point in the history
)

in SelectList Component
#256
  • Loading branch information
shubhamv-ss authored Aug 5, 2024
1 parent 98a6e87 commit 5b2a572
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@catena-x/portal-shared-components",
"version": "3.0.29",
"version": "3.0.30",
"description": "Catena-X Portal Shared Components",
"author": "Catena-X Contributors",
"license": "Apache-2.0",
Expand Down
21 changes: 16 additions & 5 deletions src/components/basic/SelectList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextFieldProps, 'variant'> {
// eslint-disable-next-line
Expand Down Expand Up @@ -66,6 +66,19 @@ export const SelectList = ({
// Add an ESLint exception until there is a solution
// eslint-disable-next-line
const [selected, setSelected] = useState<any>(defaultValue || {})

useEffect(() => {
setSelected(defaultValue)
}, [defaultValue])

// eslint-disable-next-line
const handleChange = (newValue: any) => {
if (newValue.target.value) {
setSelected(newValue)
onChangeItem(newValue)
}
}

return (
<Autocomplete
className="cx-select-list"
Expand All @@ -81,10 +94,8 @@ export const SelectList = ({
options={items.map((item: any) => 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 }) => (
Expand Down

0 comments on commit 5b2a572

Please sign in to comment.