JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://igorescobar.github.io/jQuery-Mask-Plugin/js/jquery.mask.min.js"></script>
CPF / CNPJ: <input type="text" name="cpfcnpj" id="cpfcnpj" />
JavaScript
$("#cpfcnpj").keydown(function(){
try {
$("#cpfcnpj").unmask();
} catch (e) {}
var tamanho = $("#cpfcnpj").val().length;
if(tamanho < 11){
$("#cpfcnpj").mask("999.999.999-99");
} else if(tamanho >= 11){
$("#cpfcnpj").mask("99.999.999/9999-99");
}
// ajustando foco
var elem = this;
setTimeout(function(){
// mudo a posição do seletor
elem.selectionStart = elem.selectionEnd = 10000;
}, 0);
// reaplico o valor para mudar o foco
var currentValue = $(this).val();
$(this).val('');
$(this).val(currentValue);
});