From 63c9c44262b963b149032662658a143f768422a2 Mon Sep 17 00:00:00 2001 From: Robert Katzki Date: Fri, 29 May 2020 10:12:11 +0200 Subject: [PATCH 1/2] fix: use a not random id for the list --- README.md | 6 ++++++ src/Geosuggest.tsx | 4 ++-- src/types/props.d.ts | 1 + test/Geosuggest_spec.tsx | 21 +++++++++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7b55b908..525915fc 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,12 @@ Default: `''` An initial value for the input, when you want to prefill the suggest. +#### id +Type: `String` +Default: `''` + +Define an ID for the geosuggest. Needed when there are multiple instances on a page. + #### className Type: `String` Default: `''` diff --git a/src/Geosuggest.tsx b/src/Geosuggest.tsx index 15b79781..2a4b4aa4 100644 --- a/src/Geosuggest.tsx +++ b/src/Geosuggest.tsx @@ -108,7 +108,7 @@ export default class extends React.Component { this.onSuggestNoResults = this.onSuggestNoResults.bind(this); this.hideSuggests = this.hideSuggests.bind(this); this.selectSuggest = this.selectSuggest.bind(this); - this.listId = `geosuggest__list_${Math.random().toString(16).slice(2)}`; + this.listId = `geosuggest__list${props.id ? `--${props.id}` : ''}`; if (props.queryDelay) { this.onAfterInputChange = debounce( @@ -648,7 +648,7 @@ export default class extends React.Component { ); return ( -
+
{shouldRenderLabel && (