diff --git a/app/components/api-token-row.js b/app/components/api-token-row.js index eb8255a63ef..9c628e44148 100644 --- a/app/components/api-token-row.js +++ b/app/components/api-token-row.js @@ -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.focus) { + input.focus(); } }, diff --git a/app/components/crate-readme.js b/app/components/crate-readme.js index afe36ac80c5..a22e17c0283 100644 --- a/app/components/crate-readme.js +++ b/app/components/crate-readme.js @@ -2,18 +2,12 @@ import Component from '@ember/component'; export default Component.extend({ rendered: '', + didRender() { this._super(...arguments); - this.$('pre > code').each(function() { - window.Prism.highlightElement(this); - }); - this.scrollToFragment(); - }, - scrollToFragment() { - if (location.hash) { - let anchor_id = location.hash.substr(1); - document.getElementById(anchor_id).scrollIntoView(); - } + this.element.querySelectorAll('pre > code').forEach(function(node) { + window.Prism.highlightElement(node); + }); }, }); diff --git a/app/components/rl-dropdown.js b/app/components/rl-dropdown.js index be9b398f7a7..f0752a797f5 100644 --- a/app/components/rl-dropdown.js +++ b/app/components/rl-dropdown.js @@ -1,7 +1,6 @@ import Component from '@ember/component'; import { alias } from '@ember/object/computed'; import { computed } from '@ember/object'; -import $ from 'jquery'; import RlDropdownContainer from './rl-dropdown-container'; @@ -15,26 +14,17 @@ export default Component.extend({ isExpanded: alias('dropdownContainer.dropdownExpanded'), - closeOnChildClick: false, - - propagateClicks: true, - click(event) { - let closeOnChildClick = this.closeOnChildClick; - let propagateClicks = this.propagateClicks; - let $target = $(event.target); - let $c = this.$(); + let closeOnChildClick = 'a:link'; + let $target = event.target; + let $c = this.element; - if ($target !== $c) { - if ((closeOnChildClick === true || closeOnChildClick === 'true') && $target.closest($c).length) { - this.set('isExpanded', false); - } else if (closeOnChildClick && $target.closest(closeOnChildClick, $c).length) { - this.set('isExpanded', false); - } + if ($target === $c) { + return; } - if (propagateClicks === false || propagateClicks === 'false') { - event.stopPropagation(); + if ($target.closest(closeOnChildClick, $c).length) { + this.set('isExpanded', false); } }, }); diff --git a/app/templates/application.hbs b/app/templates/application.hbs index 7ceb2e7cc56..3f9fa6ca4f2 100644 --- a/app/templates/application.hbs +++ b/app/templates/application.hbs @@ -40,7 +40,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" id="doc-links" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" id="doc-links" class="dropdown"}}
  • Getting Started
  • Guide
  • Specifying Dependencies
  • @@ -66,7 +66,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown current-user-links" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown current-user-links"}}
  • {{#link-to 'dashboard'}}Dashboard{{/link-to}}
  • {{#link-to 'me'}}Account Settings{{/link-to}}
  • {{#link-to 'me.pending-invites'}}Owner Invites{{/link-to}}
  • @@ -87,7 +87,7 @@ Menu {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName='ul' class='dropdown current-user-links' closeOnChildClick='a:link'}} + {{#rl-dropdown tagName='ul' class='dropdown current-user-links'}}
  • {{#link-to "crates"}}Browse All Crates{{/link-to}}
  • {{#if session.currentUser}}
  • {{#link-to 'dashboard'}}Dashboard{{/link-to}}
  • diff --git a/app/templates/categories.hbs b/app/templates/categories.hbs index b3ae63b6e5e..84541644726 100644 --- a/app/templates/categories.hbs +++ b/app/templates/categories.hbs @@ -23,7 +23,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params sort="alpha")}} Alphabetical diff --git a/app/templates/category/index.hbs b/app/templates/category/index.hbs index 537ce8c60d8..a5dc2aa3ca0 100644 --- a/app/templates/category/index.hbs +++ b/app/templates/category/index.hbs @@ -56,7 +56,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params sort="alpha")}} Alphabetical diff --git a/app/templates/components/api-token-row.hbs b/app/templates/components/api-token-row.hbs index 8eeaf0a4dfa..03ad410e751 100644 --- a/app/templates/components/api-token-row.hbs +++ b/app/templates/components/api-token-row.hbs @@ -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}} diff --git a/app/templates/crates.hbs b/app/templates/crates.hbs index bca965170e6..c9d2f7d77fc 100644 --- a/app/templates/crates.hbs +++ b/app/templates/crates.hbs @@ -44,7 +44,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params page=1 sort="alpha")}} Alphabetical diff --git a/app/templates/keyword/index.hbs b/app/templates/keyword/index.hbs index dccefc5fe28..f6a4f69f276 100644 --- a/app/templates/keyword/index.hbs +++ b/app/templates/keyword/index.hbs @@ -24,7 +24,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params sort="alpha")}} Alphabetical diff --git a/app/templates/keywords.hbs b/app/templates/keywords.hbs index 10751d85297..3e6ec64ea9e 100644 --- a/app/templates/keywords.hbs +++ b/app/templates/keywords.hbs @@ -23,7 +23,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params sort="alpha")}} Alphabetical diff --git a/app/templates/me/crates.hbs b/app/templates/me/crates.hbs index c5dfd9e7041..526b4441532 100644 --- a/app/templates/me/crates.hbs +++ b/app/templates/me/crates.hbs @@ -25,7 +25,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params sort="alpha")}} Alphabetical diff --git a/app/templates/me/following.hbs b/app/templates/me/following.hbs index de3047b1a8e..3ba95f6d3d6 100644 --- a/app/templates/me/following.hbs +++ b/app/templates/me/following.hbs @@ -23,7 +23,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params sort="alpha")}} Alphabetical diff --git a/app/templates/search.hbs b/app/templates/search.hbs index 89282b73454..35ba03851b0 100644 --- a/app/templates/search.hbs +++ b/app/templates/search.hbs @@ -36,7 +36,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params page=1 sort="relevance")}} Relevance diff --git a/app/templates/team.hbs b/app/templates/team.hbs index d0821752c04..cddc243c0f4 100644 --- a/app/templates/team.hbs +++ b/app/templates/team.hbs @@ -39,7 +39,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params sort="alpha")}} Alphabetical diff --git a/app/templates/user.hbs b/app/templates/user.hbs index be98992d829..b61f30f6e0c 100644 --- a/app/templates/user.hbs +++ b/app/templates/user.hbs @@ -30,7 +30,7 @@ {{/rl-dropdown-toggle}} - {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}} + {{#rl-dropdown tagName="ul" class="dropdown"}}
  • {{#link-to (query-params sort="alpha")}} Alphabetical diff --git a/tests/integration/components/api-token-row-test.js b/tests/integration/components/api-token-row-test.js new file mode 100644 index 00000000000..e02f4469acd --- /dev/null +++ b/tests/integration/components/api-token-row-test.js @@ -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(); + }); +});