4 ms·
IMO: If it makes sense to "open in new tab" then it should be a link. Otherwise it's a button. Corollary: If it's a link then middle-clicking on it better op
by aidenn0 4y ago
IMO:
If it makes sense to "open in new tab" then it should be a link. Otherwise it's a button.
Corollary: If it's a link then middle-clicking on it better open it in a new tab! There are way too many times that this was broken by JS with the href just being set to "#" or something, but clicking the link, copying the new URL, opening a new tab, pasting the url, going back to the original page and hitting "back" did exactly what I wanted. Don't do this!
- quickthrower2 4y agoOr simply, if it is a form <button> make it look like a button. Otherwise if it is an <a> make it look like a link. Also related: if it is a GET request, don't mutate state or perform an action on the server (except perhaps logging). But that is basic security too. There are exceptions, but know why you are doing the exception. For example a landing page will typically have button-like links for call to actions, because people expect that.
- aidenn0 4y agoIf it's an <a> don't just make it look like a link, make it act like a link instead of having the href just be "#" and overriding what it does with an onclick().
- FridgeSeal 4y ago> If it makes sense to "open in new tab" then it should be a link. Otherwise it's a button. The problem is that apparently, an infuriating number of Front end devs seem to think that nothing in their shouldn’t-have-been-an-SPA page should ever be a link and go somewhere, preferring instead to waste an equivalent amount of time popping up some modal or changing page anyway.
- aidenn0 4y agoBut a lot of times they have a useful routing library (even if by accident) that updates the URL, so opening a new tab with the update URL actually does something useful, but it's not a link so I can't do that.
- Gigachad 4y agoUgh, its an annoying problem that I understand from both sides. Opening a new page has a surprisingly large amount of user friction vs opening a sidesheet or modal. Most of it is just a deficiency in how browsers work. If I'm scrolling down a listing page, I don't want to open a new page because returning will often leave me not where I was before. So I make a judgement call on if a link is _really_ worth clicking. While pages which allow expandable previews or modals, I am much more likely to click since its less of a disruption.
- 8ytecoder 4y agoReturning/navigating back absolutely takes you back exactly where you were. It’s broken because the whole page is now being rendered in js and that forces a re-render. SPA misuse has ruined web to the extent we’ve forgotten what it was like to have proper navigation before all the history hijacking and complete rerendering jazz.
- jameshart 4y agoOn the other hand, after opening a bunch of tool windows and documents to copy-paste between in photoshop or blender or whatever, users don’t expect a ‘back button’ to take them back to the previous window layout state. They might expect a back button to navigate among which window is in the foreground, or between view/zoom positions. Consider the possibility that some web applications might actually benefit from acting more like that.
- 8ytecoder 4y agoWhy I said SPA misuse and not use of SPA.
- yakshaving_jgt 4y ago> If I'm scrolling down a listing page, I don't want to open a new page because returning will often leave me not where I was before. Have you actually tried doing that on this very website you are now reading? Click on my profile. Then click back. Where are you? When I tested this just now, I was returned to exactly the point in the page where I left it.
- tshaddox 4y agoThis is a very popular criticism of SPAs, but every time I see it I really gotta ask how people are screwing this up and if it actually has anything to do with SPAs. With every even slightly popular way I know of to develop SPAs, you have to go out of your way to make links not work as normal links.
- edflsafoiewq 4y agoYou don't make a single page application by adding links to other pages.
- tshaddox 4y agoSure you do. You use the Link component (or similar) that’s provided by the SPA router, which renders a normal <a href="cool-page"> tag that works fine with middle-clicking, command-clicking, and right-clicking. The only difference is that it overrides the click event to perform a client-side navigation on normal clicks. You have to go out of your way to make this not work, or I suppose you could implement your own SPA framework and not understand how any of this works.
- chrismorgan 4y agoI’ve never liked the <Link> approach. I much prefer to write normal links throughout and intercept clicks globally, which is easier to work with, and every bit as reliable (more, in some situations). See https://news.ycombinator.com/item?id=31366875 https://news.ycombinator.com/item?id=31366875 for some discussion of this approach, with sample code in https://news.ycombinator.com/item?id=31373486 https://news.ycombinator.com/item?id=31373486.
- tshaddox 4y agoYeah, that works well too, it just isn't as common in component-based frameworks for the reasons pointed out in that thread.
- runarberg 4y agoThis is a much better rule of thumb IMO. I actually have been a proponent of replacing a bunch of buttons with links at a previous workplace, using the middle click as an argument in favor. Sibling comments seem to misunderstand a frontend development a little. I’ve replaced quite a few dialog modals with pages (in a single page app), and it is usually because a backend developer (or a well meaning intern) thought they could implement the feature on their own (or more likely a project manager told them to), and simply didn’t known about the usability issues with this. Most front end developers I know deal with the same stuff in their workplace.