Device-Bugs icon indicating copy to clipboard operation
Device-Bugs copied to clipboard

iOS: input labels don't focus on associated fields

Open bradfrost opened this issue 13 years ago • 5 comments
trafficstars

Summary

Tapping a label doesn't put focus in the associated input field in iOS.

Platforms

iOS

How to Reproduce

Add
<label for="field">Label</label> <input id="field" type="text" />

In normal browsers, clicking on the label will focus you in the associated field declared by the for attribute. However, tapping the label in iOS does nothing.

Reduced Example

http://bradfrostweb.com/demo/ios-focus/

Workarounds

Adding a script: How to fix the broken iPad form label click issue

bradfrost avatar Mar 26 '12 19:03 bradfrost

This one is a real pain for checkboxes and radiobuttons because the label doesn't toggle the state of the controls. Sure makes hitting a native check or radio really tricky with a finger.

toddparker avatar Mar 26 '12 19:03 toddparker

This is not a bug.

Tapping a label and having the labelled control be activated is specified to be platform-dependent, because the behavior is supposed to match local platform conventions. Browsers on Windows differ from browsers on Mac which differ from mobile WebKit in this.

hober avatar Aug 27 '12 23:08 hober

This behavior may not be part of the spec, but it is convention on all other browsers. It's mystifying that a touch based browser like mobile Webkit would break with convention to make it more difficult to tap small UI elements like checkboxes and radiobuttons. What could be the rationale?

toddparker avatar Aug 28 '12 01:08 toddparker

There is a workaround - adding an empty 'onclick' to a parent element worked for me. More ideas here: http://stackoverflow.com/questions/5421659/html-label-command-doesnt-work-in-iphone-browser

johnholtripley avatar Aug 28 '12 13:08 johnholtripley

It seems that in iOS 7 this behavior has been fixed. In your example both labels work identically for me (iOS 7.1.2 on iPad Mini 1).

SelenIT avatar Sep 28 '14 08:09 SelenIT