Skip to content

Redo api row #1923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/components/api-token-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ export default Component.extend({
serverError: null,

didInsertElement() {
if (this.get('api_token.isNew')) {
this.$('input').focus();
let input = this.element.querySelector('input');
if (input && input.focus) {
input.focus();
}
},

Expand Down
6 changes: 4 additions & 2 deletions app/templates/components/api-token-row.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
placeholder="New token name"
disabled=api_token.isSaving
value=api_token.name
autofocus=true
enter="saveToken"}}
autofocus="autofocus"
enter="saveToken"
data-test-focused-input=true
}}
{{else}}
{{ api_token.name }}
{{/if}}
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/components/api-token-row-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Component | api-token-row', function(hooks) {
setupRenderingTest(hooks);

test('input is focused if token is new', async function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });
this.set('api_token', {
isNew: true,
});

await render(hbs`{{api-token-row api_token=api_token}}`);
assert.dom('[data-test-focused-input]').isFocused();
});
});