-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Select): Refactor Downshift items to be strings
This refactors Select so that Downshift holds items as an array of strings rather than an array of ReactElements. This brings it in line with recent changes to Autocomplete.
- Loading branch information
Showing
6 changed files
with
51 additions
and
71 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
packages/react-component-library/src/components/Autocomplete/Autocomplete.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React, { useEffect } from 'react' | ||
import React from 'react' | ||
import { | ||
IconAgriculture, | ||
IconAnchor, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 7 additions & 19 deletions
26
packages/react-component-library/src/components/SelectBase/helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,13 @@ | ||
import React from 'react' | ||
import { isNil } from 'lodash' | ||
|
||
import { SelectBaseOptionAsStringProps } from './SelectBaseOption' | ||
import { SelectChildrenType, SelectChildWithStringType } from './types' | ||
import { ItemsMap } from './types' | ||
|
||
function itemToString(item: SelectChildWithStringType) { | ||
return React.isValidElement<SelectBaseOptionAsStringProps>(item) | ||
? item.props.children | ||
: '' | ||
function getSelectedItem(value: string | null | undefined, itemsMap: ItemsMap) { | ||
return !isNil(value) && value in itemsMap ? value : null | ||
} | ||
|
||
function initialSelectedItem( | ||
children: SelectChildrenType, | ||
value: string | null | ||
) { | ||
if (value === null) { | ||
return null | ||
} | ||
|
||
return React.Children.toArray(children).find((child) => { | ||
return React.isValidElement(child) ? child.props.value === value : null | ||
}) | ||
function itemToString(item: string | null, itemsMap: ItemsMap) { | ||
return !isNil(item) && item in itemsMap ? itemsMap[item].props.children : '' | ||
} | ||
|
||
export { initialSelectedItem, itemToString } | ||
export { getSelectedItem, itemToString } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters