From 69662bd5d2c7ea6ea8e46675bcf1ed912c8eb174 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Sun, 30 Nov 2014 11:27:09 -0800 Subject: [PATCH] gh-trim-focus-input autofocus fix for iOS Safari MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #4446 - Mobile Safari doesn’t support the HTML5 `autofocus` attribute, but also doesn’t play nice with jQuery’s `focus()` and `select()` methods. - Mobile Safari wouldn’t automatically select the input field anyway, so this PR simply removes the “jumping input fields” error without changing any actual behaviour. - Disallowing the programmatic selection of input fields (with select, focus or similar methods) is apparently considered a feature rather than a bug (ref http://bugs.jquery.com/ticket/12789) - `autofocus` attribute is now only set on non-iOS devices --- core/client/components/gh-trim-focus-input.js | 11 ++++++++++- core/client/templates/signin.hbs | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/client/components/gh-trim-focus-input.js b/core/client/components/gh-trim-focus-input.js index 7e9b53b30c..4e69b7c36b 100644 --- a/core/client/components/gh-trim-focus-input.js +++ b/core/client/components/gh-trim-focus-input.js @@ -1,8 +1,17 @@ +/*global device*/ var TrimFocusInput = Ember.TextField.extend({ focus: true, + attributeBindings: ['autofocus'], + + autofocus: Ember.computed(function () { + return (device.ios()) ? false : 'autofocus'; + }), + setFocus: function () { - if (this.focus) { + // This fix is required until Mobile Safari has reliable + // autofocus, select() or focus() support + if (this.focus && !device.ios()) { this.$().val(this.$().val()).focus(); } }.on('didInsertElement'), diff --git a/core/client/templates/signin.hbs b/core/client/templates/signin.hbs index a138583728..f225774759 100644 --- a/core/client/templates/signin.hbs +++ b/core/client/templates/signin.hbs @@ -2,7 +2,7 @@