The datalist element on iOS

The datalist element is good. It was a bit bumpy there for a while, but browser implementations have improved over time. Now it’s by far the simplest and most robust way to create an autocompleting combobox widget.

Hook up an input element with a datalist element using the list and id attributes and you’re done. You can even use a bit of Ajax to dynamically update the option elements inside the datalist in response to the user’s input. The browser takes care of all the interaction. If you try to roll your own combobox implementation, it’s almost certainly going to involve a lot of JavaScript and still probably won’t account for all use cases.

Safari on iOS—and therefore all browsers on iOS—didn’t support datalist for quite a while. But once it finally shipped, it worked really nicely. The options showed up just like automplete suggestions above the keyboard.

But that broke a while back.

The suggestions still appeared, but if you tapped on one of them, nothing happened. The input element didn’t get updated. You had to tap on a little downward arrow inside the input in order to see the list of options.

That was really frustrating for anybody on iOS using The Session. By far the most common task on the site is searching for a tune, something that’s greatly (progressively) enhanced with a dynamically-updating datalist.

I just updated to iOS 18 specifically to see if this bug has been fixed, and it has:

Fixed updating the input value when selecting an option from a datalist element.

Hallelujah!

But now there’s some additional behaviour that’s a little weird.

As well as showing the options in the autocomplete list above the keyboard, Safari on iOS—and therefore all browsers on iOS—also pops up the options as a list (as if you had tapped on that downward arrow). If the list is more than a few options long, it completely obscures the input element you’re typing into!

I’m not sure if this is a bug or if it’s the intended behaviour. It feels like a bug, but I don’t know if I should file something.

For now, I’ve updated the datalist elements on The Session to only ever hold three option elements in order to minimise the problem. Seeing as the autosuggest list above the keyboard only ever shows a maximum of three suggestions anyway, this feels like a reasonable compromise.

Have you published a response to this? :

Responses

Curtis Wilcox

@adactio The datalist opening after typing feels like a bug only because I can’t reliably reproduce it. It happened the first time I tried it on a page but not since, even when I opened the page in a Private tab.

Tapping anywhere outside the list dismisses it and appears to restore the virtual keyboard. Typing further doesn’t make the list reappear.

2 Shares

# Shared by Baldur Bjarnason on Thursday, September 26th, 2024 at 3:42pm

# Shared by Alex Guyot on Thursday, September 26th, 2024 at 4:45pm

3 Likes

# Liked by Evil Jim O’Donnell on Thursday, September 26th, 2024 at 3:42pm

# Liked by Fernando Mateus on Friday, September 27th, 2024 at 11:09am

# Saturday, September 28th, 2024 at 2:48pm

Related posts

Displaying HTML web components

You might want to use `display: contents` …maybe.

Progressive disclosure defaults

If you’re going to toggle the display of content with CSS, make sure the more complex selector does the hiding, not the showing.

Declarative design

Defining the inputs instead of trying to control the outputs.

Accent all areas

A small but important addition to CSS.

Drag’n’drop revisited

An easy accessibility fix, courtesy of my past self.

Related links

Fine-tuning Text Inputs

Garrett talks through some handy HTML attributes: spellcheck, autofocus, autocapitalize, autocomplete, and autocorrect:

While they feel like small details, when we set these attributes on inputs, we streamline things for visitors while also guiding the browser on when it should just get out of the way.

Tagged with

SCALABLE: Save form data to localStorage and auto-complete on refresh

When I was in Amsterdam I was really impressed with the code that Rose was writing and I encouraged her to share it. Here it is: drop this script into a web page with a form to have its values automatically saved into local storage (and automatically loaded into the form if something goes wrong before the form is submitted).

Tagged with

Bring Focus to the First Form Field with an Error :: Aaron Gustafson

A handy little script from Aaron to improve the form validation experience.

Tagged with

The ‘Form’ Element Created the Modern Web. Was It a Big Mistake? | WIRED

Paul Ford:

The web was born to distribute information on computers, but the technology industry can never leave well enough alone. It needs to make everything into software. To the point that your internet browser is basically no longer a magical book of links but a virtual machine that can simulate a full-fledged computer.

Tagged with

Be the browser’s mentor, not its micromanager. - Build Excellent Websites

This one-page site that Andy has made to illustrate his talk at All Day Hey is exactly what I was talking about with declarative design.

Give the browser some solid rules and hints, then let it make the right decisions for the people that visit it, based on their device, connection quality and capabilities. This is how they will get a genuinely great user experience, rather than a fragmented, broken one.

Tagged with

Previously on this day

2 years ago I wrote Design systems thinking

Do you have a design system or do you have a design analytical?

8 years ago I wrote Indie Web Camp Brighton 2016

A jolly weekend of talking and making.

12 years ago I wrote RoboHornet’s nest

For shame, Microsoft.

14 years ago I wrote Rockwellian

Sound and vision.

17 years ago I wrote Amazapple

MP3 - DRM = good for you and good for me.

19 years ago I wrote Belgium, man, Belgium

While I was away in Florida, an opportunity arose for a Salter Cane concert. We were offered the support slot for Holly Golightly.

20 years ago I wrote So far, far away, so close

I’ve spent the last week re-living my childhood.

22 years ago I wrote The Electric Ballroom

It’s been quite a busy week for me.