diff --git a/frontend/src/components/ui/collapsible.tsx b/frontend/src/components/ui/collapsible.tsx index 9605c4e4..1a81b4de 100644 --- a/frontend/src/components/ui/collapsible.tsx +++ b/frontend/src/components/ui/collapsible.tsx @@ -1,9 +1,28 @@ +import * as React from 'react'; + import * as CollapsiblePrimitive from '@radix-ui/react-collapsible'; +import { cn } from '@/lib/classnames'; + const Collapsible = CollapsiblePrimitive.Root; const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger; -const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent; +const CollapsibleContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + + {children} + +)); +CollapsibleContent.displayName = CollapsiblePrimitive.Content.displayName; export { Collapsible, CollapsibleTrigger, CollapsibleContent }; diff --git a/frontend/src/containers/map/content/map/layers-toolbox/layers-list/index.tsx b/frontend/src/containers/map/content/map/layers-toolbox/layers-list/index.tsx index e84b9643..082f04d4 100644 --- a/frontend/src/containers/map/content/map/layers-toolbox/layers-list/index.tsx +++ b/frontend/src/containers/map/content/map/layers-toolbox/layers-list/index.tsx @@ -20,7 +20,7 @@ const TABS_ICONS_CLASSES = 'w-5 h-5 -translate-y-[2px]'; const LayersDropdown = (): JSX.Element => { const [activeLayers, setMapLayers] = useSyncMapLayers(); - const [, setLayerSettings] = useSyncMapLayerSettings(); + const [layerSettings, setLayerSettings] = useSyncMapLayerSettings(); const [{ labels }, setMapSettings] = useSyncMapSettings(); const layersQuery = useGetLayers( @@ -45,7 +45,19 @@ const LayersDropdown = (): JSX.Element => { : activeLayers.filter((_layerId) => _layerId !== Number(layerId)) ); + // If we don't have layerSettings entries, the view is in its default state; we wish to + // show all legend accordion items expanded by default. + const initialSettings = (() => { + const layerSettingsKeys = Object.keys(layerSettings); + if (layerSettingsKeys.length) return {}; + return Object.assign( + {}, + ...activeLayers.map((layerId) => ({ [layerId]: { expanded: true } })) + ); + })(); + setLayerSettings((prev) => ({ + ...initialSettings, ...prev, [layerId]: { ...prev[layerId], @@ -53,7 +65,7 @@ const LayersDropdown = (): JSX.Element => { }, })); }, - [activeLayers, setLayerSettings, setMapLayers] + [activeLayers, layerSettings, setLayerSettings, setMapLayers] ); const handleLabelsChange = useCallback( @@ -71,8 +83,10 @@ const LayersDropdown = (): JSX.Element => { Data Layers - - + +
    @@ -109,11 +123,13 @@ const LayersDropdown = (): JSX.Element => { className={`${COLLAPSIBLE_TRIGGER_CLASSES} pb-0 data-[state=open]:pb-2`} > basemap Layers - - + + -
      +