I’ve been banging the drum for a button type="share" for a while now.
I’ve also written about other potential button types. The pattern I noticed was that, if a JavaScript API first requires a user interaction—like the Web Share API—then that’s a good hint that a declarative option would be useful:
The Fullscreen API has the same restriction. You can’t make the browser go fullscreen unless you’re responding to user gesture, like a click. So why not have button type=”fullscreen” in HTML to encapsulate that? And again, the fallback in non-supporting browsers is predictable—it behaves like a regular button—so this is trivial to polyfill.
There’s another “smell” that points to some potential button types: what functionality do browsers provide in their interfaces?
Some browsers provide a print button. So how about button type="print"? The functionality is currently doable with button onclick="window.print()" so this would be a nicer, more declarative way of doing something that’s already possible.
It’s the same with back buttons, forward buttons, and refresh buttons. The functionality is available through a browser interface, and it’s also scriptable, so why not have a declarative equivalent?
How about bookmarking?
And remember, the browser interface isn’t always visible: progressive web apps that launch with minimal browser UI need to provide this functionality.
Šime Vidas was wondering about button type="copy” for copying to clipboard. Again, it’s something that’s currently scriptable and requires a user gesture. It’s a little more complex than the other actions because there needs to be some way of providing the text to be copied, but it’s definitely a valid use case.
button type="share"button type="fullscreen"button type="print"button type="bookmark"button type="back"button type="forward"button type="refresh"button type="copy"
Any more?
25 Shares
# Shared by Curtis Wilcox on Monday, June 19th, 2023 at 3:15pm
# Shared by Jeff Posnick on Monday, June 19th, 2023 at 3:15pm
# Shared by Tyler Sticka on Monday, June 19th, 2023 at 3:15pm
# Shared by Dave 🧱 on Monday, June 19th, 2023 at 3:15pm
# Shared by Josh Tumath on Monday, June 19th, 2023 at 3:15pm
# Shared by westbrook on Monday, June 19th, 2023 at 3:15pm
# Shared by Clayton Dewey on Monday, June 19th, 2023 at 3:15pm
# Shared by Johannes Odland on Monday, June 19th, 2023 at 3:41pm
# Shared by Paul Robert Lloyd 🐢 on Monday, June 19th, 2023 at 4:09pm
# Shared by Thain on Monday, June 19th, 2023 at 4:44pm
# Shared by Eric on Monday, June 19th, 2023 at 4:44pm
# Shared by Brian LeRoux 💚 on Monday, June 19th, 2023 at 4:44pm
# Shared by Sean Boots on Monday, June 19th, 2023 at 5:18pm
# Shared by Evert Pot on Monday, June 19th, 2023 at 5:18pm
# Shared by Cédric Belin on Monday, June 19th, 2023 at 6:27pm
# Shared by Matt Round on Monday, June 19th, 2023 at 7:38pm
# Shared by Felix Niklas on Monday, June 19th, 2023 at 7:38pm
# Shared by Šime Vidas on Monday, June 19th, 2023 at 7:38pm
# Shared by Vladimir Shamsheev on Monday, June 19th, 2023 at 8:36pm
# Shared by Antonio Sarcevic on Monday, June 19th, 2023 at 9:19pm
# Shared by Jeffrey Lembeck on Monday, June 19th, 2023 at 9:19pm
# Shared by Paul Hebert on Monday, June 19th, 2023 at 9:55pm
# Shared by Pez Pengelly on Monday, June 19th, 2023 at 11:49pm
# Shared by Chris Taylor on Tuesday, June 20th, 2023 at 6:11am
# Shared by ambrwlsn on Thursday, June 29th, 2023 at 9:41am