Skip to content

Commit 1552bca

Browse files
Correcting error on open on chevron (#98)
When you open, then close whitout selecting any item and open again, it throws a error ("undefined.length is not a function") Co-authored-by: Alexandr Kozhevnikov <[email protected]>
1 parent 7db9d0a commit 1552bca

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/ScrollViewListItem.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ export const ScrollViewListItem = memo(({ highlight, title, style, onPress, igno
88
let titleStart = title
99
let titleEnd = ''
1010

11-
if (typeof title === 'string' && title.length > 0 && highlight.length > 0) {
11+
if (typeof title === 'string' && title?.length > 0 && highlight?.length > 0) {
12+
const highlightIn = ignoreAccents ? diacriticless(title?.toLowerCase()) : title?.toLowerCase()
13+
const highlightWhat = ignoreAccents ? diacriticless(highlight?.toLowerCase()) : highlight?.toLowerCase()
1214

13-
const highlightIn = ignoreAccents ? diacriticless( title.toLowerCase()) : title.toLowerCase()
14-
const highlightWhat = ignoreAccents ? diacriticless( highlight.toLowerCase()) : highlight.toLowerCase()
15-
16-
const substrIndex = highlightIn.indexOf( highlightWhat )
15+
const substrIndex = highlightIn?.indexOf(highlightWhat)
1716
if (substrIndex !== -1) {
18-
titleStart = title.slice(0, substrIndex)
19-
titleHighlighted = title.slice(substrIndex, substrIndex + highlight.length)
20-
titleEnd = title.slice(substrIndex + highlight.length)
17+
titleStart = title?.slice(0, substrIndex)
18+
titleHighlighted = title?.slice(substrIndex, substrIndex + highlight?.length)
19+
titleEnd = title?.slice(substrIndex + highlight?.length)
2120
}
2221
}
2322

0 commit comments

Comments
 (0)