
Glossary Web Component
Glossary Web Component êŽë š
Iâve added a secret glossary to my blog! You might find it by hovering over special links. Donât tell anyone, itâs a secret. At least until I can find a way to style the links without them being a distraction. Do I need to, or can they remain easter eggs[1]?
The Idea
This project came about when I noted concern over my reliance on MDN[2]. I always favour MDN over other sources. Iâm lazy. I feel guilty for not linking to the small web, the indie web, the weird web. At first I banned myself from linking to MDN. Later I mulled over the glossary idea. I think Iâve solved it!
The Implementation
I write my blog posts in Markdown[3]. For new glossary terms I now link to a placeholder rather than an external source. For example:
[React](/glossary/react.json)
This references a JSON[4] file that has the following format:
{
"title": "React",
"description": "A legacy JavaScript framework (turned religion). Favoured by tech bros and famous for bloated bundles and crippling web performance.",
"links": [
{
"name": "JSX.lol",
"title": "Does anybody actually like React?",
"url": "https://jsx.lol"
},
{
"name": "React",
"url": "https://react.dev"
}
]
}
My build script replaces the markdown link with a web component[5]:
<glossary-term id="--term-react">
<a href="https://jsx.lol">React</a>
</glossary-term>
The first link in the JSON is used as the canonical source.
HTML wrapped in a custom element[6] is a perfect example of progressive enhancement[^7]. For unsupported browsers there is still an accessible link inside. For browsers that support the Popover API[^8] each <glossary-term> element is enhanced with a fancy popover.
[^7] The front-end practice of building an accessible baseline with extra features and functionality defined by browser capabilities. The antithesis of React.
[^8] A mechanism for top-layer accessible components. Popovers can be implemented declaratively in HTML (yay!) or with JavaScript (boo!)
If youâve missed every example so far here is the React[7] link.
I captured a screen recording of how it should appear:
The popover is activated by either hover or keyboard focus. The escape key can also dismiss them. For touchscreens Iâm going to test that liveâŠ
~[INSERT TEST RESULTS]~
Test results
it works fine. If youâve got one of those new Apple Pencils â the new new one, not the new old one â the hover effect is magical. Touch taps are taken straight to the canonical link. The popover might be open upon return. Maybe I should cancel the popover based on touch events to avoid confusion?
Failures
Initially I tried to use CSS anchor positioning[8].
I really tried. It left me in tears and I rage quit. It might be the most unintuitive, doesnât work like it says, infuriating web âstandardâ ever. When anchoring a popover itâs impossible to ensure elements stay inside the viewport (without JavaScript). Please prove me wrong!
I tried to get creative with view transitions[9] and failed. Safari had some pixel-shifting jank going on. I tried normal transitions with allow-discrete and @starting-style and failed. In an isolated demo itâs all gravy but together this new CSS stuff doesnât plays nice. Itâs not all baseline[10] yet so letâs hope it improves. đ€
CSS anchors are Chrome and Chrome derivatives (ungoogled-software/ungoogled-chromium)[11] only right now. Safari Technical Preview claims to have support but Apple lies under oath so who knows?
Ultimately I gave up and used JavaScript[12] to calculate position so I can support all browsers. Iâll recharge morale and tackle a v2.0 at a later date.
Bookmarking
I donât plan to immediately retrofit older blog posts with glossary links. Although that could be a quick find & replace if Iâm careful. Iâm looking for positive feedback before I do. So let me know if you like it (or not). If no one hates it Iâll plough ahead, because I like it. This glossary may just be the third incarnation of my bookmarks blog.
Iâm tempted to use a similar technique to create popover cards for linked notes. They have more content so I need to consider that more.
Sources on 'MDN Web Docs'(2)
Sources on 'Markdown'(3)
Sources on 'Web Component'(5)
Sources on 'Progressive Enhancement'(7)
Sources on 'Popover API'(8)
Sources on 'React'(9)
Sources on 'CSS Anchor Positioning'(10)
Sources on 'Baseline'(12)
Sources on 'Chrome'(13)
Sources on 'JavaScript'(14)
A hidden message or feature covered in less chocolate than last year due to shrinkflation. â©ïž
The GOAT resource for web standards documentation, API references, developer guides, and an entire section on accessibility youâve never read. â©ïž
A simple plain text markup language created by John Gruber and bastardised by everyone else. Designed for writers who enjoy teeny-weeny font sizes. â©ïž
JavaScript Object Notation. An almost perfect specification. If only theyâd allowed trailing commas. â©ïž
A combination of web APIs including custom elements, shadow DOM, HTML templates, and good times. â©ïž
An extension of HTML with behaviour defined by the developer. Shadow DOM allows for encapsulation. Bring your own tag! It must be hyphenated. â©ïž
React: A legacy JavaScript framework (turned religion). Favoured by tech bros and famous for bloated bundles and crippling web performance. â©ïž
CSS Anchor Positioning: An indecipherable jumble of keywords that may or may not tether elements to one another. â©ïž
View Transition: Yet another web standard API for animations and transitions. Theyâve become exceeding efficient at it. â©ïž
Baseline: A summary of web platform support across browsers based on spurious self-reporting and lack of real-world testing. Invented by Big Browser. â©ïž
One browser to rule them all, one browser to find them, one browser to bring them all, and in the darkness bind them. â©ïž
[object Object] â©ïž