The idea is to have an overlay on the same level as the modal or widget, so when click the overlay, the modal closes.
<div class="overlay"></div>
<div class="widget"></div>
.widget {
width: 50px;
height: 50px;
background-color: firebrick;
position: absolute;
}
.overlay {
position: fixed;
top: 0;
left: 0;
background-color: #dedede;
width: 100vw;
height: 100vh;
}