Has anyone made a disclosure/content-warning/spoilers web component?
-
Has anyone made a disclosure/content-warning/spoilers web component?
-
Jay Hannahreplied to Zach Leatherman :11ty: on last edited by
@zachleat I think there’s a WP plugin for that.
-
@zachleat I guess the details element is sorta that?
-
@nickcolley kind of! I think the design/UX could be a bit more specific here
-
Zach Leatherman :11ty:replied to Jay Hannah on last edited by
@deafferret I just can’t defederret you, jay
-
Steve Frenzelreplied to Zach Leatherman :11ty: on last edited by
@zachleat maybe this helps?
-
Zach Leatherman :11ty:replied to Steve Frenzel on last edited by
@stvfrnzl *excellent* thank you! (and @scottohara too)
-
Curtis Wilcoxreplied to Zach Leatherman :11ty: last edited by
@zachleat
Also not in web component form but this is my take on a spoiler pattern.`visibility: hidden` keeps the content hidden from everyone until it's used.
-
Zach Leatherman :11ty:replied to Curtis Wilcox last edited by
@cwilcox808 @stvfrnzl @scottohara oh my this code would be excellent for a web component (would have the extra benefit of for-free init for any later injected content too)
-
Curtis Wilcoxreplied to Zach Leatherman :11ty: last edited by
@zachleat
Here's a web component version. I fumbled my way through making this custom element by cribbing from from others.Using :has() with :host didn't seem to work so I'm glad I had already included a fallback for browsers that didn't support it.
Because of the click listener, I wouldn't use it for interactive content though links should be fine.
https://codepen.io/ccwilcox/pen/ZEgKvea
@stvfrnzl @scottohara -
Zach Leatherman :11ty:replied to Curtis Wilcox last edited by
@cwilcox808 @stvfrnzl @scottohara oh my—you went much deeper than I expected! nice work! I was just expecting a super simple custom element with light dom
-
Curtis Wilcoxreplied to Zach Leatherman :11ty: last edited by
@zachleat
Yeah, I took it as an opportunity to try making one that used Shadow DOM.Now I've made a lowest effort Light DOM version, it only replaces the querySelectorAll() and forEach() calls with creating the class and defining the element.
I also made a collection for the 'pens (including a fork of Scott's). I want to do at least one more variant, a Light DOM version that at least adds the button for you.
https://codepen.io/ccwilcox/pen/QWegKEy
-
Zach Leatherman :11ty:replied to Curtis Wilcox last edited by
@cwilcox808 @stvfrnzl @scottohara excellent work!