Skip to content

Commit 870b7c5

Browse files
authored
Merge pull request #507 from mashmatrix/handle-empty-array-of-picklist-selected-label
Consider possibility of an empty array of `Picklist`'s selected label
2 parents fe37f51 + a4f96c0 commit 870b7c5

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/scripts/Picklist.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ function collectOptionValues(children: unknown): PicklistValue[] {
6767
function findSelectedItemLabel(
6868
children: unknown,
6969
selectedValue: PicklistValue
70-
): React.ReactNode {
71-
return React.Children.map(children, (child) => {
70+
): React.ReactNode | null {
71+
const selectedLabel = React.Children.map(children, (child) => {
7272
if (!React.isValidElement(child)) {
7373
return null;
7474
}
@@ -118,6 +118,12 @@ function findSelectedItemLabel(
118118

119119
return labelValue || childrenValue;
120120
});
121+
122+
if (Array.isArray(selectedLabel) && selectedLabel.length === 0) {
123+
return null;
124+
}
125+
126+
return selectedLabel;
121127
}
122128

123129
/**

0 commit comments

Comments
 (0)