Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ describe('usePickerLabel hook tests', () => {
expect(sut.result.current.label).toEqual('Red');
});

it('expect label to equal value when no items passed', () => {
it('expect label to equal empty string when no items passed', () => {
const sut = makeSUT({items: undefined, value: 'Some string', getLabel: undefined});
expect(sut.result.current.label).toEqual('Some string');
expect(sut.result.current.label).toEqual('');
});
});
10 changes: 2 additions & 8 deletions src/components/picker/helpers/usePickerLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,8 @@ const usePickerLabel = (props: UsePickerLabelProps) => {
return getLabelsFromArray(value);
}

if (!_.isEmpty(items)) {
const selectedItem = _.find(items, {value});
return _.get(selectedItem, 'label');
}

if (typeof value === 'string') {
return value;
}
const selectedItem = _.find(items, {value});
return _.get(selectedItem, 'label');
}, [getLabel, getLabelsFromArray, items]);

const accessibilityInfo = useMemo(() => {
Expand Down