Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Create with element instead of ID #59

Open
eskan opened this issue Jun 11, 2020 · 5 comments
Open

[Feature Request] Create with element instead of ID #59

eskan opened this issue Jun 11, 2020 · 5 comments

Comments

@eskan
Copy link

eskan commented Jun 11, 2020

Hi,
we should have a way to create a reader with an HTMLElement instead of an ID. In case of using shadowRoot, application should not be able to find element with document.getElementById.
Cheers,

@mebjas
Copy link
Owner

mebjas commented Jun 13, 2020

Interesting, can you point me to some references on how libraries are used with shadowRoot?

@eskan
Copy link
Author

eskan commented Jun 24, 2020

Hi @mebjas,
This is a good introduction to shadowDom :
https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM
Most of the time people use document.getElementById to find an Element, but when you use shadowDom to create some element you can choose to attach them to a shadowDom : a Dom in the Dom, so it's not a part of document, it cannot be found with document.getElementById. Most of people that provide a library that refer to an element handle an HTMLElement instead of an id to prevent this behavior and they avoid to use "getElementById" (in fact often they use both)
thanks for looking at this, cheers,

@mebjas
Copy link
Owner

mebjas commented Jun 27, 2020

I see, thanks for sharing this. I'll start working on this to see if I can add the support. But to be honest, the library internally uses element id in many places and this'd involve some rework.

@eskan
Copy link
Author

eskan commented Jun 27, 2020

as there is some workaround .. we can use to "move" a root element into a CustomElement, the library is not unusable. So yes i suppose there's some rework :S, i'll hope i can help with this.

@quinn
Copy link

quinn commented Dec 1, 2022

+1 for this. First step would be to refactor code to only call getElementById once, and only work with elements directly after that point.

For example this code:

        const scpCameraScanRegion = document.createElement("div");
        scpCameraScanRegion.id = this.getDashboardSectionCameraScanRegionId();

Does not need to assign an ID. Instead the element could be held as a value and passed to the contexts that need to use this element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants