Skip to content

Commit 7e401e8

Browse files
Merge pull request #52 from equinor/fix/48/use_existing_if_present
fix(48): re-use existing container if present and fix query selector
2 parents c2835c9 + b188050 commit 7e401e8

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/components/Annotations/Annotations.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,15 @@ export const Annotations = ({ maxVisible = 100, children }: AnnotationsProviderP
111111

112112
if (!parent) throw Error('Unable to create root!')
113113

114-
let container: HTMLElement | null = parent.querySelector(id)
114+
let container: HTMLElement | null = parent.querySelector(`#${id}`)
115115

116-
if (container) {
117-
container.remove()
116+
if (!container) {
117+
container = document.createElement('div')
118+
container.setAttribute('id', id)
119+
container.setAttribute('style', 'position:absolute;top:0;left:0;z-index: 1;pointer-events:none;padding:0;width:100%;height:100%;user-select:none')
120+
parent.appendChild(container)
118121
}
119122

120-
container = document.createElement('div')
121-
container.setAttribute('id', id)
122-
container.setAttribute('style', 'position:absolute;top:0;left:0;z-index: 1;pointer-events:none;padding:0;width:100%;height:100%;user-select:none')
123-
parent.appendChild(container)
124-
125123
const annotationsRoot = createRoot(container)
126124

127125
return annotationsRoot

0 commit comments

Comments
 (0)