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

Limit resize notifications #31

Merged
merged 4 commits into from
Nov 3, 2017
Merged
Changes from 2 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
51 changes: 50 additions & 1 deletion cosmoz-tabbable-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
opts = {node: item, bubbles: false };

if (index > -1) {
this.async(this.notifyResize);
this.async(this._notifyTabResize);

if (!item._previouslySelected) {
this.fire('tab-first-select', {}, opts);
Expand Down Expand Up @@ -210,7 +210,56 @@

_normalizeValue: function (value) {
return this.attrForSelected ? value : isNaN(value) || value === null ? value : Number(value);
},

/**
* True if the current element is visible.
*/
get _isVisible() {
return Boolean(this.offsetWidth || this.offsetHeight);
},

_onDescendantIronResize(event) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Redefining _onDescendantIronResize in tabbable behavior is a bit confusing.
Because, looking at cosmoz-tab behaviors:

behaviors: [
	Cosmoz.TabbableBehavior,
	Cosmoz.TabbedBehavior
],

one might think this overridden method will also apply to cosmoz-tab, which is not the case (because the last behavior takes precedence).

So because tabbable behavior is shared between cosmoz-tabs and cosmoz-tab, it would be much clearer if _onDescendantIronResize was redefined in cosmoz-tabs.

if (this._notifyingDescendant || !this._isVisible) {
event.stopPropagation();
return;
}
const ev = Polymer.dom(event),
item = ev.localTarget,
index = this.items.indexOf(item);

if (index < 0 || !item.isSelected) {
event.stopPropagation();
return;
}

if (!Polymer.Settings.useShadow) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If redefining _onDescendantIronResize, maybe you should consider this PR PolymerElements/iron-resizable-behavior#35

this._fireResize();
}
},

resizerShouldNotify(resizable) {
return resizable.is === 'paper-tabs' || resizable.isSelected;
},

_notifyTabResize() {
if (!this.isAttached) {
return;
}

this._interestedResizables.forEach(resizable => {
if (this.resizerShouldNotify(resizable)) {
this._notifyDescendant(resizable);
}
});

if (!this._isVisible) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be also possible to not notify descendants when this._isVisible is false ?

// Fire resize on tab change only if this element is visible
return;
}
this._fireResize();
}

};

/** @polymerBehavior */
Expand Down