Skip to content
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

Disable tethering while tooltips are hidden #96

Merged
merged 3 commits into from
Oct 14, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 34 additions & 2 deletions addon/components/tooltip-and-popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,21 @@ export default EmberTetherComponent.extend({

/* Properties */

attributeBindings: ['aria-hidden', 'role', 'tabindex'],
attributeBindings: ['aria-hidden', 'role', 'tabindex', 'data-tether-enabled'],
classNameBindings: ['effectClass'],
classPrefix: 'ember-tooltip-or-popover',

_didUpdateTimeoutLength: 1000, // 1000 ms or 0 ms, depending whether in test mode
_hideTimer: null,
_showTimer: null,
_isTetherEnabled: true,

/* CPs */

'data-tether-enabled': computed('_isTetherEnabled', function() {
return this.get('_isTetherEnabled') ? 'true' : 'false';
}),

'aria-hidden': computed('isShown', function() {
return this.get('isShown') ? 'false' : 'true';
}),
Expand Down Expand Up @@ -240,6 +245,8 @@ export default EmberTetherComponent.extend({

this.set('isShown', false);
this.sendAction('onHide', this);

this.stopTether();
},

didInsertElement() {
Expand Down Expand Up @@ -298,6 +305,10 @@ export default EmberTetherComponent.extend({
}

this.set('offset', offset);

if (!this.get('isShown')) {
this.stopTether();
}
},

/*
Expand Down Expand Up @@ -327,6 +338,7 @@ export default EmberTetherComponent.extend({
const isShown = this.get('isShown');

if (isShown) {
this.startTether();
const duration = cleanNumber(this.get('duration'));

run.cancel(this.get('_hideTimer'));
Expand All @@ -342,10 +354,14 @@ export default EmberTetherComponent.extend({

this.set('_hideTimer', hideTimer);
}
} else {
this.stopTether();
}
}),

show() {
this.startTether();

// this.positionTether() fixes the issues raised in
// https://github.com/sir-dunxalot/ember-tooltips/issues/75
this.positionTether();
Expand Down Expand Up @@ -419,4 +435,20 @@ export default EmberTetherComponent.extend({
this.sendAction('onDestroy', this);
},

startTether() {
// can't depend on `_tether.enabled` because it's not an
// Ember property (so won't trigger cp update when changed)
Copy link
Contributor

Choose a reason for hiding this comment

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

good note

this.set('_isTetherEnabled', true);
this.get('_tether').enable();
},

stopTether() {
run.schedule('afterRender', () => {
// can't depend on `_tether.enabled` because it's not an
// Ember property (so won't trigger cp update when changed)
this.set('_isTetherEnabled', false);
this.get('_tether').disable();
});
}

});
14 changes: 14 additions & 0 deletions tests/helpers/sync/assert-visibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ export function assertHide(assert, context) {

}

export function assertTetherEnabled(assert, context) {

assert.equal(context.$().find('.ember-tooltip').attr('data-tether-enabled'), 'true',
'Should enable tether');

}

export function assertTetherDisabled(assert, context) {

assert.equal(context.$().find('.ember-tooltip').attr('data-tether-enabled'), 'false',
'Should disable tether');

}


export function assertPopoverShow(assert, context) {

Expand Down
10 changes: 7 additions & 3 deletions tests/integration/components/tooltip-is-visible-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Ember from 'ember';
import { moduleForComponent, test } from 'ember-qunit';
import { assertHide, assertShow } from '../../helpers/sync/assert-visibility';
import { assertHide, assertShow, assertTetherEnabled, assertTetherDisabled } from '../../helpers/sync/assert-visibility';
Copy link
Contributor

@a15n a15n Oct 12, 2016

Choose a reason for hiding this comment

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

I would recommend against creating a new assertion just for the tether. This means that people will always have to opt in to the coverage and will likely skip that test. Instead I would add the check as part of assertShow and assertHide. When I did this I found some holes in my enable/disable coverage

https://github.com/zenefits/ember-tooltips/pull/21/files#diff-c2e9fd979e3b24030663b2c4c84cd5beR3

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be blocking

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good point. I'll try split it (or make a new PR if you want to merge already).

Copy link
Contributor

Choose a reason for hiding this comment

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

If you could do it as part of this PR that'd be great. Thanks!

import hbs from 'htmlbars-inline-precompile';

const { run } = Ember;
Expand All @@ -11,38 +11,42 @@ moduleForComponent('tooltip-on-element', 'Integration | Option | isShown', {

test('It toggles with isShown', function(assert) {

assert.expect(2);
assert.expect(4);

this.set('showTooltip', true);

this.render(hbs`{{tooltip-on-element isShown=showTooltip}}`);

assertShow(assert, this);
assertTetherEnabled(assert, this);

run(() => {
this.set('showTooltip', false);
});

assertHide(assert, this);
assertTetherDisabled(assert, this);

});

test('It toggles with tooltipIsVisible', function(assert) {
// tooltipIsVisible is deprecated in favor of isShown
// tooltipIsVisible will be supported until v3.0.0

assert.expect(2);
assert.expect(4);

this.set('showTooltip', true);

this.render(hbs`{{tooltip-on-element tooltipIsVisible=showTooltip}}`);

assertShow(assert, this);
assertTetherEnabled(assert, this);

run(() => {
this.set('showTooltip', false);
});

assertHide(assert, this);
assertTetherDisabled(assert, this);

});