i used this little trick and i think it's better than writing the logic separately in js
<dialog>
<form method="dialog">
<!-- stuff you want -->
<button type="button" class="btn" onclick="this.closest('dialog').close()">
Cancel
</button>
</form>
</dialog>