Skip to content

Commit 72f55e3

Browse files
authored
Check for string type before calling string method (#10292)
### WHY are these changes introduced? Fixes #0000 <!-- link to issue if one exists --> <!-- Context about the problem that’s being addressed. --> ### WHAT is this pull request doing?
1 parent 9b14e23 commit 72f55e3

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

.changeset/hip-pears-work.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': patch
3+
---
4+
5+
Added check for string type before calling string method

polaris-react/src/components/ActionList/ActionList.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export function ActionList({
4444
finalSections = sections;
4545
}
4646

47+
const isFilterable = finalSections?.some((section) =>
48+
section.items.some((item) => typeof item.content === 'string'),
49+
);
50+
4751
const hasMultipleSections = finalSections.length > 1;
4852
const elementRole =
4953
hasMultipleSections && actionRole === 'menuitem' ? 'menu' : undefined;
@@ -52,8 +56,10 @@ export function ActionList({
5256

5357
const filteredSections = finalSections?.map((section) => ({
5458
...section,
55-
items: section.items.filter((item) =>
56-
item.content?.toLowerCase().includes(searchText.toLowerCase()),
59+
items: section.items.filter(({content}) =>
60+
typeof content === 'string'
61+
? content?.toLowerCase().includes(searchText.toLowerCase())
62+
: content,
5763
),
5864
}));
5965

@@ -130,7 +136,7 @@ export function ActionList({
130136

131137
return (
132138
<>
133-
{showSearch && (
139+
{showSearch && isFilterable && (
134140
<Box padding="2" paddingBlockEnd={totalFilteredActions > 0 ? '0' : '2'}>
135141
<SearchField
136142
placeholder={i18n.translate(

0 commit comments

Comments
 (0)