Skip to content

Replace jQuery animation for table of contents and remove jQuery package #771

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 3 commits into from
Aug 12, 2021
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
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = {
browser: true,
},
rules: {
'ember/no-jquery': 'off',
'no-console': 'off',
'ember/no-new-mixins': 'off',
'ember/no-mixins': 'off',
Expand Down
3 changes: 2 additions & 1 deletion app/components/table-of-contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import Component from '@ember/component';
export default Component.extend({
actions: {
toggle(type) {
this.$('ol.toc-level-1.' + type).slideToggle(200);
const tableElement = document.querySelector(`ol.toc-level-1.${type}`);
tableElement.classList.toggle('selected');
},
},
});
10 changes: 8 additions & 2 deletions app/styles/components/_sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,17 @@ li.toc-level-0 {
ol.toc-level-1 {
border-left: $base-border;
font-size: $base-font-size * 0.9;
transition: max-height 0.5s ease;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be animating height or max-height?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't actually use height. For the expanded condition, we would have to give height: auto and According to the Mozilla Developer Network docs, auto values have been intentionally excluded from the CSS transitions spec.
Source: https://css-tricks.com/using-css-transitions-auto-dimensions/


&:not(.selected) {
display: none;
&.selected{
max-height: 3000px;
}

&:not(.selected) {
overflow: hidden;
max-height: 0;
}

li {
border-left: 3px solid transparent;
transition: border-width $duration, margin-right $duration;
Expand Down
12 changes: 6 additions & 6 deletions app/templates/components/table-of-contents.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<ol class="toc-level-0">
<li class="toc-level-0">
<a {{action 'toggle' 'modules'}} href="#">Packages</a>
<ol class="toc-level-1 modules" style="display: block">
<a {{action 'toggle' 'modules'}} href="#" data-test-toc-title="packages">Packages</a>
<ol class="toc-level-1 modules selected">
{{#each moduleIDs as |moduleID|}}

{{#if (not-eq moduleID "@ember/object/computed")}}
Expand All @@ -16,8 +16,8 @@

{{#if isShowingNamespaces}}
<li class="toc-level-0">
<a {{action 'toggle' 'namespaces'}} href="#">Namespaces</a>
<ol class="toc-level-1 namespaces" style="display: block">
<a {{action 'toggle' 'namespaces'}} href="#" data-test-toc-title="namespaces">Namespaces</a>
<ol class="toc-level-1 namespaces selected">
{{#each namespaceIDs as |namespaceID|}}
<li class="toc-level-1" data-test-namespace={{namespaceID}}>
{{#link-to 'project-version.namespaces.namespace' version namespaceID}}{{namespaceID}}{{/link-to}}
Expand All @@ -28,8 +28,8 @@
{{/if}}

<li class="toc-level-0">
<a {{action 'toggle' 'classes'}} href="#">Classes</a>
<ol class="toc-level-1 classes" style="display: block">
<a {{action 'toggle' 'classes'}} href="#" data-test-toc-title="classes">Classes</a>
<ol class="toc-level-1 classes selected">
{{#each classesIDs as |classID|}}
<li class="toc-level-1" data-test-class={{classID}}>
{{#link-to 'project-version.classes.class' version classID}}{{classID}}{{/link-to}}
Expand Down
2 changes: 1 addition & 1 deletion config/optional-features.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"application-template-wrapper": false,
"default-async-observers": true,
"jquery-integration": true,
"jquery-integration": false,
"template-only-glimmer-components": true
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"test:ember": "ember test"
},
"devDependencies": {
"@ember/jquery": "^1.1.0",
"@ember/optional-features": "^2.0.0",
"@ember/test-helpers": "^2.2.5",
"@glimmer/component": "^1.0.4",
Expand Down
151 changes: 139 additions & 12 deletions tests/integration/components/table-of-contents-test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,157 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, findAll } from '@ember/test-helpers';
import { render, findAll, click } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

const TIMEOUT_FOR_ANIMATION = 600;
const CLASSES = ['Descriptor', 'Ember'];
const MODULES = ['@ember/application', '@ember/array'];

module('Integration | Component | table of contents', function (hooks) {
setupRenderingTest(hooks);

test('it renders', async function (assert) {
// Set any properties with this.set('myProperty', 'value');
this.set('projectId', 'Ember');
this.set('emberVersion', '2.4.3');
this.set('classesIDs', CLASSES);

await render(hbs`
{{
table-of-contents showPrivateClasses=true
projectid=projectId
version=emberVersion
classesIDs=classesIDs
isShowingNamespaces=true
}}
`);

const contentTitle = document.querySelector(
'[data-test-toc-title="classes"]'
);
const contentReference = '.toc-level-1';

assert.dom(contentTitle).hasText('Classes');
assert
.dom(`${contentReference} li`)
.exists({ count: 2 }, 'We have two items to display');
assert.dom(findAll(`${contentReference} li`)[0]).hasText(CLASSES[0]);
assert.dom(findAll(`${contentReference} li`)[1]).hasText(CLASSES[1]);
});

test('Starts with underlying content visible', async function (assert) {
// Set any properties with this.set('myProperty', 'value');
this.set('projectId', 'Ember');
this.set('emberVersion', '2.4.3');
this.set('moduleIDs', MODULES);

this.set('classesIDs', ['Descriptor', 'Ember']);
await render(hbs`
{{
table-of-contents showPrivateClasses=true
projectid=projectId
version=emberVersion
moduleIDs=moduleIDs
isShowingNamespaces=true
}}
`);

await render(hbs`{{table-of-contents showPrivateClasses=true
projectid=projectId
version=emberVersion
classesIDs=classesIDs
isShowingNamespaces=true
}}`);
const contentReference = '.toc-level-1';
const content = document.querySelector(contentReference);
const contentTitle = document.querySelector(
'[data-test-toc-title="classes"]'
);

assert.dom(findAll('.toc-level-0 > a')[2]).hasText('Classes');
assert.dom(contentTitle).hasText('Classes');
assert.dom(content).hasClass('selected');
assert
.dom('.toc-level-1 li')
.dom(`${contentReference} li`)
.exists({ count: 2 }, 'We have two items to display');
assert.dom(findAll('.toc-level-1 li')[0]).hasText('Descriptor');
assert.dom(findAll('.toc-level-1 li')[1]).hasText('Ember');
assert.dom(content).isVisible();
assert.dom(findAll(`${contentReference} li`)[0]).hasText(MODULES[0]);
assert.dom(findAll(`${contentReference} li`)[1]).hasText(MODULES[1]);
});

test('Underlying content hides once clicked', async function (assert) {
// Set any properties with this.set('myProperty', 'value');
this.set('projectId', 'Ember');
this.set('emberVersion', '2.4.3');
this.set('moduleIDs', MODULES);

await render(hbs`
{{
table-of-contents showPrivateClasses=true
projectid=projectId
version=emberVersion
moduleIDs=moduleIDs
isShowingNamespaces=true
}}
`);

const contentTitle = document.querySelector(
'[data-test-toc-title="packages"]'
);
const contentReference = '.toc-level-1';
const content = document.querySelector(contentReference);

assert.dom(contentTitle).hasText('Packages');
assert.dom(content).hasClass('selected');
assert.dom(content).isVisible();

await click(contentTitle);

const done = assert.async();
setTimeout(() => {
assert.dom(content).isNotVisible();
assert.dom(content).doesNotHaveClass('selected');
done();
}, TIMEOUT_FOR_ANIMATION);
});

test('Underlying content should be visible after 2 clicks', async function (assert) {
// Set any properties with this.set('myProperty', 'value');
this.set('projectId', 'Ember');
this.set('emberVersion', '2.4.3');
this.set('moduleIDs', MODULES);

await render(hbs`
{{
table-of-contents showPrivateClasses=true
projectid=projectId
version=emberVersion
moduleIDs=moduleIDs
isShowingNamespaces=true
}}
`);

const titleButton = document.querySelector(
'[data-test-toc-title="packages"]'
);
const contentReference = '.toc-level-1';
const content = document.querySelector(contentReference);

assert.dom(titleButton).hasText('Packages');
assert.dom(content).hasClass('selected');
assert.dom(content).isVisible();

await click(titleButton);

const done1 = assert.async();

setTimeout(async () => {
assert.dom(content).isNotVisible();
assert.dom(content).doesNotHaveClass('selected');

await click(titleButton);

const done2 = assert.async();

setTimeout(() => {
assert.dom(content).isVisible();
assert.dom(content).hasClass('selected');
done2();
}, TIMEOUT_FOR_ANIMATION);

done1();
}, TIMEOUT_FOR_ANIMATION);
});
});
Loading