JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://rawgit.com/Rich-Harris/simulant/master/simulant.js"></script>
<input id="first">
<input id="second">
<p>Dispatching Tab keydown event in 3 seconds... <span id="done" style="color:red"></span></p>
JavaScript
//simulates keydown of the tab key
function simulateTab() {
var TAB_KEY = 9;
simulant.fire(document, 'keydown', { keyCode: TAB_KEY });
}
//focus 'first' input
document.getElementById('first').focus();
//focus 'second' input after 3 seconds
setTimeout(function(){
simulateTab();
document.getElementById('done').innerHTML = 'Done!';
}, 3000);