Skip to content

Commit

Permalink
Do not add autofocus attribute unless set to focus
Browse files Browse the repository at this point in the history
No Issue
- Don't add the "autofocus" attribute to the input element unless
  the "focus" property is set to true.
  • Loading branch information
jaswilli committed Jan 30, 2015
1 parent aa4bcda commit db693b5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
12 changes: 8 additions & 4 deletions core/client/components/gh-trim-focus-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ var TrimFocusInput = Ember.TextField.extend({
attributeBindings: ['autofocus'],

autofocus: Ember.computed(function () {
return (device.ios()) ? false : 'autofocus';
if (this.get('focus')) {
return (device.ios()) ? false : 'autofocus';
}

return false;
}),

setFocus: function () {
didInsertElement: function () {
// This fix is required until Mobile Safari has reliable
// autofocus, select() or focus() support
if (this.focus && !device.ios()) {
if (this.get('focus') && !device.ios()) {
this.$().val(this.$().val()).focus();
}
}.on('didInsertElement'),
},

focusOut: function () {
var text = this.$().val();
Expand Down
22 changes: 22 additions & 0 deletions core/test/client/unit/components/gh-trim-focus-input_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,26 @@ describeComponent('gh-trim-focus-input', function () {
component.$().focusout();
expect(component.$().val()).to.equal('some random stuff');
});

it('does not have the autofocus attribute if not set to focus', function () {
var component = this.subject({
value: 'some text',
focus: false
});

this.render();

expect(component.$().attr('autofocus')).to.not.be.ok;
});

it('has the autofocus attribute if set to focus', function () {
var component = this.subject({
value: 'some text',
focus: true
});

this.render();

expect(component.$().attr('autofocus')).to.be.ok;
});
});

0 comments on commit db693b5

Please sign in to comment.