Skip to content

Commit

Permalink
[fix] Legend is rendered outside of widget (#2417)
Browse files Browse the repository at this point in the history
Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
Co-authored-by: Ilya Boyandin <ilya@boyandin.me>
  • Loading branch information
igorDykhta and ilyabo committed Oct 28, 2023
1 parent 473bd80 commit 5e0ad51
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/components/src/map/map-legend-panel.tsx
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import React, {ComponentType, useCallback, useState} from 'react';
import React, {ComponentType, useCallback, useContext, useState} from 'react';
import styled from 'styled-components';

import {Legend} from '../common/icons';
Expand All @@ -34,6 +34,8 @@ import {Layer} from '@kepler.gl/layers';
import {media} from '@kepler.gl/styles';
import {ActionHandler, toggleSplitMapViewport} from '@kepler.gl/actions';

import {RootContext} from '../context';

MapLegendPanelFactory.deps = [MapControlTooltipFactory, MapControlPanelFactory, MapLegendFactory];

export type MapLegendPanelFactoryDeps = [
Expand Down Expand Up @@ -158,13 +160,14 @@ function MapLegendPanelFactory(MapControlTooltip, MapControlPanel, MapLegend) {
</MapControlPanel>
);

const rootContext = useContext(RootContext);
if (isPinned) {
// Pinned panel is not supported in export mode
if (isExport) {
return mapControlPanel;
}
const pinnedPanel = <PinToBottom offsetRight={offsetRight}>{mapControlPanel}</PinToBottom>;
return createPortal(pinnedPanel, document.body);
return createPortal(pinnedPanel, rootContext?.current || document.body);
}

return (
Expand Down

0 comments on commit 5e0ad51

Please sign in to comment.