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 b70be2a8f3..8c035a74bc 100644 --- a/editor.planx.uk/src/@planx/components/MapAndLabel/Public/Context.tsx +++ b/editor.planx.uk/src/@planx/components/MapAndLabel/Public/Context.tsx @@ -118,7 +118,6 @@ export const MapAndLabelProvider: React.FC = ( }; const editItem = (index: number) => { - setActiveItemInitialState(formik.values.schemaData[index]); setActiveIndex(index); }; @@ -128,6 +127,8 @@ export const MapAndLabelProvider: React.FC = ( formik.setFieldValue(`schemaData[${activeIndex}]`, activeItemInitialState); const addFeature = () => { + resetErrors(); + const currentFeatures = formik.values.schemaData; const updatedFeatures = [...currentFeatures, initialValues]; formik.setFieldValue("schemaData", updatedFeatures); diff --git a/editor.planx.uk/src/@planx/components/MapAndLabel/Public/index.tsx b/editor.planx.uk/src/@planx/components/MapAndLabel/Public/index.tsx index 2728797075..f12d89568c 100644 --- a/editor.planx.uk/src/@planx/components/MapAndLabel/Public/index.tsx +++ b/editor.planx.uk/src/@planx/components/MapAndLabel/Public/index.tsx @@ -39,14 +39,7 @@ function a11yProps(index: number) { const VerticalFeatureTabs: React.FC<{ features: Feature[] }> = ({ features, }) => { - const { schema, activeIndex, formik } = useMapAndLabelContext(); - const [activeTab, setActiveTab] = useState( - features[features.length - 1].properties?.label || "", - ); - - const handleChange = (_event: React.SyntheticEvent, newValue: string) => { - setActiveTab(newValue); - }; + const { schema, activeIndex, formik, editItem } = useMapAndLabelContext(); return ( = ({ maxHeight: "fit-content", }} > - + { + editItem(parseInt(newValue, 10)); + }} + // TODO! aria-label="Vertical tabs example" sx={{ borderRight: 1, borderColor: "divider" }} > {features.map((feature, i) => ( @@ -78,7 +74,7 @@ const VerticalFeatureTabs: React.FC<{ features: Feature[] }> = ({ {features.map((feature, i) => (