Open dialogs with command and commandfor
Connect a button to a dialog or popover by ID, then check its keyboard behavior and provide a path for older browsers.
Your shipping page has a button that opens a modal and another that toggles a rate card. If their click handlers only call showModal() and togglePopover(), you can put those commands on the buttons.
Connect the button to its target
Use commandfor with the target's element ID, without a leading #. Use command to choose the action. The HTML standard defines the built-in commands and the elements they apply to.
Save this as an HTML file and open it in a browser with invoker command support.
<button type="button" command="show-modal" commandfor="shipping">
Shipping details
</button>
<dialog id="shipping" aria-labelledby="shipping-title">
<h2 id="shipping-title">Shipping details</h2>
<p>Orders ship on weekdays.</p>
<button type="button" command="close" commandfor="shipping">Close</button>
</dialog>
<button type="button" command="toggle-popover" commandfor="rates">
Show rates
</button>
<div id="rates" popover>Standard shipping costs $5.</div>Shipping details opens a modal with a Close button, and Show rates toggles a separate popover.
The dialog gets its accessible name from the heading referenced by aria-labelledby. Open it with the keyboard and check where focus lands. With this markup it lands on Close. Close the dialog with that button or with Escape and check that focus returns to the opener.
The popover has a different job. The rates card leaves the rest of the page usable while it is open. The popover attribute enables popover behavior on the target, and toggle-popover opens or closes it from the same button.
Check the page without command support
If a button appears to do nothing, start with the ID and the command spelling. show-modal needs a dialog. toggle-popover needs a target with the popover attribute. Keep the IDs unique so the browser can identify the intended element.
For a popover button that only toggles, popovertarget="rates" is another declarative option. It uses the Popover API's default toggle action. A browser also needs Popover API support for that version of the button to work.
Before removing a dialog handler, check the browsers you support. A browser without these commands still renders the button, so the control can appear usable even if activating it has no effect. Keep a fallback for those browsers if the content is essential. For the shipping example, an ordinary link to the shipping information gives the reader a path even when the modal command is unavailable.