Skip to content

Commit

Permalink
fix: prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
DevJoaoLopes committed Jul 29, 2023
1 parent b45b511 commit 60e3bc5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/autocomplete/__tests__/Autocomplete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,17 @@ describe('Autocomplete', () => {
})

describe('when inputvalues is object', () => {
it.only('should read data autocomplete', async () => {
const items = [{name: 'Apple', id: 1}, {name: 'Orange', id: 2}]
it('should read data autocomplete', async () => {
const items = [
{ name: 'Apple', id: 1 },
{ name: 'Orange', id: 2 }
]

render(
makeAutocompleteFixture({
allowOtherValues: true,
items,
itemToString: (item) => (item ? item.name : ""),
itemToString: item => (item ? item.name : '')
})
)

Expand All @@ -106,10 +109,9 @@ describe('Autocomplete', () => {
const item = await screen.findByText('Apple')
userEvent.click(item)


// an object will be returned in the input without error
expect(textInput).toHaveValue('Apple')
})
});
})
})
})
11 changes: 8 additions & 3 deletions src/autocomplete/src/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ const AutocompleteItems = ({
width
}) => {
itemsFilter = itemsFilter || fuzzyFilter(itemToString)
const items = isFilterDisabled || (typeof inputValue === 'string' && inputValue.trim() === '') ? originalItems : itemsFilter(originalItems, inputValue)
const items =
isFilterDisabled || (typeof inputValue === 'string' && inputValue.trim() === '')
? originalItems
: itemsFilter(originalItems, inputValue)

if (items.length <= 0) return null

Expand Down Expand Up @@ -128,8 +131,10 @@ const Autocomplete = memo(
}

if (props.allowOtherValues && state.isOpen && !changes.isOpen) {
const valueItem = changes.selectedItem || state.inputValue;
return typeof valueItem === 'object' ? {...changes, selectedItem: valueItem} : {...changes, selectedItem: valueItem, inputValue: valueItem}
const valueItem = changes.selectedItem || state.inputValue
return typeof valueItem === 'object'
? { ...changes, selectedItem: valueItem }
: { ...changes, selectedItem: valueItem, inputValue: valueItem }
}

return changes
Expand Down

0 comments on commit 60e3bc5

Please sign in to comment.