Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/opened-binding'
Browse files Browse the repository at this point in the history
  • Loading branch information
bicknellr committed Apr 24, 2017
2 parents b1fd199 + 3559c51 commit bf6ce10
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 12 deletions.
20 changes: 8 additions & 12 deletions paper-submenu.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,30 +131,23 @@
* Expand the submenu content.
*/
open: function() {
if (!this.disabled && !this._active) {
this.$.collapse.show();
this._active = true;
this.__trigger && this.__trigger.classList.add('iron-selected');
this.__content && this.__content.focus();
if (!this.disabled) {
this.opened = true;
}
},

/**
* Collapse the submenu content.
*/
close: function() {
if (this._active) {
this.$.collapse.hide();
this._active = false;
this.__trigger && this.__trigger.classList.remove('iron-selected');
}
this.opened = false;
},

/**
* Toggle the submenu.
*/
toggle: function() {
if (this._active) {
if (this.opened) {
this.close();
} else {
this.open();
Expand All @@ -175,8 +168,11 @@
*/
_openedChanged: function(opened, oldOpened) {
if (opened) {
this.__trigger && this.__trigger.classList.add('iron-selected');
this.__content && this.__content.focus();
this.fire('paper-submenu-open');
} else if (oldOpened != null) {
this.__trigger && this.__trigger.classList.remove('iron-selected');
this.fire('paper-submenu-close');
}
},
Expand Down Expand Up @@ -206,7 +202,7 @@
*/
_disabledChanged: function(disabled) {
Polymer.IronControlState._disabledChanged.apply(this, arguments);
if (disabled && this._active) {
if (disabled && this.opened) {
this.close();
}
},
Expand Down
82 changes: 82 additions & 0 deletions test/paper-submenu.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@
</template>
</test-fixture>

<test-fixture id="opened">
<template>
<paper-menu>
<paper-submenu class="menu-content" opened>
<paper-item class="menu-trigger">My submenu is opened to start!</paper-item>
<paper-menu class="menu-content">
<paper-item>Triggered item</paper-item>
</paper-menu>
</paper-submenu>
</paper-menu>
</template>
</test-fixture>

<script>

suite('<paper-submenu>', function() {
Expand Down Expand Up @@ -197,6 +210,75 @@
});
});

suite('<paper-submenu opened>', function() {
var opened;
var submenu;
var collapse;

var fail = function(msg) {
return function() {
throw new Error(msg);
};
};

setup(function() {
opened = fixture('opened');
submenu = opened.querySelector('paper-submenu');
collapse = Polymer.dom(submenu.root).querySelector('iron-collapse');
});

test('opened binding + .menu-trigger tap', function() {
assert.isTrue(submenu.opened);

var trigger = submenu.querySelector('.menu-trigger');
MockInteractions.tap(trigger);
assert.isFalse(submenu.opened);

MockInteractions.tap(trigger);
assert.isTrue(submenu.opened);
});

test('opened binding + open()/close()', function() {
assert.isTrue(submenu.opened);

submenu.close();
assert.isFalse(submenu.opened);
assert.isFalse(collapse.opened);

submenu.open();
assert.isTrue(submenu.opened);
assert.isTrue(collapse.opened);
});

test('opened binding + toggle()', function() {
assert.isTrue(submenu.opened);

submenu.toggle();
assert.isFalse(submenu.opened);
assert.isFalse(collapse.opened);

submenu.toggle();
assert.isTrue(submenu.opened);
assert.isTrue(collapse.opened);
});

test('opened binding + open() x 2', function() {
assert.isTrue(submenu.opened);

opened.addEventListener('paper-submenu-open', fail('duplicate open'));

submenu.open(); // Opening when already opened should not fire().
});

test('opened binding + close() x 2', function() {
submenu.close();
assert.isFalse(submenu.opened);

opened.addEventListener('paper-submenu-close', fail('duplicate close'));

submenu.close(); // Closing again when !opened should not fire().
});
});
</script>

</body>
Expand Down

0 comments on commit bf6ce10

Please sign in to comment.