@carto/ps-react-ui 6.5.0 → 6.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,6 +26,7 @@ import { Close as CloseIcon } from '@mui/icons-material'
26
26
  import { WidgetOptions } from '@carto/meridian-ds/custom-icons'
27
27
  import { Tooltip } from '../../components'
28
28
  import { DEFAULT_TOOLBOX_LABELS, type ToolboxLabels } from './labels'
29
+ import { useWrapperCollapsed } from '../wrapper/collapsed-context'
29
30
  import { styles } from './style'
30
31
 
31
32
  export interface ToolboxProps {
@@ -166,6 +167,14 @@ export function Toolbox({
166
167
  setOpen(false)
167
168
  }
168
169
 
170
+ // Same pattern when the enclosing Wrapper collapses: its Accordion keeps
171
+ // the details mounted, so the portalled popper would otherwise stay open
172
+ // over the page with no visible trigger.
173
+ const collapsed = useWrapperCollapsed()
174
+ if (collapsed && open) {
175
+ setOpen(false)
176
+ }
177
+
169
178
  // Reparent the host into the active shell whenever `open` (or either
170
179
  // shell) changes. `useLayoutEffect` runs synchronously after commit
171
180
  // (after refs have been written), so the popover Paper ref is already
@@ -0,0 +1,12 @@
1
+ import { createContext, useContext } from 'react'
2
+
3
+ /**
4
+ * Whether the enclosing `<Wrapper>` is collapsed. The Accordion keeps its
5
+ * details mounted, so content that opens portalled UI (the Toolbox popper)
6
+ * reads this to close it. `false` outside a Wrapper.
7
+ */
8
+ export const WrapperCollapsedContext = createContext(false)
9
+
10
+ export function useWrapperCollapsed(): boolean {
11
+ return useContext(WrapperCollapsedContext)
12
+ }
@@ -24,6 +24,7 @@ import { useWidget, useWidgetId } from '../stores'
24
24
  import { Actions, Options } from './widget-actions'
25
25
  import { styles } from './style'
26
26
  import { DEFAULT_WRAPPER_LABELS, type WrapperLabels } from './labels'
27
+ import { WrapperCollapsedContext } from './collapsed-context'
27
28
 
28
29
  export interface WrapperProps {
29
30
  title: string
@@ -192,7 +193,11 @@ export function Wrapper({
192
193
  </Box>
193
194
  )}
194
195
  </Box>
195
- <AccordionDetails sx={styles.detail}>{detailsSlots}</AccordionDetails>
196
+ <AccordionDetails sx={styles.detail}>
197
+ <WrapperCollapsedContext.Provider value={effectiveCollapsed}>
198
+ {detailsSlots}
199
+ </WrapperCollapsedContext.Provider>
200
+ </AccordionDetails>
196
201
  </Accordion>
197
202
  )
198
203
  }