Skip to content

Commit 6138687

Browse files
committed
Auto merge of #1923 - integer32llc:redo-api-row, r=carols10cents
Redo api row @locks I think this fixes the revoke button -- what I saw was `TypeError: input is null` on page load, when there isn't any input because a row hasn't been inserted yet. This reverts the reverts and adds a null check. r? @locks
2 parents 8f56f5f + df07a44 commit 6138687

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

app/components/api-token-row.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ export default Component.extend({
77
serverError: null,
88

99
didInsertElement() {
10-
if (this.get('api_token.isNew')) {
11-
this.$('input').focus();
10+
let input = this.element.querySelector('input');
11+
if (input && input.focus) {
12+
input.focus();
1213
}
1314
},
1415

app/templates/components/api-token-row.hbs

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
placeholder="New token name"
77
disabled=api_token.isSaving
88
value=api_token.name
9-
autofocus=true
10-
enter="saveToken"}}
9+
autofocus="autofocus"
10+
enter="saveToken"
11+
data-test-focused-input=true
12+
}}
1113
{{else}}
1214
{{ api_token.name }}
1315
{{/if}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { module, test } from 'qunit';
2+
import { setupRenderingTest } from 'ember-qunit';
3+
import { render } from '@ember/test-helpers';
4+
import hbs from 'htmlbars-inline-precompile';
5+
6+
module('Integration | Component | api-token-row', function(hooks) {
7+
setupRenderingTest(hooks);
8+
9+
test('input is focused if token is new', async function(assert) {
10+
// Set any properties with this.set('myProperty', 'value');
11+
// Handle any actions with this.set('myAction', function(val) { ... });
12+
this.set('api_token', {
13+
isNew: true,
14+
});
15+
16+
await render(hbs`{{api-token-row api_token=api_token}}`);
17+
assert.dom('[data-test-focused-input]').isFocused();
18+
});
19+
});

0 commit comments

Comments
 (0)