JSFiddle - React, Tailwind, and code Playground

HTML

<input id=password value="test">
<button id=copy_btn>Copy</button>

JavaScript

function clickListener() {
		 document.getElementById('password').select();
    document.execCommand('copy');
}

document.getElementById('copy_btn').addEventListener('click', clickListener);