I have my html content inside the shadow root which is all dynamic coming through microblink SDK.
I need to addEventListener to the #fileBtn
so whenever it is clicked I need to do something. But as it is shadow root I cannot access the DOM property. Also I am using reactjs for this.
<microblink-ui-web tabs="true" autoscroll="true" style="height: 319.562px;">
#shadow-root (open)
<div class="container root" max-width="500px 600px 630px">
<div class="container main">
<div class="container intro dropzone active">
<div class="flex-vertical">
<p class="intro-label">
<slot name="labels.chooseInputMethod">Choose input method</slot>
</p>
<div class="flex-horizontal">
<input
type="file"
accept="image/png,image/gif,image/bmp,image/jpeg,image/x-png,image/vnd.wap.wbmp"
id="file"
/>
<button type="button" class="intro-button" id="fileBtn">
</button>
<button type="button" class="intro-button" id="cameraLocalBtn">
</button>
</div>
</div>
</div>
</div>
</div
></microblink-ui-web>
Thanks in advance!!!
Use shadowRoot property to access the Shadow DOM content.
let mb = document.querySelector( 'microblink-ui-web' )
mb.shadowRoot.querySelector( '#fileBtn' ).addEventListener( 'click', clicked )
function clicked( ev ) {
console.log( ev.target.id + 'clicked' )
}