From 365a36eb22a1e0ff8eb358c7fddef3b9e382b668 Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Mon, 9 Sep 2024 13:42:30 +0200 Subject: [PATCH] more consistent setActiveIndex --- .../@planx/components/MapAndLabel/Public/Context.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/editor.planx.uk/src/@planx/components/MapAndLabel/Public/Context.tsx b/editor.planx.uk/src/@planx/components/MapAndLabel/Public/Context.tsx index 3e7f049db7..cedbfa6aa8 100644 --- a/editor.planx.uk/src/@planx/components/MapAndLabel/Public/Context.tsx +++ b/editor.planx.uk/src/@planx/components/MapAndLabel/Public/Context.tsx @@ -152,13 +152,14 @@ export const MapAndLabelProvider: React.FC = ( const addFeatureToMap = (geojson: GeoJSONChange) => { resetErrors(); - setFeatures(geojson["EPSG:3857"].features); - setActiveIndex((features && features?.length - 2) || activeIndex + 1); + const newFeatures = geojson["EPSG:3857"].features; + setFeatures(newFeatures); + setActiveIndex(newFeatures.length - 1); }; const addInitialFeaturesToMap = (features: Feature[]) => { setFeatures(features); - // TODO: setActiveIndex ? + // setActiveIndex(features.length - 1); }; const addFeatureToForm = () => { @@ -212,8 +213,9 @@ export const MapAndLabelProvider: React.FC = ( resetErrors(); removeFeatureFromForm(index); removeFeatureFromMap(index); + // Set active index as highest tab after removal, so that when you "add" a new feature the tabs increment correctly - setActiveIndex((features && features.length - 2) || activeIndex - 1); + setActiveIndex((features && features.length - 2) || 0); }; return (