From a2b17efbaae39577b2eebc207f79a0f3c30eb64e Mon Sep 17 00:00:00 2001 From: Nils Ingwersen Date: Wed, 8 Jan 2025 11:34:07 +0100 Subject: [PATCH] fix: added a function to set a key based on the index if the placeId is missing --- src/suggest-list.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/suggest-list.tsx b/src/suggest-list.tsx index d8acbcc..db821c7 100644 --- a/src/suggest-list.tsx +++ b/src/suggest-list.tsx @@ -41,6 +41,14 @@ export default class SuggestList extends React.PureComponent { return this.props.isHidden || this.props.suggests.length === 0; } + /** + * Generate a unique key for each suggestion + */ + getSuggestionKey(suggest: Suggest, index: number): string { + // Use placeId if available, otherwise fall back to combination of label and index + return suggest.placeId || `${suggest.label}_${index}`; + } + /** * There are new properties available for the list */ @@ -75,7 +83,7 @@ export default class SuggestList extends React.PureComponent { role="listbox" aria-label={this.props.listLabel} id={this.props.listId}> - {this.props.suggests.map((suggest) => { + {this.props.suggests.map((suggest, index) => { const isActive = (this.props.activeSuggest && suggest.placeId === this.props.activeSuggest.placeId) || @@ -83,7 +91,7 @@ export default class SuggestList extends React.PureComponent { return (