Skip to content

Conversation

@renoirb
Copy link
Contributor

@renoirb renoirb commented Dec 12, 2025

Description

Problem

When both the map legend and location modal are open simultaneously, the location modal overlaps the legend, obscuring it completely. This occurs because both UI components use z-30 and are positioned from the right side of the map, causing the LocationModal (which renders after the Legend in the DOM) to paint on top.

Solution

Implement Redux state management for map UI overlays, allowing the LocationModal to dynamically adjust its position based on whether the legend is open or closed.

Implementation Details

1. Redux State Architecture - MapOverlayState Interface

  • Created new MapOverlayState interface to represent UI overlay components
  • Includes isOpen: boolean property to track open/closed state
  • Future-ready with commented properties for overlap detection: width, height, x, y, bounds

2. Redux Store Updates (map-slice.ts)

  • Added legend: MapOverlayState to track legend panel state
  • Added locationModal: MapOverlayState to track location modal state (prepared for future use)
  • Created setLegendOpen(boolean) action to control legend state
  • Created setLocationModalOpen(boolean) action (prepared for future use)

3. Component Refactoring

MapLegend Component:

  • Migrated from local useState to Redux for isOpen state
  • Now dispatches setLegendOpen() instead of calling setIsOpen()
  • Maintains existing behavior: opens automatically when map width >= 430px

LocationModal Component:

  • Reads state.map.legend.isOpen from Redux
  • Refactored className management for clarity and maintainability
  • Implements conditional positioning:
    • Legend closed: md:right-28 (~112px from right edge)
    • Legend open: md:right-[480px] (~480px from right edge)
  • This adjustment prevents the ~338px overlap when both components are visible
  • Added comprehensive component documentation explaining positioning logic

Behavior

  • Legend opens automatically on wider screens (>= 430px map width) - from parent branch CLIM-1233: Map Legend, opened by default #643
  • LocationModal positioning adjusts dynamically based on legend state
  • No overlap occurs when both components are visible
  • Smooth user experience with predictable UI behavior

Future Enhancements

The MapOverlayState interface architecture supports:

  • Precise overlap detection using DOM DOMRect bounds
  • Dynamic positioning calculations based on actual component dimensions
  • Sophisticated multi-overlay coordination and z-index management
  • Potential integration with setLocationModalOpen() action for consistent state management

Testing Checklist

  • Verify legend opens automatically on screens >= 430px width
  • Toggle legend open/closed and confirm LocationModal repositions correctly
  • Test with both components open simultaneously - verify no overlap
  • Test on various screen sizes (mobile: centered, desktop: right-positioned)
  • Verify behavior in Forecast mode (where both components appear)

Related ticket

  • CLIM-1235

Related PRs

@renoirb renoirb changed the base branch from main to CLIM-1233_Map-legend-opened-by-default December 12, 2025 04:53
@renoirb renoirb force-pushed the CLIM-1233_Map-legend-opened-by-default branch from 4ebff88 to 5bbddcd Compare December 15, 2025 18:32
@renoirb renoirb force-pushed the CLIM-1235_Map-Legend-under-LocationModal branch from 66c5258 to 52d8a46 Compare December 15, 2025 18:33
@renoirb renoirb marked this pull request as ready for review December 15, 2025 18:33
@renoirb renoirb self-assigned this Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants