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

feat(use defaults for hideOn/showOn when passed undefined) #88

Merged
merged 1 commit into from
Nov 23, 2017
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
![Download count all time](https://img.shields.io/npm/dt/ember-attacher.svg)
[![npm](https://img.shields.io/npm/dm/ember-attacher.svg)]()
[![Ember Observer Score](http://emberobserver.com/badges/ember-attacher.svg)](http://emberobserver.com/addons/ember-attacher)
[![Build Status](https://travis-ci.org/kybishop/ember-attacher.svg)](https://travis-ci.org/kybishop/ember-attacher)
[![Build Status](https://travis-ci.org/kybishop/ember-attacher.svg?branch=master)](https://travis-ci.org/kybishop/ember-attacher)

Tooltips and popovers made easy.
Just drop an `{{#attach-tooltip}} or `{{#attach-popover}}` in a parent and your popper is ready to go!
Expand Down
10 changes: 7 additions & 3 deletions addon/components/attach-popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export default Component.extend({
}),

_hideOn: computed('hideOn', function() {
return this.get('hideOn').split(' ');
const hideOn = this.get('hideOn');

return hideOn === null ? [] : (hideOn || DEFAULTS.hideOn).split(' ');
}),

_modifiers: computed('arrow', 'flip', 'modifiers', function() {
Expand Down Expand Up @@ -146,12 +148,14 @@ export default Component.extend({
}
},

_shouldRender: computed('lazyRender', function() {
_shouldRender: computed.not('lazyRender', function() {
return !this.get('lazyRender');
}),

_showOn: computed('showOn', function() {
return this.get('showOn').split(' ');
const showOn = this.get('showOn');

return showOn === null ? [] : (showOn || DEFAULTS.showOn).split(' ');
}),

_transitionDuration: 0,
Expand Down
16 changes: 11 additions & 5 deletions tests/integration/components/ember-attacher/is-shown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test('isShown works with showOn/hideOn set to "click"', async function(assert) {
assert.equal(isVisible(attachment), true, 'Shown again after click');
});

test('isShown works with showOn/hideOn set to "none"', async function(assert) {
test('isShown works with showOn/hideOn set to `null`', async function(assert) {
assert.expect(3);

this.on('closePopover', () => {
Expand All @@ -49,14 +49,17 @@ test('isShown works with showOn/hideOn set to "none"', async function(assert) {

this.set('isShown', false);

this.set('hideOn', null);
this.set('showOn', null);

this.render(hbs`
<button id="open" {{action 'openPopover'}}>
Click me, captain!

{{#attach-popover id='attachment'
hideOn='none'
hideOn=hideOn
isShown=isShown
showOn='none'}}
showOn=showOn}}
isShown w/ hideOn/ShowOn of 'none'

<button id="close" {{action 'closePopover'}}>
Expand Down Expand Up @@ -95,6 +98,9 @@ test('nested attachers open and close as expected', async function(assert) {
this.set('childIsShown', true);
});

this.set('hideOn', null);
this.set('showOn', null);

this.setProperties({
childIsShown: false,
parentIsShown: false
Expand All @@ -104,10 +110,10 @@ test('nested attachers open and close as expected', async function(assert) {
<button id="openParent" {{action 'openParentPopover'}}>
Open parent

{{#attach-popover hideOn='none'
{{#attach-popover hideOn=hideOn
id='parent'
isShown=parentIsShown
showOn='none'}}
showOn=showOn}}
<button id="openChild" {{action 'openChildPopover'}}>
Open child

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import hbs from 'htmlbars-inline-precompile';
import { find, focus } from 'ember-native-dom-helpers';
import { find, triggerEvent } from 'ember-native-dom-helpers';
import { isVisible } from 'ember-attacher';
import { moduleForComponent, test } from 'ember-qunit';

Expand All @@ -24,7 +24,7 @@ test('shows when the target gains focus', async function(assert) {

assert.equal(isVisible(attachment), false, 'Initially hidden');

await focus('#target');
await triggerEvent('#target', 'focus');

assert.equal(isVisible(attachment), true, 'Now shown');
});
64 changes: 64 additions & 0 deletions tests/integration/components/ember-attacher/show-on-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import hbs from 'htmlbars-inline-precompile';
import { click, find, triggerEvent } from 'ember-native-dom-helpers';
import { isVisible } from 'ember-attacher';
import { moduleForComponent, test } from 'ember-qunit';

moduleForComponent('ember-attacher', 'Integration | Component | showOn', {
integration: true
});

test('uses the defaults when passed `undefined`', async function(assert) {
assert.expect(4);

this.set('showOn', undefined);

this.render(hbs`
<button id="target">
{{#attach-popover id='attachment' hideOn='click' showOn=showOn}}
showOn mouseenter
{{/attach-popover}}
</button>
`);

const attachment = find('#attachment');

assert.equal(isVisible(attachment), false, 'Initially hidden');

await triggerEvent('#target', 'mouseenter');

assert.equal(isVisible(attachment), true, 'Now shown');

await click('#target');

assert.equal(isVisible(attachment), false, 'Hidden again');

await triggerEvent('#target', 'focus');

assert.equal(isVisible(attachment), true, 'Shown again');
});

test('sets showOn to an empty array when passed `null`', async function(assert) {
assert.expect(3);

this.set('showOn', null);

this.render(hbs`
<button id="target">
{{#attach-popover id='attachment' hideOn='click' showOn=showOn}}
showOn mouseenter
{{/attach-popover}}
</button>
`);

const attachment = find('#attachment');

assert.equal(isVisible(attachment), false, 'Initially hidden');

await triggerEvent('#target', 'mouseenter');

assert.equal(isVisible(attachment), false, 'Still hidden after mouseenter');

await triggerEvent('#target', 'focus');

assert.equal(isVisible(attachment), false, 'Still hidden after focus');
});