Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Selected Values Not Saved or Reset to Default in SelectList Component #257

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading