Skip to content

Commit 01486e4

Browse files
Revert "(Picklist): execute extractTextContent() inside extractTextContent()"
This reverts commit 6ab7b63.
1 parent 79c5729 commit 01486e4

File tree

1 file changed

+3
-38
lines changed

1 file changed

+3
-38
lines changed

src/scripts/Picklist.tsx

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function collectOptionValues(children: unknown): PicklistValue[] {
6767
function findSelectedItemLabel(
6868
children: unknown,
6969
selectedValue: PicklistValue
70-
): string | number | null {
70+
): React.ReactNode | null {
7171
return (
7272
React.Children.map(children, (child) => {
7373
if (!React.isValidElement(child)) {
@@ -107,56 +107,21 @@ function findSelectedItemLabel(
107107
typeof label === 'string' ||
108108
typeof label === 'number' ||
109109
React.isValidElement(label)
110-
? extractTextContent(label)
110+
? label
111111
: undefined;
112112
const childrenValue =
113113
typeof itemChildren === 'string' ||
114114
typeof itemChildren === 'number' ||
115115
React.isValidElement(itemChildren) ||
116116
Array.isArray(itemChildren)
117-
? extractTextContent(itemChildren)
117+
? itemChildren
118118
: undefined;
119119

120120
return labelValue || childrenValue;
121121
}).find((result) => result !== null) ?? null
122122
);
123123
}
124124

125-
/**
126-
* Extract text content from React node recursively
127-
*/
128-
function extractTextContent(node: unknown): string | number | null {
129-
if (node == null) {
130-
return null;
131-
}
132-
133-
if (typeof node === 'string' || typeof node === 'number') {
134-
return node;
135-
}
136-
137-
if (typeof node === 'boolean') {
138-
return String(node);
139-
}
140-
141-
if (Array.isArray(node)) {
142-
return node
143-
.map(extractTextContent)
144-
.filter((result) => result !== null)
145-
.join('');
146-
}
147-
148-
if (
149-
React.isValidElement(node) &&
150-
node.props &&
151-
typeof node.props === 'object' &&
152-
'children' in node.props
153-
) {
154-
return extractTextContent(node.props.children);
155-
}
156-
157-
return null;
158-
}
159-
160125
/**
161126
*
162127
*/

0 commit comments

Comments
 (0)