JSFiddle - React, Tailwind, and code Playground
JavaScript
// Select text on focus
$('input').on('focus', function (e, silent) {
if (!silent) {
var that = this;
setTimeout(function () { $(that).select(); }, 0);
}
});
// Assign global key handler
$(document).on('keypress', function (e) {
// Send textual key-presses to search field if no input field has focus
// ignores control characters and 'space'
if (e.which > 32 && e.target.tagName !== 'INPUT') {
e.preventDefault();
$('input').trigger('focus', [true])
.val(String.fromCharCode(e.which));
}
});