question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Doesn't work on iOS when nesting the elements within the label element

See original GitHub issue

It doesn’t work properly on iOS when nesting the elements within the label element.

This is the code

<label for="text-field">
  From <span aria-hidden="true">*</span>
  <input id="text-field" type="text" class="" placeholder="Departure airport" value="" list="airports" required aria-required="true">
  <datalist id="airports" title="Choose an aiport">
      <option value="Bologna, Guglielmo Marconi [BLQ] (ITALIA)">
      <option value="Dubai, Al Maktoum Intl [DWC] (EMIRATI ARABI)">
      <option value="Roma, Fiumicino [FCO] (ITALIA)">
      <option value="New York Ny, John F Kennedy Intl [JFK] (STATI UNITI)">
      <option value="Parigi, Charles De Gaulle [CDG] (FRANCIA)">
      <option value="Berlino, Schoenefeld [SXF] (GERMANIA)">
      <option value="Londra, Heathrow [LHR] (REGNO UNITO)">
  </datalist>
</label>

I noticed that the select appears behind the keyboard, but if I put the datalist out of label it works. Ok I tried to modify the markup also on the demo page and I confirm you that if datalist is inside label (and for my needs I have to do in this way), it doesn’t work.

Any suggestions?

polyfill

JS Bin: https://output.jsbin.com/solopuq

_Originally posted by @acespace90 in https://github.com/mfranzke/datalist-polyfill/issues/43#issuecomment-431312871_

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mfranzkecommented, Nov 7, 2018

@acespace90, what I meant by my previous post was that the label shouldn’t include the datalist element in general (and from my perspective even also it doesn’t need to include input elements, but that’s another discussion).

Even on the „simple“ solution (and not using my polyfill at all) provided within the W3C specs to wrap the option elements within the datalist by a select you would face the same issue that you’ve reported on iOS - so this is what I wanted to reflect by providing their HTML code within that JSbin: https://jsbin.com/fegojipiqi/1/edit?html The reason why is that „interactive content“ shouldn’t be placed into label elements, compare to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label#Interactive_content

This would be a working JSBin with the datalist outside of the label element: https://jsbin.com/cufelutulo/edit?html

0reactions
mfranzkecommented, Nov 7, 2018

Mentioned the aspect of not to include the datalist within the label within the readme file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should I put input elements inside a label element?
Nesting the input inside the label preserves the maximum clickable area, giving maximum accessibility even for users that struggle with precise mouse or...
Read more >
The Label element - HTML: HyperText Markup Language | MDN
To explicitly associate a <label> element with an <input> element, you first need to add the id attribute to the <input> element.
Read more >
Common Accessibility Element Pitfalls and How to Avoid Them
An interesting issue involving nesting accessibility elements. You can find examples of the concepts discussed in this post (and much more) ...
Read more >
Trying to nest an input element within a label element but not ...
Tell us what's happening: I was able to add the <input> box on the same line with the label. But my code doesn't...
Read more >
HTML Inputs and Labels: A Love Story | CSS-Tricks
Each separate input element should only be paired with one label. And a label should only be ... Don't add elements like headings...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found