This code doesn't actually handle the tab (which is why it was named watch), it just checks when the focus is on the first or last element, which would make that the next/previous tab would leave the dialog, and only in this cases it resets the tab to the last/first item. This is also why I had to fix several links.

So to remove the tab on the tabs/close links, we need to actually manage the tab, or trigger a tab till this items no longer have focus, or make those items not tabable. Also, we can remove the code that focus the search bar when switching tabs and only focus the search after opening the dialog.

When we use tabs, the content for both tabs is in the DOM, so there are lots of inputs/links inside the dialog that are hidden. But since this code just makes sure that the tab stays inside the dialog, it can be hard that the first or last input/link element is inside a tab. Anyway it could happen when there are no elements in the dialog footer, so I think it might be safer to keep it.