Skip to content

Commit 5c35310

Browse files
committed
fixes
Signed-off-by: Ilya Boyandin <ilyabo@gmail.com>
1 parent 904db57 commit 5c35310

2 files changed

Lines changed: 7 additions & 16 deletions

File tree

src/components/src/hooks/use-legend-position.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,11 @@ export default function useLegendPosition({
172172
}
173173
}, [isSidePanelShown, onChangeSettings, sidePanelWidth]);
174174

175-
// Clamp position when map resizes to ensure legend stays within viewport
175+
// Clamp contentHeight when map resizes to ensure legend stays within available space
176176
useEffect(() => {
177177
if (!mapWidth || !mapHeight || !legendContentRef.current) return;
178-
179-
const currentPos = posRef.current;
180-
181-
let needsUpdate = false;
182-
const newPos = {...currentPos};
183-
// Clamp contentHeight if it exceeds available space
184178
if (maxContentHeight && contentHeight > 0 && contentHeight > maxContentHeight) {
185179
onChangeSettings({contentHeight: maxContentHeight});
186-
needsUpdate = true;
187-
}
188-
189-
if (needsUpdate) {
190-
onChangeSettings({position: newPos});
191180
}
192181
}, [mapWidth, mapHeight, contentHeight, onChangeSettings, maxContentHeight]);
193182

test/browser/components/hooks/use-legend-position.spec.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('useLegendPosition', () => {
5757
expect(positionStyles).toEqual({left: 100, top: 200});
5858
});
5959

60-
test('should calculate maxContentHeight from mapRootDimensions', () => {
60+
test('should calculate maxContentHeight from mapWidth and mapHeight', () => {
6161
const {
6262
result: {
6363
current: {maxContentHeight}
@@ -69,15 +69,16 @@ describe('useLegendPosition', () => {
6969
settings: {},
7070
onChangeSettings: jest.fn(),
7171
theme: THEME,
72-
mapRootDimensions: {width: 800, height: 600}
72+
mapHeight: 600,
73+
mapWidth: 800
7374
})
7475
);
7576
// maxContentHeight = height - MARGIN.top - MARGIN.bottom - MAP_CONTROL_HEADER_FULL_HEIGHT
7677
// = 600 - 10 - 30 - 34 = 526
7778
expect(maxContentHeight).toBe(526);
7879
});
7980

80-
test('should return undefined maxContentHeight when mapRootDimensions not provided', () => {
81+
test('should return undefined maxContentHeight when mapWidth and mapHeight not provided', () => {
8182
const {
8283
result: {
8384
current: {maxContentHeight}
@@ -116,7 +117,8 @@ describe('useLegendPosition', () => {
116117
},
117118
onChangeSettings,
118119
theme: THEME,
119-
mapRootDimensions: {width: 800, height: 600}
120+
mapHeight: 600,
121+
mapWidth: 800
120122
})
121123
);
122124

0 commit comments

Comments
 (0)