Lightweight vanilla js Trapping tab key focus function within the Element (just 1kb) , No dependencies
check demo here : https://idurar.github.io/vanilla-js-trapping-tab-key-focus/
### javascript code to open Modal
modal.open('idContent'); // to open Modal with wanted html content
// modal.close(); // to close Modal
### HTML code to insert in Modal
<div id="idContent" style="display:none">
<!--your Modal html content here -->
</div>