Displaying HTML web components

Those HTML web components I made for date inputs are very simple. All they do is slightly extend the behaviour of the existing input elements.

This would be the ideal use-case for the is attribute:

<input is="input-date-future" type="date">

Alas, Apple have gone on record to say that they will never ship support for customized built-in elements.

So instead we have to make HTML web components by wrapping existing elements in new custom elements:

<input-date-future>
  <input type="date">
<input-date-future>

The end result is the same. Mostly.

Because there’s now an additional element in the DOM, there could be unexpected styling implications. Like, suppose the original element was direct child of a flex or grid container. Now that will no longer be true.

So something I’ve started doing with HTML web components like these is adding something like this inside the connectedCallback method:

connectedCallback() {
    this.style.display = 'contents';
  …
}

This tells the browser that, as far as styling is concerned, there’s nothing to see here. Move along.

Or you could (and probably should) do it in your stylesheet instead:

input-date-future {
  display: contents;
}

Just to be clear, you should only use display: contents if your HTML web component is augmenting what’s within it. If you add any behaviours or styling to the custom element itself, then don’t add this style declaration.

It’s a bit of a hack to work around the lack of universal support for the is attribute, but it’ll do.

Have you published a response to this? :

Responses

akazzop

@adactio for whatever reasons browsers on ios (safari and firefox focus at least) tend to refuse opening the page :-/

# Posted by akazzop on Wednesday, April 17th, 2024 at 10:26am

Ryan Townsend

@adactio I really wish there was an `:custom-element` state selector in CSS so you could default all custom elements to `display: contents` and just override on a case-by-case basis.

(unfortunately `:defined` targets native elements too, otherwise `:defined, :not(:defined)` would work to target custom elements)

5 Likes

# Liked by Andrew Maier on Wednesday, April 17th, 2024 at 10:40am

# Liked by Jeff Triplett on Wednesday, April 17th, 2024 at 11:41am

# Liked by Warren Buckley on Wednesday, April 17th, 2024 at 7:36pm

# Liked by Elly Loel ✨🌱 on Wednesday, April 17th, 2024 at 10:29pm

# Liked by Jens Tangermann on Wednesday, April 17th, 2024 at 11:39pm

Related posts

Multi-page web apps

A question via email…

Progressive disclosure with HTML

The `details` element is like the TL;DR of markup.

Three attributes for better web forms

Better UX through better HTML: inputmode, enterkeyhint, and autocomplete.

Today, the distant future

2022 was once unimaginable to some web folks.

Accessibility testing

It’s not just about finding the issues—it’s about finding the issues at the right time.

Related links

a view source web

As a self-initiated learner, being able to view source brought to mind the experience of a slow walk through someone else’s map.

This ability to “observe” software makes HTML special to work with.

Tagged with

On Container Queries, Responsive Images, and JPEG-XL – Cloud Four

Container queries can’t be used in the sizes attribute for responsive images. Here, Jason breaks down why that is (spoiler: it’s the lookahead pre-parser) and segues into a truly long term solution: a “magical” image format.

If you’ve ever thought it felt weird to put media conditions inside the HTML for responsive images, this will resonate.

Tagged with

How to (not) make a button - Tomas Pustelnik’s personal website

A demonstration of how even reinventing a relatively simple wheel takes way more effort than it’s worth when you could just use what the brower gives you for free.

Tagged with

Will Serving Real HTML Content Make A Website Faster? Let’s Experiment! - WebPageTest Blog

Spoiler: the answer to the question in the title is a resounding “hell yeah!”

Scott brings receipts.

Tagged with

TIL: You Can Access A User’s Camera with Just HTML

The capture attribute is pretty nifty—and I just love that you get so much power in a declarative way:

<input type="file" accept="image/*" capture="environment">

Tagged with

Previously on this day

4 years ago I wrote Future Sync 2020

Questions and answers from the opening talk of an online conference.

6 years ago I wrote Technical balance

Why I had two technical editors working with me on Going Offline, with opposite levels of experience.

9 years ago I wrote 100 words 026

Day twenty six.

10 years ago I wrote Fragmentions

Deeper linking for deeper thinking.

11 years ago I wrote A dao revisited

Musing on a thirteen year old piece of writing on the web.

11 years ago I wrote Responsive workshopping

A half-day workshop I did at this year’s UX London.

15 years ago I wrote Blast from the past

When rabbit holes become memory holes.

16 years ago I wrote Iteration and You

Liveblogging a presentation by Daniel Burka at The Future of Web Design.

16 years ago I wrote From Design to Deployment

Liveblogging a presentation by Jon Hicks at The Future of Web Design.

16 years ago I wrote Print is the New Web

Liveblogging a talk by Elliot Jay Stocks at The Future of Web Design.

16 years ago I wrote Photoshop Battle

Liveblogging a Photoshop tennis match at the Future of Web Design.

16 years ago I wrote Getting Your Designs Approved

Liveblogging a presentation from Larissa Meek at the Future of Web Design.

16 years ago I wrote Demo hell

The air gets sucked out of the room at The Future of Web Design.

16 years ago I wrote The User Experience Curve

Liveblogging a talk from Andy Budd at The Future of Web Design in London.

16 years ago I wrote User Experience vs. Brand Experience

Liveblogging a session from Steven Pearce and Andy Clarke at the Future of Web Design.

18 years ago I wrote Bedroll

Not a blogroll.

22 years ago I wrote A thousand words

Jeb has posted some pictures of his trip to Europe.