Skip to content

Commit

Permalink
make logic respect default_value and value props
Browse files Browse the repository at this point in the history
  • Loading branch information
joakbjerk committed May 23, 2024
1 parent 9c9bbfd commit 694edf6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/dnb-eufemia/src/components/autocomplete/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
getCurrentDataTitle,
getCurrentData,
getCurrentIndex,
normalizeData,
} from '../../fragments/drawer-list/DrawerListHelpers'

export default class Autocomplete extends React.PureComponent {
Expand Down Expand Up @@ -411,9 +412,15 @@ class AutocompleteInstance extends React.PureComponent {
}

if (props?.data?.length > 0 && state?.prevData?.length === 0) {
state.inputValue = state.inputValue
? state.inputValue
: getCurrentDataTitle(state.selected_item, props.data)
const currentData = getCurrentData(
props.default_value ?? props.value ?? state.selected_item,
normalizeData(props.data)
)

state.inputValue = parseContentTitle(currentData, {
separator: ' ',
preferSelectedValue: true,
})
}

if (props.data !== state.prevData) {
Expand Down

0 comments on commit 694edf6

Please sign in to comment.