Skip to content

Commit

Permalink
allow user to control React wrapper id (visgl#6010)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress authored Jul 25, 2021
1 parent bd85343 commit 726ab80
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
7 changes: 3 additions & 4 deletions modules/core/src/lib/deck.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function getPropTypes(PropTypes) {
}

const defaultProps = {
id: 'deckgl-overlay',
id: '',
width: '100%',
height: '100%',

Expand Down Expand Up @@ -424,13 +424,12 @@ export default class Deck {

if (!canvas) {
canvas = document.createElement('canvas');
canvas.id = props.id || 'deckgl-overlay';
const parent = props.parent || document.body;
parent.appendChild(canvas);
}

const {id, style} = props;
canvas.id = id;
Object.assign(canvas.style, style);
Object.assign(canvas.style, props.style);

return canvas;
}
Expand Down
5 changes: 3 additions & 2 deletions modules/react/src/deckgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const DeckGL = forwardRef((props, ref) => {
const {viewManager} = thisRef.deck || {};
const currentViewports = viewManager && viewManager.getViewports();

const {ContextProvider, width, height, style} = props;
const {ContextProvider, width, height, id, style} = props;

const {containerStyle, canvasStyle} = useMemo(() => extractStyles({width, height, style}), [
width,
Expand Down Expand Up @@ -221,14 +221,15 @@ const DeckGL = forwardRef((props, ref) => {

const canvas = createElement('canvas', {
key: 'canvas',
id: id || 'deckgl-overlay',
ref: canvasRef,
style: canvasStyle
});

// Render deck.gl as the last child
thisRef.control = createElement(
'div',
{id: 'deckgl-wrapper', ref: containerRef, style: containerStyle},
{id: `${id || 'deckgl'}-wrapper`, ref: containerRef, style: containerStyle},
[canvas, childrenUnderViews]
);
}
Expand Down

0 comments on commit 726ab80

Please sign in to comment.