@defra/interactive-map 0.0.41-alpha → 0.0.42-fmp-2

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.
Files changed (77) hide show
  1. package/dist/css/index.css +1 -1
  2. package/dist/esm/im-core.js +1 -1
  3. package/dist/umd/im-core.js +1 -1
  4. package/dist/umd/index.js +1 -1
  5. package/docs/api/button-definition.md +7 -8
  6. package/docs/api/control-definition.md +8 -0
  7. package/docs/api/panel-definition.md +5 -0
  8. package/docs/api/slots.md +24 -1
  9. package/docs/examples/add-polygons.mdx +8 -2
  10. package/docs/examples/add-symbols.mdx +8 -2
  11. package/docs/plugins/datasets.md +23 -15
  12. package/docs/plugins/map-key.md +147 -0
  13. package/docs/plugins.md +5 -1
  14. package/package.json +4 -2
  15. package/plugins/beta/draw-ol/dist/css/index.css +1 -13
  16. package/plugins/beta/frame/dist/css/index.css +1 -11
  17. package/plugins/beta/map-styles/dist/css/index.css +1 -1
  18. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  19. package/plugins/beta/map-styles/dist/umd/index.js +1 -1
  20. package/plugins/beta/scale-bar/dist/css/index.css +1 -31
  21. package/plugins/beta/use-location/dist/esm/im-use-location-plugin.js +1 -1
  22. package/plugins/beta/use-location/dist/umd/im-use-location-plugin.js +1 -1
  23. package/plugins/beta/use-location/src/manifest.js +1 -1
  24. package/plugins/datasets/dist/css/5648.index.css +1 -5
  25. package/plugins/datasets/dist/css/index.css +1 -1
  26. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  27. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  28. package/plugins/draw/dist/umd/index.js +1 -1
  29. package/plugins/draw/src/api/createNewShape.js +41 -0
  30. package/plugins/draw/src/api/createNewShape.test.js +63 -0
  31. package/plugins/draw/src/api/newLine.js +2 -40
  32. package/plugins/draw/src/api/newPolygon.js +2 -40
  33. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  34. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  35. package/plugins/interact/dist/umd/index.js +1 -1
  36. package/plugins/interact/src/manifest.js +1 -1
  37. package/plugins/map-key/dist/css/index.css +1 -62
  38. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  39. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  40. package/plugins/map-key/src/components/Key/Key.jsx +5 -3
  41. package/plugins/map-key/src/components/Key/Key.module.scss +6 -0
  42. package/plugins/map-key/src/components/Key/KeyItem.jsx +5 -8
  43. package/plugins/map-key/src/components/Key/KeySvg.jsx +21 -22
  44. package/plugins/map-key/src/components/Key/KeySvgLine.jsx +3 -9
  45. package/plugins/map-key/src/components/Key/KeySvgPattern.jsx +2 -7
  46. package/plugins/map-key/src/components/Key/KeySvgPattern.test.jsx +6 -0
  47. package/plugins/map-key/src/components/Key/KeySvgRect.jsx +4 -11
  48. package/plugins/map-key/src/components/Key/KeySvgSymbol.jsx +5 -11
  49. package/plugins/map-key/src/components/Key/KeySvgSymbol.test.jsx +12 -0
  50. package/plugins/map-key/src/components/Key/MapKey.jsx +5 -2
  51. package/plugins/map-key/src/components/Key/MapKey.test.jsx +28 -11
  52. package/plugins/menu/dist/css/index.css +1 -80
  53. package/plugins/search/dist/css/index.css +1 -1
  54. package/providers/beta/esri/dist/css/index.css +1 -34
  55. package/rollup.esm.mjs +2 -1
  56. package/scripts/publish-package.sh +8 -0
  57. package/src/App/components/KeyboardHelp/KeyboardHelp.jsx +25 -23
  58. package/src/App/components/KeyboardHelp/KeyboardHelp.test.jsx +22 -5
  59. package/src/App/components/Panel/Panel.jsx +50 -8
  60. package/src/App/components/Panel/Panel.module.scss +31 -7
  61. package/src/App/components/Panel/Panel.test.jsx +81 -2
  62. package/src/App/components/Tabs/Tabs.jsx +43 -17
  63. package/src/App/components/Tabs/Tabs.module.scss +32 -5
  64. package/src/App/components/Tabs/Tabs.test.jsx +40 -10
  65. package/src/App/renderer/groupByKey.js +28 -0
  66. package/src/App/renderer/groupByKey.test.js +39 -0
  67. package/src/App/renderer/groupIntoTabs.js +42 -0
  68. package/src/App/renderer/groupIntoTabs.test.js +95 -0
  69. package/src/App/renderer/mapButtons.js +74 -122
  70. package/src/App/renderer/mapButtons.test.js +51 -80
  71. package/src/App/renderer/mapControls.js +1 -0
  72. package/src/App/renderer/mapControls.test.js +16 -0
  73. package/src/App/renderer/mapPanels.js +26 -19
  74. package/src/App/renderer/mapPanels.test.js +44 -0
  75. package/src/config/appConfig.js +2 -2
  76. package/src/types.js +20 -2
  77. package/webpack.umd.mjs +6 -1
@@ -1,34 +1 @@
1
- :root {
2
- font-family: inherit !important;
3
- text-rendering: auto !important;
4
- -webkit-font-smoothing: auto !important;
5
- -moz-osx-font-smoothing: auto !important;
6
- }
7
-
8
- :root:not(.esri-ui):not([class*=calcite]):not([class*=esri]) {
9
- --calcite-font-family: inherit !important;
10
- --calcite-sans-family: inherit !important;
11
- }
12
-
13
- body, html {
14
- font-family: inherit !important;
15
- text-rendering: auto !important;
16
- -webkit-font-smoothing: auto !important;
17
- -moz-osx-font-smoothing: auto !important;
18
- }
19
-
20
- .your-map-container {
21
- font-family: var(--calcite-font-family);
22
- }
23
-
24
- :not(.esri-view):not(.esri-ui):not([class*=calcite]):not([class*=esri]).calcite-typography, :not(.esri-view):not(.esri-ui):not([class*=calcite]):not([class*=esri]) .calcite-typography {
25
- font-family: inherit !important;
26
- font-size: inherit !important;
27
- font-weight: inherit !important;
28
- letter-spacing: inherit !important;
29
- line-height: inherit !important;
30
- }
31
-
32
- .esri-view-attribution {
33
- display: none;
34
- }
1
+ :root{-webkit-font-smoothing:auto!important;-moz-osx-font-smoothing:auto!important;font-family:inherit!important;text-rendering:auto!important}:root:not(.esri-ui):not([class*=calcite]):not([class*=esri]){--calcite-font-family:inherit!important;--calcite-sans-family:inherit!important}body,html{-webkit-font-smoothing:auto!important;-moz-osx-font-smoothing:auto!important;font-family:inherit!important;text-rendering:auto!important}.your-map-container{font-family:var(--calcite-font-family)}:not(.esri-view):not(.esri-ui):not([class*=calcite]):not([class*=esri]) .calcite-typography,:not(.esri-view):not(.esri-ui):not([class*=calcite]):not([class*=esri]).calcite-typography{font-family:inherit!important;font-size:inherit!important;font-weight:inherit!important;letter-spacing:inherit!important;line-height:inherit!important}.esri-view-attribution{display:none}
package/rollup.esm.mjs CHANGED
@@ -166,7 +166,8 @@ const createESMConfig = (entryPath, outDir, isCore = false, manualChunks = null,
166
166
  // (rootDir) → "css/index.css" — no ".." in the emitted fileName.
167
167
  postcss({
168
168
  extract: path.resolve(cssDir, 'index.css'),
169
- use: ['sass']
169
+ use: ['sass'],
170
+ minimize: true
170
171
  }),
171
172
 
172
173
  terser(),
@@ -53,6 +53,14 @@ validate_version_bump() {
53
53
  }
54
54
 
55
55
  determine_release_tag() {
56
+ if [[ "$TAG_NAME" =~ -([a-zA-Z0-9-]+)\. ]]; then
57
+ local label="${BASH_REMATCH[1]}"
58
+ if [[ "$label" != "alpha" && "$label" != "beta" ]]; then
59
+ echo "$label"
60
+ return
61
+ fi
62
+ fi
63
+
56
64
  if [[ "$IS_PRE_RELEASE" == "true" ]] || [[ "$TAG_NAME" =~ $PRE_RELEASE_PATTERN ]]; then
57
65
  echo "pre-release"
58
66
  else
@@ -3,6 +3,9 @@ import React from 'react'
3
3
  import { useConfig } from '../../store/configContext'
4
4
  import { useApp } from '../../store/appContext.js'
5
5
  import { Tabs } from '../Tabs/Tabs.jsx'
6
+ import { groupIntoTabs } from '../../renderer/groupIntoTabs.js'
7
+
8
+ const DEFAULT_GROUP = 'Navigate'
6
9
 
7
10
  const ShortcutList = ({ items }) => (
8
11
  <dl className='im-c-keyboard-help__list'>
@@ -15,26 +18,22 @@ const ShortcutList = ({ items }) => (
15
18
  </dl>
16
19
  )
17
20
 
18
- const buildGroupMap = (shortcuts) => shortcuts.reduce((acc, shortcut) => {
19
- const group = shortcut.group || 'Navigate'
20
- if (!acc[group]) {
21
- acc[group] = []
22
- }
23
- acc[group].push(shortcut)
24
- return acc
25
- }, {})
26
-
27
- const getDefaultTab = (groupEntries, context) => {
28
- const exactMatch = groupEntries.find(([, items]) =>
29
- items.some(s => (s.context ?? 'viewport') === context)
21
+ /**
22
+ * Picks which tab should be active on open: the first tab containing a shortcut whose own
23
+ * context matches exactly, else the first tab containing a global-context shortcut, else
24
+ * just the first tab. Domain-specific to keyboard shortcuts — not part of groupIntoTabs.
25
+ */
26
+ const getDefaultTab = (tabs, context) => {
27
+ const exactMatch = tabs.find(tab =>
28
+ tab.items.some(({ shortcut }) => (shortcut.context ?? 'viewport') === context)
30
29
  )
31
30
  if (exactMatch) {
32
- return exactMatch[0]
31
+ return exactMatch.name
33
32
  }
34
- const globalMatch = groupEntries.find(([, items]) =>
35
- items.some(s => s.context === 'global')
33
+ const globalMatch = tabs.find(tab =>
34
+ tab.items.some(({ shortcut }) => shortcut.context === 'global')
36
35
  )
37
- return globalMatch?.[0] ?? groupEntries[0][0]
36
+ return globalMatch?.name ?? tabs[0].name
38
37
  }
39
38
 
40
39
  // eslint-disable-next-line camelcase, react/jsx-pascal-case
@@ -46,10 +45,13 @@ export const KeyboardHelp = ({ context = 'viewport' }) => { // NOSONAR: project
46
45
  const shortcuts = listboxIsActive
47
46
  ? allShortcuts
48
47
  : allShortcuts.filter(s => s.context !== 'listbox')
49
- const groupMap = buildGroupMap(shortcuts)
50
- const groupEntries = Object.entries(groupMap)
51
48
 
52
- if (groupEntries.length <= 1) {
49
+ const tabs = groupIntoTabs({
50
+ items: shortcuts.map(shortcut => ({ id: shortcut.id, order: 0, tab: shortcut.group, shortcut })),
51
+ fallbackLabel: DEFAULT_GROUP
52
+ })
53
+
54
+ if (!tabs) {
53
55
  return (
54
56
  <div className='im-c-keyboard-help'>
55
57
  <ShortcutList items={shortcuts} />
@@ -57,14 +59,14 @@ export const KeyboardHelp = ({ context = 'viewport' }) => { // NOSONAR: project
57
59
  )
58
60
  }
59
61
 
60
- const tabs = groupEntries.map(([name, items]) => ({
61
- name,
62
- content: <ShortcutList items={items} />
62
+ const tabProps = tabs.map(tab => ({
63
+ name: tab.name,
64
+ content: <ShortcutList items={tab.items.map(({ shortcut }) => shortcut)} />
63
65
  }))
64
66
 
65
67
  return (
66
68
  <div className='im-c-keyboard-help'>
67
- <Tabs tabs={tabs} defaultTab={getDefaultTab(groupEntries, context)} />
69
+ <Tabs tabs={tabProps} defaultTab={getDefaultTab(tabs, context)} />
68
70
  </div>
69
71
  )
70
72
  }
@@ -116,11 +116,11 @@ describe('KeyboardHelp — tabs', () => {
116
116
  expect(screen.getByRole('tab', { name: 'Group A' })).toHaveAttribute('aria-selected', 'true')
117
117
  })
118
118
 
119
- it('shows only the active tab panel content', () => {
119
+ it('shows only the active tab panel content — the inactive one stays in the DOM (so its aria-controls target exists) but hidden', () => {
120
120
  getKeyboardShortcuts.mockReturnValue(allShortcuts)
121
121
  render(<KeyboardHelp context='viewport' />)
122
- expect(screen.getByText('Move')).toBeInTheDocument()
123
- expect(screen.queryByText('Select')).not.toBeInTheDocument()
122
+ expect(screen.getByText('Move')).toBeVisible()
123
+ expect(screen.getByText('Select')).not.toBeVisible()
124
124
  })
125
125
 
126
126
  it('switches tab and content on click', () => {
@@ -128,8 +128,8 @@ describe('KeyboardHelp — tabs', () => {
128
128
  render(<KeyboardHelp context='viewport' />)
129
129
  fireEvent.click(screen.getByRole('tab', { name: SELECT_FEATURES_GROUP }))
130
130
  expect(screen.getByRole('tab', { name: SELECT_FEATURES_GROUP })).toHaveAttribute('aria-selected', 'true')
131
- expect(screen.getByText('Select')).toBeInTheDocument()
132
- expect(screen.queryByText('Move')).not.toBeInTheDocument()
131
+ expect(screen.getByText('Select')).toBeVisible()
132
+ expect(screen.getByText('Move')).not.toBeVisible()
133
133
  })
134
134
 
135
135
  it('ungrouped shortcuts default to Navigate group', () => {
@@ -141,6 +141,23 @@ describe('KeyboardHelp — tabs', () => {
141
141
  fireEvent.click(screen.getByRole('tab', { name: DEFAULT_GROUP }))
142
142
  expect(screen.getByText('No group')).toBeInTheDocument()
143
143
  })
144
+
145
+ it('merges group names that differ only by case/whitespace into one tab (groupIntoTabs)', () => {
146
+ getKeyboardShortcuts.mockReturnValue([
147
+ { id: 'a', group: 'Select Features', context: 'listbox', title: 'Shortcut A', command: '<kbd>Ctrl+A</kbd>' },
148
+ { id: 'b', group: 'select features', context: 'listbox', title: 'Shortcut B', command: '<kbd>Ctrl+B</kbd>' },
149
+ ...VIEWPORT_SHORTCUTS
150
+ ])
151
+ render(<KeyboardHelp context='listbox' />)
152
+ // Two groups present (Select Features, Navigate) — not one, so tabs render at all
153
+ expect(screen.getAllByRole('tab')).toHaveLength(2)
154
+ // First-encountered member's raw group string wins as the tab's displayed name
155
+ const tab = screen.getByRole('tab', { name: 'Select Features' })
156
+ expect(tab).toBeInTheDocument()
157
+ fireEvent.click(tab)
158
+ expect(screen.getByText('Shortcut A')).toBeVisible()
159
+ expect(screen.getByText('Shortcut B')).toBeVisible()
160
+ })
144
161
  })
145
162
 
146
163
  // ─── listboxIsActive filtering ────────────────────────────────────────────────
@@ -5,6 +5,7 @@ import { stringToKebab } from '../../../utils/stringToKebab.js'
5
5
  import { useModalPanelBehaviour } from '../../hooks/useModalPanelBehaviour.js'
6
6
  import { useIsScrollable } from '../../hooks/useIsScrollable.js'
7
7
  import { Icon } from '../Icon/Icon'
8
+ import { Tabs } from '../Tabs/Tabs.jsx'
8
9
 
9
10
  const computePanelState = (bpConfig, triggeringElement, focus, focusOnOpen) => {
10
11
  const isAside = bpConfig.slot === 'side' && bpConfig.open && !bpConfig.modal
@@ -59,6 +60,8 @@ const buildBodyProps = ({ bodyRef, panelBodyClass, isBodyScrollable, elementId }
59
60
  // Renders the panel body's content: an ordered list of items (own content plus any
60
61
  // controls injected via the `<panelId>-panel` slot convention), or the legacy single
61
62
  // WrappedChild/children shape for callers that don't build an items list (e.g. HtmlElementHost).
63
+ // Tabbed content is handled separately by Panel itself — see the tabs handling below — since
64
+ // the tablist needs to render outside this component's scrollable body, not inside it.
62
65
  const BodyContent = ({ items, WrappedChild, props, children }) => { // NOSONAR
63
66
  if (items) {
64
67
  return items.map(item => <React.Fragment key={item.id}>{item.element}</React.Fragment>)
@@ -66,9 +69,44 @@ const BodyContent = ({ items, WrappedChild, props, children }) => { // NOSONAR
66
69
  return WrappedChild ? <WrappedChild {...props} /> : children
67
70
  }
68
71
 
72
+ // Chooses between the three body shapes: static html, tabbed, or the flat BodyContent above.
73
+ // .im-c-panel__body (bodyProps) always wraps everything, completely unchanged — same padding/
74
+ // overflow/box role it's always had, which is also what the tablist and tabpanel need to pick
75
+ // up their own inset from by simply being nested inside it. Only the scrollable-region
76
+ // behaviour (ref/tabIndex/role/aria-labelledby) moves down onto <Tabs>' own tabpanel div via
77
+ // panelProps when tabbed, since that's the part that should actually scroll/receive focus —
78
+ // the tablist (rendered by <Tabs> itself, ahead of the tabpanel) stays outside that inner
79
+ // scroll boundary so it can't scroll away with long tab content. The tabpanel's own focus ring
80
+ // clearance (so it isn't flush against its content) is a CSS-only concern — see
81
+ // Panel.module.scss's .im-c-tabs__panel override.
82
+ const PanelBody = ({ innerHtmlProp, tabs, items, WrappedChild, props, children, bodyProps, panelBodySlot }) => { // NOSONAR
83
+ if (innerHtmlProp) {
84
+ return <div {...bodyProps} dangerouslySetInnerHTML={innerHtmlProp} /> // nosonar
85
+ }
86
+ const { className, ...scrollableProps } = bodyProps
87
+ if (tabs) {
88
+ return (
89
+ <div className={className} data-panel-slot={panelBodySlot}>
90
+ <Tabs
91
+ tabs={tabs.map(tab => ({
92
+ name: tab.name,
93
+ content: tab.items.map(item => <React.Fragment key={item.id}>{item.element}</React.Fragment>)
94
+ }))}
95
+ panelProps={scrollableProps}
96
+ />
97
+ </div>
98
+ )
99
+ }
100
+ return (
101
+ <div {...bodyProps} data-panel-slot={panelBodySlot}> {/* nosonar */}
102
+ <BodyContent items={items} WrappedChild={WrappedChild} props={props}>{children}</BodyContent>
103
+ </div>
104
+ )
105
+ }
106
+
69
107
  // eslint-disable-next-line camelcase, react/jsx-pascal-case
70
108
  // sonarjs/disable-next-line function-name
71
- export const Panel = ({ panelId, panelConfig, props, focusOnOpen, WrappedChild, items, label, html, children, isOpen = true, rootRef }) => {
109
+ export const Panel = ({ panelId, panelConfig, props, focusOnOpen, WrappedChild, items, tabs, label, html, children, isOpen = true, rootRef }) => {
72
110
  const { id } = useConfig()
73
111
  const { dispatch, breakpoint, layoutRefs, interfaceType } = useApp()
74
112
 
@@ -141,13 +179,17 @@ export const Panel = ({ panelId, panelConfig, props, focusOnOpen, WrappedChild,
141
179
  </button>
142
180
  )}
143
181
 
144
- {innerHtmlProp
145
- ? <div {...bodyProps} dangerouslySetInnerHTML={innerHtmlProp} /> // nosonar
146
- : (
147
- <div {...bodyProps} data-panel-slot={panelBodySlot}> {/* nosonar */}
148
- <BodyContent items={items} WrappedChild={WrappedChild} props={props}>{children}</BodyContent>
149
- </div>
150
- )}
182
+ <PanelBody
183
+ innerHtmlProp={innerHtmlProp}
184
+ tabs={tabs}
185
+ items={items}
186
+ WrappedChild={WrappedChild}
187
+ props={props}
188
+ bodyProps={bodyProps}
189
+ panelBodySlot={panelBodySlot}
190
+ >
191
+ {children}
192
+ </PanelBody>
151
193
  </div>
152
194
  )
153
195
  }
@@ -59,15 +59,39 @@
59
59
  .im-c-panel__body {
60
60
  padding: 0 var(--panel-margin) var(--panel-margin);
61
61
  overflow: auto;
62
+ // display: flex so a tabbed .im-c-tabs child (see Tabs.module.scss) has a flex context to
63
+ // size itself within — its tablist keeps its natural height, only its tabpanel grows and
64
+ // scrolls internally, rather than this whole element (tablist included) scrolling as one.
65
+ // A single non-tabbed child is unaffected — one flex item in a column sizes the same as a
66
+ // plain block child would.
67
+ display: flex;
68
+ flex-direction: column;
69
+ }
62
70
 
63
- &[data-focus-visible="true"] {
64
- outline: var(--scrollable-outline);
65
- outline-offset: var(--scrollable-outline-offset);
66
- box-shadow: var(--scrollable-box-shadow);
71
+ // The tabpanel (see Tabs.module.scss) is its own scroll/focus region nested inside this
72
+ // already-padded wrapper — its content already sits correctly inset just by being nested, but
73
+ // its own border box (where the focus ring is drawn, and where its own overflow: auto clips)
74
+ // would otherwise sit tight against that content, with no room of its own. Reaching out with a
75
+ // negative margin — matching this wrapper's own padding — and re-padding by the same amount
76
+ // gives it that room without moving the content: the negative margin and the padding cancel
77
+ // out visually, but the border box itself is now larger. This is a panel-specific override —
78
+ // <Tabs> used anywhere else would need the same treatment if this clearance matters there too.
79
+ .im-c-panel__body .im-c-tabs__panel {
80
+ margin: 0 calc(-1 * var(--panel-margin)) calc(-1 * var(--panel-margin));
81
+ padding: 0 var(--panel-margin) var(--panel-margin);
82
+ }
83
+
84
+ // The scrollable-region focus ring — normally on .im-c-panel__body itself, but when tabbed,
85
+ // the tabpanel (see Tabs.module.scss's .im-c-tabs__panel) is the element that's actually
86
+ // focusable/scrollable instead (see Panel.jsx's PanelBody), so it needs the same treatment.
87
+ .im-c-panel__body[data-focus-visible="true"],
88
+ .im-c-tabs__panel[data-focus-visible="true"] {
89
+ outline: var(--scrollable-outline);
90
+ outline-offset: var(--scrollable-outline-offset);
91
+ box-shadow: var(--scrollable-box-shadow);
67
92
 
68
- @media (-ms-high-contrast:active), screen and (forced-colors: active) {
69
- outline-width: 4px;
70
- }
93
+ @media (-ms-high-contrast:active), screen and (forced-colors: active) {
94
+ outline-width: 4px;
71
95
  }
72
96
  }
73
97
 
@@ -69,7 +69,7 @@ describe('Panel', () => {
69
69
  const { container } = renderPanel()
70
70
 
71
71
  // 2. Target by class to avoid role collision with the parent panel
72
- const body = container.querySelector('.im-c-panel__body')
72
+ const body = container.querySelector('[data-panel-slot]')
73
73
 
74
74
  expect(body).toHaveAttribute('tabIndex', '0')
75
75
  expect(body).toHaveAttribute('role', 'region')
@@ -219,7 +219,7 @@ describe('Panel', () => {
219
219
 
220
220
  it('stamps data-panel-slot on the items-capable body, for controls DOM-projected via the JS API', () => {
221
221
  const { container } = renderPanel({}, { items: [{ id: 'a', element: <p>Item</p> }] })
222
- const body = container.querySelector('.im-c-panel__body')
222
+ const body = container.querySelector('[data-panel-slot]')
223
223
  expect(body).toHaveAttribute('data-panel-slot', 'settings-panel')
224
224
  })
225
225
 
@@ -228,5 +228,84 @@ describe('Panel', () => {
228
228
  const body = container.querySelector('.im-c-panel__body')
229
229
  expect(body).not.toHaveAttribute('data-panel-slot')
230
230
  })
231
+
232
+ describe('tabs', () => {
233
+ const tabs = [
234
+ { name: 'First', items: [{ id: 'a', element: <p>First content</p> }] },
235
+ { name: 'Second', items: [{ id: 'b', element: <p>Second content</p> }] }
236
+ ]
237
+
238
+ it('renders items grouped into tabs when the tabs prop is provided', () => {
239
+ renderPanel({}, { tabs })
240
+ expect(screen.getByRole('tablist')).toBeInTheDocument()
241
+ expect(screen.getByRole('tab', { name: 'First' })).toBeInTheDocument()
242
+ expect(screen.getByRole('tab', { name: 'Second' })).toBeInTheDocument()
243
+ expect(screen.getByText('First content')).toBeInTheDocument()
244
+ })
245
+
246
+ it('switches tab content when a different tab is activated', () => {
247
+ renderPanel({}, { tabs })
248
+ fireEvent.click(screen.getByRole('tab', { name: 'Second' }))
249
+ expect(screen.getByText('Second content')).toBeVisible()
250
+ expect(screen.getByText('First content')).not.toBeVisible()
251
+ })
252
+
253
+ it('prefers tabs over items/WrappedChild/children when provided', () => {
254
+ renderPanel({}, {
255
+ tabs,
256
+ items: [{ id: 'x', element: <p>Flat item</p> }],
257
+ WrappedChild: () => <p>Wrapped</p>,
258
+ children: <p>Child content</p>
259
+ })
260
+ expect(screen.getByText('First content')).toBeInTheDocument()
261
+ expect(screen.queryByText('Flat item')).not.toBeInTheDocument()
262
+ expect(screen.queryByText('Wrapped')).not.toBeInTheDocument()
263
+ expect(screen.queryByText('Child content')).not.toBeInTheDocument()
264
+ })
265
+
266
+ it('keeps the panel body wrapper (padding, data-panel-slot) around the whole tabs block', () => {
267
+ const { container } = renderPanel({}, { tabs })
268
+ const body = container.querySelector('[data-panel-slot]')
269
+ expect(body).toHaveAttribute('data-panel-slot', 'settings-panel')
270
+ expect(body.querySelector('[role="tablist"]')).not.toBeNull()
271
+ expect(body.querySelector('[role="tabpanel"]')).not.toBeNull()
272
+ })
273
+
274
+ it('keeps the outer wrapper as the normal, unconditional im-c-panel__body — the tablist and tabpanel pick up their inset by being nested inside it, same as any other panel content', () => {
275
+ const { container } = renderPanel({}, { tabs })
276
+ const body = container.querySelector('[data-panel-slot]')
277
+ expect(body).toHaveClass('im-c-panel__body')
278
+ })
279
+
280
+ it('keeps the tablist outside the scrollable tabpanel, so it does not scroll away with long tab content', () => {
281
+ const { container } = renderPanel({}, { tabs })
282
+ const tabpanel = container.querySelector('[role="tabpanel"]')
283
+ expect(tabpanel.querySelector('[role="tablist"]')).toBeNull()
284
+ })
285
+
286
+ it('places the tablist before the tabpanel in DOM order, so keyboard focus reaches it first', () => {
287
+ const { container } = renderPanel({}, { tabs })
288
+ const tablist = container.querySelector('[role="tablist"]')
289
+ const tabpanel = container.querySelector('[role="tabpanel"]')
290
+ // DOCUMENT_POSITION_FOLLOWING (4) means `tabpanel` comes after `tablist`
291
+ // eslint-disable-next-line no-bitwise
292
+ expect(tablist.compareDocumentPosition(tabpanel) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
293
+ })
294
+
295
+ it('moves the scrollable-region treatment onto the tabpanel itself, not the outer wrapper', () => {
296
+ useIsScrollable.mockReturnValue(true)
297
+
298
+ const { container } = renderPanel({}, { tabs })
299
+ const body = container.querySelector('[data-panel-slot]')
300
+ const tabpanel = screen.getByRole('tabpanel')
301
+
302
+ expect(tabpanel).toHaveAttribute('tabIndex', '0')
303
+ expect(body).not.toHaveAttribute('tabIndex')
304
+ expect(body).not.toHaveAttribute('role', 'region')
305
+ expect(tabpanel).not.toHaveAttribute('data-panel-slot')
306
+
307
+ useIsScrollable.mockReturnValue(false)
308
+ })
309
+ })
231
310
  })
232
311
  })
@@ -1,18 +1,31 @@
1
1
  import React, { useState, useCallback } from 'react'
2
+ import { useConfig } from '../../store/configContext'
2
3
 
3
- const toTabId = (name) => `im-c-tabs-tab-${name.toLowerCase().replaceAll(/\s+/g, '-')}`
4
- const toPanelId = (name) => `im-c-tabs-panel-${name.toLowerCase().replaceAll(/\s+/g, '-')}`
4
+ // Prefixed with the app's own id (not the im-c- BEM prefix, which is for CSS classes, not DOM
5
+ // ids see Panel.jsx's/MapButton.jsx's own ${id}-... ids for the same convention) so these
6
+ // stay unique when more than one map instance is on the same page.
7
+ const toTabId = (idPrefix, name) => `${idPrefix}-tabs-tab-${name.toLowerCase().replaceAll(/\s+/g, '-')}`
8
+ const toPanelId = (idPrefix, name) => `${idPrefix}-tabs-panel-${name.toLowerCase().replaceAll(/\s+/g, '-')}`
5
9
 
10
+ /**
11
+ * @param {object} [panelProps] Extra props merged onto the tabpanel div (not the tablist) —
12
+ * e.g. a scrollable container's ref/className/tabIndex, for a caller (Panel.jsx) that needs
13
+ * that behaviour scoped to just the active tab's content, not the tablist above it. `id`,
14
+ * `role` and `aria-labelledby` are structural to the tabs pattern and always win over any
15
+ * same-named key in `panelProps`; `tabIndex` defers to `panelProps.tabIndex` when provided,
16
+ * since a scrollable tabpanel legitimately wants tabIndex 0 rather than the -1 default.
17
+ */
6
18
  // eslint-disable-next-line camelcase, react/jsx-pascal-case
7
19
  // sonarjs/disable-next-line function-name
8
- export const Tabs = ({ tabs, defaultTab }) => { // NOSONAR: project does not use PropTypes
20
+ export const Tabs = ({ tabs, defaultTab, panelProps }) => { // NOSONAR: project does not use PropTypes
21
+ const { id: idPrefix } = useConfig()
9
22
  const names = tabs.map(t => t.name)
10
23
  const [activeTab, setActiveTab] = useState(defaultTab ?? names[0])
11
24
 
12
25
  const activateTab = useCallback((name) => {
13
26
  setActiveTab(name)
14
- document.getElementById(toTabId(name))?.focus()
15
- }, [])
27
+ document.getElementById(toTabId(idPrefix, name))?.focus()
28
+ }, [idPrefix])
16
29
 
17
30
  const handleKeyDown = useCallback((e) => {
18
31
  const idx = names.indexOf(activeTab)
@@ -33,7 +46,7 @@ export const Tabs = ({ tabs, defaultTab }) => { // NOSONAR: project does not use
33
46
  }
34
47
  }, [names, activeTab, activateTab])
35
48
 
36
- const activeContent = tabs.find(t => t.name === activeTab)?.content
49
+ const panelClassName = ['im-c-tabs__panel', panelProps?.className].filter(Boolean).join(' ')
37
50
 
38
51
  return (
39
52
  <div className='im-c-tabs'>
@@ -42,10 +55,10 @@ export const Tabs = ({ tabs, defaultTab }) => { // NOSONAR: project does not use
42
55
  <button
43
56
  type='button'
44
57
  key={name}
45
- id={toTabId(name)}
58
+ id={toTabId(idPrefix, name)}
46
59
  role='tab'
47
60
  aria-selected={activeTab === name}
48
- aria-controls={toPanelId(name)}
61
+ aria-controls={toPanelId(idPrefix, name)}
49
62
  tabIndex={activeTab === name ? 0 : -1}
50
63
  className='im-c-tabs__tab'
51
64
  onClick={() => activateTab(name)}
@@ -55,15 +68,28 @@ export const Tabs = ({ tabs, defaultTab }) => { // NOSONAR: project does not use
55
68
  </button>
56
69
  ))}
57
70
  </div>
58
- <div
59
- id={toPanelId(activeTab)}
60
- role='tabpanel'
61
- aria-labelledby={toTabId(activeTab)}
62
- tabIndex={-1} // nosonar panel has no focusable children; -1 per ARIA tabs pattern (AT reads via role/aria-labelledby)
63
- className='im-c-tabs__panel'
64
- >
65
- {activeContent}
66
- </div>
71
+ {/* All tabpanels render, hidden unless active — not swapped in/out — so every tab's
72
+ aria-controls always resolves to a real element, rather than only the active one's.
73
+ panelProps (ref/tabIndex — a scrollable container's, from a caller like Panel.jsx)
74
+ can only meaningfully target one DOM node, so it's applied to the active panel only;
75
+ className is shared by all of them so there's nothing to restyle on switch. */}
76
+ {tabs.map(({ name, content }) => {
77
+ const isActive = activeTab === name
78
+ return (
79
+ <div
80
+ key={name}
81
+ ref={isActive ? panelProps?.ref : undefined}
82
+ id={toPanelId(idPrefix, name)}
83
+ role='tabpanel'
84
+ aria-labelledby={toTabId(idPrefix, name)}
85
+ tabIndex={isActive ? (panelProps?.tabIndex ?? -1) : -1} // nosonar — panel has no focusable children by default (-1); a scrollable active one wants 0, via panelProps
86
+ hidden={!isActive}
87
+ className={panelClassName}
88
+ >
89
+ {content}
90
+ </div>
91
+ )
92
+ })}
67
93
  </div>
68
94
  )
69
95
  }
@@ -4,9 +4,18 @@
4
4
  // Component: Tabs
5
5
  // ===================================================
6
6
 
7
+ // Lets a caller (e.g. Panel.jsx) give Tabs a bounded height — only .im-c-tabs__panel scrolls.
8
+ .im-c-tabs {
9
+ display: flex;
10
+ flex-direction: column;
11
+ min-height: 0;
12
+ flex: 1 1 auto;
13
+ }
14
+
7
15
  .im-c-tabs__list {
8
16
  position: relative;
9
17
  display: flex;
18
+ flex: 0 0 auto;
10
19
  flex-wrap: wrap;
11
20
  padding: 0;
12
21
  margin: 0;
@@ -14,8 +23,14 @@
14
23
  z-index: 1;
15
24
  }
16
25
 
26
+ .im-c-tabs__panel {
27
+ flex: 1 1 auto;
28
+ overflow: auto;
29
+ }
30
+
17
31
  .im-c-tabs__tab {
18
32
  position: relative;
33
+ z-index: 0; // scopes the active tab's ::before (below) to this button's own stacking context
19
34
  appearance: none;
20
35
  background: var(--button-hover-color);
21
36
  border: 1px solid transparent;
@@ -42,12 +57,24 @@
42
57
  }
43
58
  }
44
59
 
60
+ // The selected tab looks taller via an absolutely-positioned ::before rather than changing
61
+ // the button's own box, so the label never moves and the tablist's height never shifts.
45
62
  &[aria-selected='true'] {
46
- background: var(--background-color);
47
- border-color: var(--app-border-color);
48
- border-bottom-color: var(--background-color);
49
- margin-top: 0;
50
- margin-bottom: -1px;
63
+ z-index: 1; // sit above unselected siblings
64
+ background: transparent;
65
+
66
+ &::before {
67
+ content: '';
68
+ position: absolute;
69
+ z-index: -1;
70
+ top: -5px;
71
+ right: -1px;
72
+ bottom: -6px;
73
+ left: -1px;
74
+ background: var(--background-color);
75
+ border: 1px solid var(--app-border-color);
76
+ border-bottom-color: var(--background-color);
77
+ }
51
78
  }
52
79
 
53
80
  &:focus .im-c-tabs__label {