mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Merge pull request #4872 from jaswilli/autofocus
Do not add autofocus attribute unless set to focus
This commit is contained in:
commit
950f9c29b3
2 changed files with 30 additions and 4 deletions
|
@ -5,16 +5,20 @@ var TrimFocusInput = Ember.TextField.extend({
|
||||||
attributeBindings: ['autofocus'],
|
attributeBindings: ['autofocus'],
|
||||||
|
|
||||||
autofocus: Ember.computed(function () {
|
autofocus: Ember.computed(function () {
|
||||||
|
if (this.get('focus')) {
|
||||||
return (device.ios()) ? false : 'autofocus';
|
return (device.ios()) ? false : 'autofocus';
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}),
|
}),
|
||||||
|
|
||||||
setFocus: function () {
|
didInsertElement: function () {
|
||||||
// This fix is required until Mobile Safari has reliable
|
// This fix is required until Mobile Safari has reliable
|
||||||
// autofocus, select() or focus() support
|
// autofocus, select() or focus() support
|
||||||
if (this.focus && !device.ios()) {
|
if (this.get('focus') && !device.ios()) {
|
||||||
this.$().val(this.$().val()).focus();
|
this.$().val(this.$().val()).focus();
|
||||||
}
|
}
|
||||||
}.on('didInsertElement'),
|
},
|
||||||
|
|
||||||
focusOut: function () {
|
focusOut: function () {
|
||||||
var text = this.$().val();
|
var text = this.$().val();
|
||||||
|
|
|
@ -15,4 +15,26 @@ describeComponent('gh-trim-focus-input', function () {
|
||||||
component.$().focusout();
|
component.$().focusout();
|
||||||
expect(component.$().val()).to.equal('some random stuff');
|
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;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue