From 185b065d6ced97c5ff9c1e8ccaee918f4347af0e Mon Sep 17 00:00:00 2001 From: valdrinkoshi Date: Wed, 14 Mar 2018 12:23:06 -0700 Subject: [PATCH 01/15] remove neon-animation dependency --- bower.json | 8 +- demo/grow-height-animation.html | 166 ++++++++++--- demo/index.html | 425 ++++++++++++++++---------------- demo/x-select.html | 135 ++++------ iron-dropdown.html | 157 ++++++++---- test/iron-dropdown.html | 9 +- 6 files changed, 504 insertions(+), 396 deletions(-) diff --git a/bower.json b/bower.json index a6d014a..e5072d8 100644 --- a/bower.json +++ b/bower.json @@ -21,14 +21,12 @@ "dependencies": { "polymer": "Polymer/polymer#1.9 - 2", "iron-behaviors": "PolymerElements/iron-behaviors#1 - 2", - "iron-overlay-behavior": "PolymerElements/iron-overlay-behavior#^2.2.0", - "neon-animation": "PolymerElements/neon-animation#1 - 2" + "iron-overlay-behavior": "PolymerElements/iron-overlay-behavior#^2.2.0" }, "devDependencies": { "iron-component-page": "PolymerElements/iron-component-page#1 - 2", "iron-demo-helpers": "PolymerElements/iron-demo-helpers#1 - 2", "iron-test-helpers": "PolymerElements/iron-test-helpers#1 - 2", - "web-animations-js": "web-animations/web-animations-js#^2.2.0", "iron-image": "PolymerElements/iron-image#1 - 2", "web-component-tester": "^6.0.0", "webcomponentsjs": "webcomponents/webcomponentsjs#^1.0.0" @@ -38,14 +36,12 @@ "dependencies": { "polymer": "Polymer/polymer#^1.9", "iron-behaviors": "PolymerElements/iron-behaviors#^1.0.0", - "iron-overlay-behavior": "PolymerElements/iron-overlay-behavior#^2.2.0", - "neon-animation": "PolymerElements/neon-animation#^1.0.0" + "iron-overlay-behavior": "PolymerElements/iron-overlay-behavior#^2.2.0" }, "devDependencies": { "iron-component-page": "PolymerElements/iron-component-page#^1.0.0", "iron-demo-helpers": "PolymerElements/iron-demo-helpers#^1.0.0", "iron-test-helpers": "PolymerElements/iron-test-helpers#^1.0.0", - "web-animations-js": "web-animations/web-animations-js#^2.2.0", "iron-image": "PolymerElements/iron-image#^1.0.0", "web-component-tester": "^4.0.0", "webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0" diff --git a/demo/grow-height-animation.html b/demo/grow-height-animation.html index e2fdc44..85f12d5 100644 --- a/demo/grow-height-animation.html +++ b/demo/grow-height-animation.html @@ -1,36 +1,130 @@ - - - - - - + + + + + + \ No newline at end of file diff --git a/demo/index.html b/demo/index.html index 15f7480..69da35d 100644 --- a/demo/index.html +++ b/demo/index.html @@ -1,211 +1,214 @@ - - - - - - - iron-dropdown - - - - - - - - - - - - - - -

Basic

- - - - -

Alignment

- - - - -

Scroll actions

- - - - -

Content

- - - - - - - - - + + + + + + + iron-dropdown + + + + + + + + + + + + + +

Basic

+ + + + +

Alignment

+ + + + +

Scroll actions

+ + + + +

Content

+ + + + + + + + + diff --git a/demo/x-select.html b/demo/x-select.html index 3944411..a049d8f 100644 --- a/demo/x-select.html +++ b/demo/x-select.html @@ -1,82 +1,53 @@ - - - - - - - - - - + + + + + + + + + diff --git a/iron-dropdown.html b/iron-dropdown.html index 88985d7..69f507d 100644 --- a/iron-dropdown.html +++ b/iron-dropdown.html @@ -11,7 +11,6 @@ - @@ -56,6 +55,50 @@ overflow: hidden; pointer-events: none; } + + #contentWrapper { + /* TODO(valdrin) evaluate which props to expose */ + @apply --iron-dropdown-content-wrapper-animation; + } + + :host, #contentWrapper { + transform-origin: left top; + } + + :host([horizontal-align="right"][vertical-align="top"]), + :host([horizontal-align="right"][vertical-align="top"]) #contentWrapper { + transform-origin: right top; + } + + :host([horizontal-align="left"][vertical-align="bottom"]), + :host([horizontal-align="left"][vertical-align="bottom"]) #contentWrapper { + transform-origin: left bottom; + } + + :host([horizontal-align="right"][vertical-align="bottom"]), + :host([horizontal-align="right"][vertical-align="bottom"]) #contentWrapper { + transform-origin: right bottom; + } + + :host(.fade-in-animation) { + animation-name: fade-in-animation; + } + + @keyframes fade-in-animation { + from { + opacity: 0; + } + } + + :host(.fade-out-animation) { + animation-name: fade-out-animation; + } + + @keyframes fade-out-animation { + to { + opacity: 0; + } + }
@@ -73,8 +116,7 @@ behaviors: [ Polymer.IronControlState, Polymer.IronA11yKeysBehavior, - Polymer.IronOverlayBehavior, - Polymer.NeonAnimationRunnerBehavior + Polymer.IronOverlayBehavior ], properties: { @@ -100,24 +142,12 @@ reflectToAttribute: true }, - /** - * An animation config. If provided, this will be used to animate the - * opening of the dropdown. Pass an Array for multiple animations. - * See `neon-animation` documentation for more animation configuration - * details. - */ - openAnimationConfig: { - type: Object + entryAnimation: { + type: String }, - /** - * An animation config. If provided, this will be used to animate the - * closing of the dropdown. Pass an Array for multiple animations. - * See `neon-animation` documentation for more animation configuration - * details. - */ - closeAnimationConfig: { - type: Object + exitAnimation: { + type: String }, /** @@ -153,7 +183,7 @@ }, listeners: { - 'neon-animation-finish': '_onNeonAnimationFinish' + 'animationend': '_onAnimationEnd' }, observers: [ @@ -181,7 +211,7 @@ this._readied = true; }, - attached: function () { + attached: function() { if (!this.sizingTarget || this.sizingTarget === this) { this.sizingTarget = this.containedElement || this; } @@ -191,42 +221,56 @@ this.cancelAnimation(); }, + cancelAnimation: function() { + this.classList.remove(this.entryAnimation); + this.classList.remove(this.exitAnimation); + this.$.contentWrapper.classList.remove('animating'); + }, + + /** + * @param {string=} animation + */ + playAnimation: function(animation) { + if (!this.noAnimations && animation) { + this.$.contentWrapper.classList.add('animating'); + this.classList.add(animation); + if (this._willAnimate() === false) { + console.info(animation + ' animation was not played'); + this._onAnimationEnd(); + } + } else { + this._onAnimationEnd(); + } + }, + /** * Called when the value of `opened` changes. * Overridden from `IronOverlayBehavior` + * @private */ _openedChanged: function() { if (this.opened && this.disabled) { this.cancel(); } else { this.cancelAnimation(); - this._updateAnimationConfig(); Polymer.IronOverlayBehaviorImpl._openedChanged.apply(this, arguments); } }, /** * Overridden from `IronOverlayBehavior`. + * @private */ _renderOpened: function() { - if (!this.noAnimations && this.animationConfig.open) { - this.$.contentWrapper.classList.add('animating'); - this.playAnimation('open'); - } else { - Polymer.IronOverlayBehaviorImpl._renderOpened.apply(this, arguments); - } + this.playAnimation(this.entryAnimation); }, /** * Overridden from `IronOverlayBehavior`. + * @private */ _renderClosed: function() { - if (!this.noAnimations && this.animationConfig.close) { - this.$.contentWrapper.classList.add('animating'); - this.playAnimation('close'); - } else { - Polymer.IronOverlayBehaviorImpl._renderClosed.apply(this, arguments); - } + this.playAnimation(this.exitAnimation); }, /** @@ -234,36 +278,31 @@ * closing). Responsible for "completing" the process of opening or * closing the dropdown by positioning it or setting its display to * none. + * @param {Event=} event + * @private */ - _onNeonAnimationFinish: function() { + _onAnimationEnd: function(event) { + if (event && event.target !== this) { + return; + } this.$.contentWrapper.classList.remove('animating'); if (this.opened) { + this.classList.remove(this.entryAnimation); this._finishRenderOpened(); } else { + // Ensure to update display before removing the + // animation class, so that user doesn't see flickering + // e.g. dialog returning to its initial position/opacity. + this.style.display = 'none'; + this.classList.remove(this.exitAnimation); this._finishRenderClosed(); } }, - - /** - * Constructs the final animation config from different properties used - * to configure specific parts of the opening and closing animations. - */ - _updateAnimationConfig: function() { - // Update the animation node to be the containedElement. - var animationNode = this.containedElement; - var animations = [].concat(this.openAnimationConfig || []).concat(this.closeAnimationConfig || []); - for (var i = 0; i < animations.length; i++) { - animations[i].node = animationNode; - } - this.animationConfig = { - open: this.openAnimationConfig, - close: this.closeAnimationConfig - }; - }, /** * Updates the overlay position based on configured horizontal * and vertical alignment. + * @private */ _updateOverlayPosition: function() { if (this.isAttached) { @@ -275,6 +314,7 @@ /** * Sets scrollAction according to the value of allowOutsideScroll. * Prefer setting directly scrollAction. + * @private */ _allowOutsideScrollChanged: function(allowOutsideScroll) { // Wait until initial values are all set. @@ -290,6 +330,7 @@ /** * Apply focus to focusTarget or containedElement + * @private */ _applyFocus: function() { var focusTarget = this.focusTarget || this.containedElement; @@ -298,8 +339,18 @@ } else { Polymer.IronOverlayBehaviorImpl._applyFocus.apply(this, arguments); } + }, + + /** + * @private + */ + _willAnimate: function() { + // If CSS Class does not have animation-name considered not be an animation + var style = getComputedStyle(this); + return (style.getPropertyValue('animation-name') !== 'none' && + style.getPropertyValue('animation-duration') !== '0ms'); } }); })(); - + \ No newline at end of file diff --git a/test/iron-dropdown.html b/test/iron-dropdown.html index e154799..9ff027c 100644 --- a/test/iron-dropdown.html +++ b/test/iron-dropdown.html @@ -20,8 +20,6 @@ - - -
- -
+ - + \ No newline at end of file diff --git a/iron-dropdown.html b/iron-dropdown.html index 8884e11..6ea8831 100644 --- a/iron-dropdown.html +++ b/iron-dropdown.html @@ -45,14 +45,10 @@ - @@ -131,7 +89,7 @@ behaviors: [ Polymer.IronControlState, Polymer.IronA11yKeysBehavior, - Polymer.IronOverlayBehavior + Polymer.IronOverlayBehavior, ], properties: { diff --git a/test/iron-dropdown.html b/test/iron-dropdown.html index 9ff027c..9187fce 100644 --- a/test/iron-dropdown.html +++ b/test/iron-dropdown.html @@ -52,6 +52,16 @@ width: 3000px; height: 3000px; } + + .fade-in-animation { + animation: fade-in-animation 100ms; + } + + @keyframes fade-in-animation { + from { + opacity: 0; + } + } @@ -250,6 +260,11 @@ }); suite('correct animationConfig setup', function() { + setup(function() { + // not supported anymore, maybe? + this.skip(); + }); + test('as objects', function() { dropdown.openAnimationConfig = { name: 'open-animation' From 84bc09a6121f5cbf6ef732a21faed46f3e9a8784 Mon Sep 17 00:00:00 2001 From: valdrinkoshi Date: Fri, 16 Mar 2018 13:43:19 -0700 Subject: [PATCH 04/15] update types --- iron-dropdown.d.ts | 70 ++++------------------------------------------ 1 file changed, 5 insertions(+), 65 deletions(-) diff --git a/iron-dropdown.d.ts b/iron-dropdown.d.ts index c49bff8..5c25c5b 100644 --- a/iron-dropdown.d.ts +++ b/iron-dropdown.d.ts @@ -11,7 +11,6 @@ /// /// /// -/// /// /** @@ -37,7 +36,7 @@ * hidden until the dropdown element has `opened` set to true, or when the `open` * method is called on the element. */ -interface IronDropdownElement extends Polymer.Element, Polymer.IronControlState, Polymer.IronA11yKeysBehavior, Polymer.IronOverlayBehavior, Polymer.NeonAnimationRunnerBehavior { +interface IronDropdownElement extends Polymer.Element, Polymer.IronControlState, Polymer.IronA11yKeysBehavior, Polymer.IronOverlayBehavior { /** * The orientation against which to align the dropdown content @@ -52,22 +51,8 @@ interface IronDropdownElement extends Polymer.Element, Polymer.IronControlState, * Overridden from `Polymer.IronFitBehavior`. */ verticalAlign: string|null|undefined; - - /** - * An animation config. If provided, this will be used to animate the - * opening of the dropdown. Pass an Array for multiple animations. - * See `neon-animation` documentation for more animation configuration - * details. - */ - openAnimationConfig: object|null|undefined; - - /** - * An animation config. If provided, this will be used to animate the - * closing of the dropdown. Pass an Array for multiple animations. - * See `neon-animation` documentation for more animation configuration - * details. - */ - closeAnimationConfig: object|null|undefined; + entryAnimation: string|null|undefined; + exitAnimation: string|null|undefined; /** * If provided, this will be the element that will be focused when @@ -99,53 +84,8 @@ interface IronDropdownElement extends Polymer.Element, Polymer.IronControlState, ready(): void; attached(): void; detached(): void; - - /** - * Called when the value of `opened` changes. - * Overridden from `IronOverlayBehavior` - */ - _openedChanged(): void; - - /** - * Overridden from `IronOverlayBehavior`. - */ - _renderOpened(): void; - - /** - * Overridden from `IronOverlayBehavior`. - */ - _renderClosed(): void; - - /** - * Apply focus to focusTarget or containedElement - */ - _applyFocus(): void; - - /** - * Called when animation finishes on the dropdown (when opening or - * closing). Responsible for "completing" the process of opening or - * closing the dropdown by positioning it or setting its display to - * none. - */ - _onNeonAnimationFinish(): void; - - /** - * Constructs the final animation config from different properties used - * to configure specific parts of the opening and closing animations. - */ - _updateAnimationConfig(): void; - - /** - * Updates the overlay position based on configured horizontal - * and vertical alignment. - */ - _updateOverlayPosition(): void; - - /** - * Sets scrollAction according to the value of allowOutsideScroll. - * Prefer setting directly scrollAction. - */ - _allowOutsideScrollChanged(allowOutsideScroll: any): void; + cancelAnimation(): void; + playAnimation(animation?: string): void; } interface HTMLElementTagNameMap { From b6956255ba5892e5cd48a5788cac9b7603275174 Mon Sep 17 00:00:00 2001 From: valdrinkoshi Date: Wed, 28 Mar 2018 16:56:40 -0700 Subject: [PATCH 05/15] keep properties for backwards-compat, update docs --- README.md | 104 ++++++++++++++++++++++++++++++--------------- iron-dropdown.d.ts | 57 +++++++++++++++++++++++++ iron-dropdown.html | 68 +++++++++++++++++++++++++++++ 3 files changed, 194 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 06c02cc..b7c5a7a 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,69 @@ -[![Build status](https://travis-ci.org/PolymerElements/iron-dropdown.svg?branch=master)](https://travis-ci.org/PolymerElements/iron-dropdown) - -_[Demo and API docs](https://elements.polymer-project.org/elements/iron-dropdown)_ - - -## <iron-dropdown> - -`` is a generalized element that is useful when you have -hidden content (`dropdown-content`) that is revealed due to some change in -state that should cause it to do so. - -Note that this is a low-level element intended to be used as part of other -composite elements that cause dropdowns to be revealed. - -Examples of elements that might be implemented using an `iron-dropdown` -include comboboxes, menubuttons, selects. The list goes on. - -The `` element exposes attributes that allow the position -of the `dropdown-content` relative to the `dropdown-trigger` to be -configured. - -```html - -
Hello!
-
-``` - -In the above example, the `
` assigned to the `dropdown-content` slot will be -hidden until the dropdown element has `opened` set to true, or when the `open` -method is called on the element. - -### Changes in 2.0 -- Removed the private property `_focusTarget` which was deprecated. -- `neon-animation 2.0` doesn't import the Web Animations polyfill, so you'll have to import it ([see example](demo/index.html)) -- Distribution moved from the `class="dropdown-content"` to `slot="dropdown-content"` +[![Build status](https://travis-ci.org/PolymerElements/iron-dropdown.svg?branch=master)](https://travis-ci.org/PolymerElements/iron-dropdown) + +_[Demo and API docs](https://elements.polymer-project.org/elements/iron-dropdown)_ + + +## <iron-dropdown> + +`` is a generalized element that is useful when you have +hidden content (`dropdown-content`) that is revealed due to some change in +state that should cause it to do so. + +Note that this is a low-level element intended to be used as part of other +composite elements that cause dropdowns to be revealed. + +Examples of elements that might be implemented using an `iron-dropdown` +include comboboxes, menubuttons, selects. The list goes on. + +The `` element exposes attributes that allow the position +of the `dropdown-content` relative to the `dropdown-trigger` to be +configured. + +```html + +
Hello!
+
+``` + +In the above example, the `
` assigned to the `dropdown-content` slot will be +hidden until the dropdown element has `opened` set to true, or when the `open` +method is called on the element. + +### Changes in 2.0 +- Removed the private property `_focusTarget` which was deprecated. +- Distribution moved from the `class="dropdown-content"` to `slot="dropdown-content"`. +- `` animations are not based on the deprecated `neon-animation` component, and use CSS keyframe animations. + +### Animations + +`` animations are not based on the deprecated `neon-animation` component, and use CSS keyframe animations. +This change reduces code size, and uses the platform. You can implement custom entry/exit animations using CSS keyframe animations; define the animation keyframes, a CSS class for the animation, and assign the class to the `entry/exit-animation`, e.g. + + + + +
Hello!
+
diff --git a/iron-dropdown.d.ts b/iron-dropdown.d.ts index 5c25c5b..5de619c 100644 --- a/iron-dropdown.d.ts +++ b/iron-dropdown.d.ts @@ -35,6 +35,45 @@ * In the above example, the `
` assigned to the `dropdown-content` slot will be * hidden until the dropdown element has `opened` set to true, or when the `open` * method is called on the element. + * + * ### Changes in 2.0 + * - Removed the private property `_focusTarget` which was deprecated. + * - Distribution moved from the `class="dropdown-content"` to `slot="dropdown-content"`. + * - `` animations are not based on the deprecated `neon-animation` component, and use CSS keyframe animations + * + * ### Animations + * + * `` animations are not based on the deprecated `neon-animation` component, and use CSS keyframe animations. + * This change reduces code size, and uses the platform. You can implement custom entry/exit animations using CSS keyframe animations; define the animation keyframes, a CSS class for the animation, and assign the class to the `entry/exit-animation`, e.g. + * + * + * + * + *
Hello!
+ *
*/ interface IronDropdownElement extends Polymer.Element, Polymer.IronControlState, Polymer.IronA11yKeysBehavior, Polymer.IronOverlayBehavior { @@ -51,7 +90,25 @@ interface IronDropdownElement extends Polymer.Element, Polymer.IronControlState, * Overridden from `Polymer.IronFitBehavior`. */ verticalAlign: string|null|undefined; + + /** + * This property is deprecated and will be ignored, use `entryAnimation` instead. + */ + openAnimationConfig: object|null|undefined; + + /** + * This property is deprecated and will be ignored, use `exitAnimation` instead. + */ + closeAnimationConfig: object|null|undefined; + + /** + * The class defining the entry animation. + */ entryAnimation: string|null|undefined; + + /** + * The class defining the exit animation. + */ exitAnimation: string|null|undefined; /** diff --git a/iron-dropdown.html b/iron-dropdown.html index 6ea8831..a3c3243 100644 --- a/iron-dropdown.html +++ b/iron-dropdown.html @@ -37,6 +37,45 @@ hidden until the dropdown element has `opened` set to true, or when the `open` method is called on the element. +### Changes in 2.0 +- Removed the private property `_focusTarget` which was deprecated. +- Distribution moved from the `class="dropdown-content"` to `slot="dropdown-content"`. +- `` animations are not based on the deprecated `neon-animation` component, and use CSS keyframe animations + +### Animations + +`` animations are not based on the deprecated `neon-animation` component, and use CSS keyframe animations. +This change reduces code size, and uses the platform. You can implement custom entry/exit animations using CSS keyframe animations; define the animation keyframes, a CSS class for the animation, and assign the class to the `entry/exit-animation`, e.g. + + + + +
Hello!
+
+ @demo demo/index.html --> @@ -115,10 +154,32 @@ reflectToAttribute: true }, + /** + * This property is deprecated and will be ignored, use `entryAnimation` instead. + * @deprecated + */ + openAnimationConfig: { + type: Object, + }, + + /** + * This property is deprecated and will be ignored, use `exitAnimation` instead. + * @deprecated + */ + closeAnimationConfig: { + type: Object, + }, + + /** + * The class defining the entry animation. + */ entryAnimation: { type: String }, + /** + * The class defining the exit animation. + */ exitAnimation: { type: String }, @@ -226,6 +287,11 @@ this.cancel(); } else { this.cancelAnimation(); + // Keep this for backwards-compat. + this.animationConfig = { + open: this.openAnimationConfig, + close: this.closeAnimationConfig + }; Polymer.IronOverlayBehaviorImpl._openedChanged.apply(this, arguments); } }, @@ -259,6 +325,8 @@ return; } this.classList.remove('animating'); + // Fire event for backwards-compat. + this.fire('neon-animation-finish', null, {bubbles: false}); if (this.opened) { this.classList.remove(this.entryAnimation); this._finishRenderOpened(); From ccd72e4bd2276ec5be15597efb139a4fda80fa93 Mon Sep 17 00:00:00 2001 From: valdrinkoshi Date: Wed, 28 Mar 2018 17:28:16 -0700 Subject: [PATCH 06/15] avoid firing neon-animation-finish when no-animations --- iron-dropdown.d.ts | 2 -- iron-dropdown.html | 88 +++++++++++++++++++++++++--------------------- 2 files changed, 48 insertions(+), 42 deletions(-) diff --git a/iron-dropdown.d.ts b/iron-dropdown.d.ts index 5de619c..11c1cf2 100644 --- a/iron-dropdown.d.ts +++ b/iron-dropdown.d.ts @@ -141,8 +141,6 @@ interface IronDropdownElement extends Polymer.Element, Polymer.IronControlState, ready(): void; attached(): void; detached(): void; - cancelAnimation(): void; - playAnimation(animation?: string): void; } interface HTMLElementTagNameMap { diff --git a/iron-dropdown.html b/iron-dropdown.html index a3c3243..e2fe8ec 100644 --- a/iron-dropdown.html +++ b/iron-dropdown.html @@ -159,7 +159,7 @@ * @deprecated */ openAnimationConfig: { - type: Object, + type: Object }, /** @@ -167,7 +167,7 @@ * @deprecated */ closeAnimationConfig: { - type: Object, + type: Object }, /** @@ -252,29 +252,7 @@ }, detached: function() { - this.cancelAnimation(); - }, - - cancelAnimation: function() { - this.classList.remove(this.entryAnimation); - this.classList.remove(this.exitAnimation); - this.classList.remove('animating'); - }, - - /** - * @param {string=} animation - */ - playAnimation: function(animation) { - if (!this.noAnimations && animation) { - this.classList.add('animating'); - this.classList.add(animation); - if (this._willAnimate() === false) { - console.info(animation + ' animation was not played'); - this._onAnimationEnd(); - } - } else { - this._onAnimationEnd(); - } + this._cancelAnimation(); }, /** @@ -286,7 +264,7 @@ if (this.opened && this.disabled) { this.cancel(); } else { - this.cancelAnimation(); + this._cancelAnimation(); // Keep this for backwards-compat. this.animationConfig = { open: this.openAnimationConfig, @@ -301,7 +279,11 @@ * @private */ _renderOpened: function() { - this.playAnimation(this.entryAnimation); + if (!this.noAnimations && this.entryAnimation) { + this._playAnimation(this.entryAnimation); + } else { + Polymer.IronOverlayBehaviorImpl._renderOpened.apply(this, arguments); + } }, /** @@ -309,7 +291,43 @@ * @private */ _renderClosed: function() { - this.playAnimation(this.exitAnimation); + if (!this.noAnimations && this.exitAnimation) { + this._playAnimation(this.exitAnimation); + } else { + Polymer.IronOverlayBehaviorImpl._renderClosed.apply(this, arguments); + } + }, + + /** + * @private + */ + _cancelAnimation: function() { + this.classList.remove(this.entryAnimation); + this.classList.remove(this.exitAnimation); + this.classList.remove('animating'); + }, + + /** + * @param {!string} animation + * @private + */ + _playAnimation: function(animation) { + this.classList.add('animating'); + this.classList.add(animation); + if (this._willAnimate() === false) { + console.info(animation + ' animation was not played'); + this._onAnimationEnd(); + } + }, + + /** + * @private + */ + _willAnimate: function() { + // If CSS Class does not have animation-name considered not be an animation + var style = getComputedStyle(this); + return (style.getPropertyValue('animation-name') !== 'none' && + style.getPropertyValue('animation-duration') !== '0ms'); }, /** @@ -324,9 +342,9 @@ if (event && event.target !== this) { return; } - this.classList.remove('animating'); // Fire event for backwards-compat. this.fire('neon-animation-finish', null, {bubbles: false}); + this.classList.remove('animating'); if (this.opened) { this.classList.remove(this.entryAnimation); this._finishRenderOpened(); @@ -380,18 +398,8 @@ } else { Polymer.IronOverlayBehaviorImpl._applyFocus.apply(this, arguments); } - }, - - /** - * @private - */ - _willAnimate: function() { - // If CSS Class does not have animation-name considered not be an animation - var style = getComputedStyle(this); - return (style.getPropertyValue('animation-name') !== 'none' && - style.getPropertyValue('animation-duration') !== '0ms'); } }); })(); - \ No newline at end of file + From 34046745fe60df1217c9b9848feef571b3edd17e Mon Sep 17 00:00:00 2001 From: valdrinkoshi Date: Wed, 28 Mar 2018 17:46:09 -0700 Subject: [PATCH 07/15] simplify demo --- demo/grow-height-animation.html | 130 -------------------------------- demo/index.html | 6 +- demo/x-select.html | 42 +++++++---- 3 files changed, 29 insertions(+), 149 deletions(-) delete mode 100644 demo/grow-height-animation.html diff --git a/demo/grow-height-animation.html b/demo/grow-height-animation.html deleted file mode 100644 index a710043..0000000 --- a/demo/grow-height-animation.html +++ /dev/null @@ -1,130 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/demo/index.html b/demo/index.html index 69da35d..bc3118b 100644 --- a/demo/index.html +++ b/demo/index.html @@ -29,15 +29,11 @@ } } - html { - --iron-dropdown-box-shadow: 0px 2px 6px #ccc; - /* --iron-dropdown-border: 1px solid; */ - } - [slot="dropdown-content"] { background-color: white; line-height: 20px; border-radius: 3px; + box-shadow: 0px 2px 6px #ccc; } .random-content { diff --git a/demo/x-select.html b/demo/x-select.html index 6a6fbeb..44a88db 100644 --- a/demo/x-select.html +++ b/demo/x-select.html @@ -9,28 +9,44 @@ --> - - \ No newline at end of file + From 0c1492ddeb5bed0da775e239b2b619a4ec051492 Mon Sep 17 00:00:00 2001 From: valdrinkoshi Date: Wed, 28 Mar 2018 17:55:34 -0700 Subject: [PATCH 08/15] fix test duration --- test/iron-dropdown.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/iron-dropdown.html b/test/iron-dropdown.html index 9187fce..85b30ba 100644 --- a/test/iron-dropdown.html +++ b/test/iron-dropdown.html @@ -54,7 +54,7 @@ } .fade-in-animation { - animation: fade-in-animation 100ms; + animation: fade-in-animation 300ms; } @keyframes fade-in-animation { From 1313b7d12eb44d60b592b6750e7749dbd3c01558 Mon Sep 17 00:00:00 2001 From: valdrinkoshi Date: Thu, 29 Mar 2018 22:35:23 -0700 Subject: [PATCH 09/15] include default animations, remove neon-animation props --- README.md | 35 ++++++------ demo/x-select.html | 10 ---- iron-dropdown.d.ts | 45 +++++++--------- iron-dropdown.html | 130 ++++++++++++++++++++++++--------------------- 4 files changed, 108 insertions(+), 112 deletions(-) diff --git a/README.md b/README.md index b7c5a7a..eea332b 100644 --- a/README.md +++ b/README.md @@ -36,34 +36,37 @@ method is called on the element. ### Animations -`` animations are not based on the deprecated `neon-animation` component, and use CSS keyframe animations. -This change reduces code size, and uses the platform. You can implement custom entry/exit animations using CSS keyframe animations; define the animation keyframes, a CSS class for the animation, and assign the class to the `entry/exit-animation`, e.g. +Set the `entry-animation` and/or `exit-animation` attributes to add an animation when the dialog +is opened or closed. Included in the component are: +- fade-in-animation +- fade-out-animation +- scale-up-animation +- scale-down-animation + +These animations are not based on the deprecated `neon-animation` component, and use CSS keyframe animations. +This change reduces code size, and uses the platform. You can implement custom entry/exit animations using +CSS keyframe animations; define the animation keyframes, a CSS class for the animation, and assign the class to the `entry/exit-animation`, e.g. -
Hello!
diff --git a/demo/x-select.html b/demo/x-select.html index 44a88db..b63565d 100644 --- a/demo/x-select.html +++ b/demo/x-select.html @@ -25,27 +25,17 @@ } to { max-height: 100vh; - opacity: 1; } } .expand-animation { - overflow: hidden; animation-name: expand-animation; - animation-fill-mode: both; animation-timing-function: cubic-bezier(0.0, 0.0, 0.2, 1); animation-delay: 150ms; animation-duration: 200ms; } - @keyframes fade-out-animation { - to { - opacity: 0 - } - } - .fade-out-animation { - animation-name: fade-out-animation; animation-duration: 150ms; } diff --git a/iron-dropdown.d.ts b/iron-dropdown.d.ts index 11c1cf2..afecce0 100644 --- a/iron-dropdown.d.ts +++ b/iron-dropdown.d.ts @@ -43,34 +43,37 @@ * * ### Animations * - * `` animations are not based on the deprecated `neon-animation` component, and use CSS keyframe animations. - * This change reduces code size, and uses the platform. You can implement custom entry/exit animations using CSS keyframe animations; define the animation keyframes, a CSS class for the animation, and assign the class to the `entry/exit-animation`, e.g. + * Set the `entry-animation` and/or `exit-animation` attributes to add an animation when the dialog + * is opened or closed. Included in the component are: + * - fade-in-animation + * - fade-out-animation + * - scale-up-animation + * - scale-down-animation + * + * These animations are not based on the deprecated `neon-animation` component, and use CSS keyframe animations. + * This change reduces code size, and uses the platform. You can implement custom entry/exit animations using + * CSS keyframe animations; define the animation keyframes, a CSS class for the animation, and assign the class to the `entry/exit-animation`, e.g. * * * - * *
Hello!
*
@@ -91,16 +94,6 @@ interface IronDropdownElement extends Polymer.Element, Polymer.IronControlState, */ verticalAlign: string|null|undefined; - /** - * This property is deprecated and will be ignored, use `entryAnimation` instead. - */ - openAnimationConfig: object|null|undefined; - - /** - * This property is deprecated and will be ignored, use `exitAnimation` instead. - */ - closeAnimationConfig: object|null|undefined; - /** * The class defining the entry animation. */ diff --git a/iron-dropdown.html b/iron-dropdown.html index e2fe8ec..915d7d9 100644 --- a/iron-dropdown.html +++ b/iron-dropdown.html @@ -44,34 +44,37 @@ ### Animations -`` animations are not based on the deprecated `neon-animation` component, and use CSS keyframe animations. -This change reduces code size, and uses the platform. You can implement custom entry/exit animations using CSS keyframe animations; define the animation keyframes, a CSS class for the animation, and assign the class to the `entry/exit-animation`, e.g. +Set the `entry-animation` and/or `exit-animation` attributes to add an animation when the dialog +is opened or closed. Included in the component are: +- fade-in-animation +- fade-out-animation +- scale-up-animation +- scale-down-animation + +These animations are not based on the deprecated `neon-animation` component, and use CSS keyframe animations. +This change reduces code size, and uses the platform. You can implement custom entry/exit animations using +CSS keyframe animations; define the animation keyframes, a CSS class for the animation, and assign the class to the `entry/exit-animation`, e.g. -
Hello!
@@ -84,35 +87,70 @@ @@ -154,22 +192,6 @@ reflectToAttribute: true }, - /** - * This property is deprecated and will be ignored, use `entryAnimation` instead. - * @deprecated - */ - openAnimationConfig: { - type: Object - }, - - /** - * This property is deprecated and will be ignored, use `exitAnimation` instead. - * @deprecated - */ - closeAnimationConfig: { - type: Object - }, - /** * The class defining the entry animation. */ @@ -265,11 +287,6 @@ this.cancel(); } else { this._cancelAnimation(); - // Keep this for backwards-compat. - this.animationConfig = { - open: this.openAnimationConfig, - close: this.closeAnimationConfig - }; Polymer.IronOverlayBehaviorImpl._openedChanged.apply(this, arguments); } }, @@ -342,18 +359,11 @@ if (event && event.target !== this) { return; } - // Fire event for backwards-compat. - this.fire('neon-animation-finish', null, {bubbles: false}); - this.classList.remove('animating'); + // Removes the classes. + this._cancelAnimation(); if (this.opened) { - this.classList.remove(this.entryAnimation); this._finishRenderOpened(); } else { - // Ensure to update display before removing the - // animation class, so that user doesn't see flickering - // e.g. dialog returning to its initial position/opacity. - this.style.display = 'none'; - this.classList.remove(this.exitAnimation); this._finishRenderClosed(); } }, From 2d533a14c54a18dfd30bd308d849c66fad8cf74e Mon Sep 17 00:00:00 2001 From: valdrinkoshi Date: Thu, 29 Mar 2018 23:26:45 -0700 Subject: [PATCH 10/15] set only entryAnimation --- test/iron-dropdown.html | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/test/iron-dropdown.html b/test/iron-dropdown.html index 85b30ba..0147270 100644 --- a/test/iron-dropdown.html +++ b/test/iron-dropdown.html @@ -52,16 +52,6 @@ width: 3000px; height: 3000px; } - - .fade-in-animation { - animation: fade-in-animation 300ms; - } - - @keyframes fade-in-animation { - from { - opacity: 0; - } - } From af91527ee0b816d5890e1b450626c38575980405 Mon Sep 17 00:00:00 2001 From: valdrinkoshi Date: Thu, 29 Mar 2018 23:27:34 -0700 Subject: [PATCH 11/15] [skip ci] update comment --- test/iron-dropdown.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/iron-dropdown.html b/test/iron-dropdown.html index 0147270..55d4666 100644 --- a/test/iron-dropdown.html +++ b/test/iron-dropdown.html @@ -251,7 +251,7 @@ suite('correct animationConfig setup', function() { setup(function() { - // not supported anymore, maybe? + // not supported anymore. this.skip(); }); From 03fd905f3119679c9f5aca5e020cbea97fea692f Mon Sep 17 00:00:00 2001 From: valdrinkoshi Date: Fri, 30 Mar 2018 16:26:03 -0700 Subject: [PATCH 12/15] warn about animationConfig usages --- iron-dropdown.d.ts | 21 ++++++++++++++++++++ iron-dropdown.html | 49 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/iron-dropdown.d.ts b/iron-dropdown.d.ts index afecce0..039a3b1 100644 --- a/iron-dropdown.d.ts +++ b/iron-dropdown.d.ts @@ -104,6 +104,27 @@ interface IronDropdownElement extends Polymer.Element, Polymer.IronControlState, */ exitAnimation: string|null|undefined; + /** + * Deprecated, use `entryAnimation` and `exitAnimation` instead. + * `iron-dropdown` doesn't depend anymore on `neon-animation`, and this property is kept + * here to not break bindings. Setting it won't have effects on the animation. + */ + animationConfig: object|null|undefined; + + /** + * Deprecated, use `entryAnimation` instead. + * `iron-dropdown` doesn't depend anymore on `neon-animation`, and this property is kept + * here to not break bindings. Setting it won't have effects on the animation. + */ + openAnimationConfig: object|null|undefined; + + /** + * Deprecated, use `exitAnimation` instead. + * `iron-dropdown` doesn't depend anymore on `neon-animation`, and this property is kept + * here to not break bindings. Setting it won't have effects on the animation. + */ + closeAnimationConfig: object|null|undefined; + /** * If provided, this will be the element that will be focused when * the dropdown opens. diff --git a/iron-dropdown.html b/iron-dropdown.html index 915d7d9..6fbe467 100644 --- a/iron-dropdown.html +++ b/iron-dropdown.html @@ -206,6 +206,36 @@ type: String }, + /** + * Deprecated, use `entryAnimation` and `exitAnimation` instead. + * `iron-dropdown` doesn't depend anymore on `neon-animation`, and this property is kept + * here to not break bindings. Setting it won't have effects on the animation. + * @deprecated + */ + animationConfig: { + type: Object + }, + + /** + * Deprecated, use `entryAnimation` instead. + * `iron-dropdown` doesn't depend anymore on `neon-animation`, and this property is kept + * here to not break bindings. Setting it won't have effects on the animation. + * @deprecated + */ + openAnimationConfig: { + type: Object + }, + + /** + * Deprecated, use `exitAnimation` instead. + * `iron-dropdown` doesn't depend anymore on `neon-animation`, and this property is kept + * here to not break bindings. Setting it won't have effects on the animation. + * @deprecated + */ + closeAnimationConfig: { + type: Object + }, + /** * If provided, this will be the element that will be focused when * the dropdown opens. @@ -264,6 +294,16 @@ if (!this.scrollAction) { this.scrollAction = this.allowOutsideScroll ? 'refit' : 'lock'; } + if (this.openAnimationConfig || this.closeAnimationConfig || this.animationConfig) { + console.warn('Configuring animations through animationConfig, openAnimationConfig, '+ + 'or closeAnimationConfig is no longer supported.' + + 'Use entryAnimation and exitAnimation instead.'); + // Set this for backwards-compat. + this.animationConfig = this.animationConfig || { + open: this.openAnimationConfig, + close: this.closeAnimationConfig + }; + } this._readied = true; }, @@ -319,9 +359,11 @@ * @private */ _cancelAnimation: function() { - this.classList.remove(this.entryAnimation); - this.classList.remove(this.exitAnimation); - this.classList.remove('animating'); + if (this._pendingAnimation) { + this.classList.remove('animating'); + this.classList.remove(this._pendingAnimation); + this._pendingAnimation = null; + } }, /** @@ -331,6 +373,7 @@ _playAnimation: function(animation) { this.classList.add('animating'); this.classList.add(animation); + this._pendingAnimation = animation; if (this._willAnimate() === false) { console.info(animation + ' animation was not played'); this._onAnimationEnd(); From dcd1a771df9b3938d4836d6afa7b23a1185d924f Mon Sep 17 00:00:00 2001 From: valdrinkoshi Date: Fri, 30 Mar 2018 16:38:16 -0700 Subject: [PATCH 13/15] implement cancelAnimation/playAnimation/getAnimationConfig as no-ops --- iron-dropdown.html | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/iron-dropdown.html b/iron-dropdown.html index 6fbe467..69b43e3 100644 --- a/iron-dropdown.html +++ b/iron-dropdown.html @@ -317,6 +317,32 @@ this._cancelAnimation(); }, + /** + * `iron-dropdown` doesn't depend anymore on `neon-animation`. + * This method was previously inherited from `Polymer.NeonAnimatableBehavior`, + * now is a no-op. + * @deprecated + */ + cancelAnimation: function() {}, + + /** + * `iron-dropdown` doesn't depend anymore on `neon-animation`. + * This method was previously inherited from `Polymer.NeonAnimatableBehavior`, + * now is a no-op. + * @param {string=} type + * @param {!Object=} cookie + * @deprecated + */ + playAnimation: function(type, cookie) {}, + + /** + * `iron-dropdown` doesn't depend anymore on `neon-animation`. + * This method was previously inherited from `Polymer.NeonAnimatableBehavior`, + * now is a no-op. + * @deprecated + */ + getAnimationConfig: function(type) { return []; }, + /** * Called when the value of `opened` changes. * Overridden from `IronOverlayBehavior` From d2a01ce24c339fff80037a96da51d0e241ffdf48 Mon Sep 17 00:00:00 2001 From: valdrinkoshi Date: Fri, 30 Mar 2018 16:40:22 -0700 Subject: [PATCH 14/15] udpdate types --- iron-dropdown.d.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/iron-dropdown.d.ts b/iron-dropdown.d.ts index 039a3b1..2b5b7ef 100644 --- a/iron-dropdown.d.ts +++ b/iron-dropdown.d.ts @@ -155,6 +155,27 @@ interface IronDropdownElement extends Polymer.Element, Polymer.IronControlState, ready(): void; attached(): void; detached(): void; + + /** + * `iron-dropdown` doesn't depend anymore on `neon-animation`. + * This method was previously inherited from `Polymer.NeonAnimatableBehavior`, + * now is a no-op. + */ + cancelAnimation(): void; + + /** + * `iron-dropdown` doesn't depend anymore on `neon-animation`. + * This method was previously inherited from `Polymer.NeonAnimatableBehavior`, + * now is a no-op. + */ + playAnimation(type?: string, cookie?: object): void; + + /** + * `iron-dropdown` doesn't depend anymore on `neon-animation`. + * This method was previously inherited from `Polymer.NeonAnimatableBehavior`, + * now is a no-op. + */ + getAnimationConfig(type: any): any; } interface HTMLElementTagNameMap { From 29681f8045984dab5a8ec1683d86096410fcd29e Mon Sep 17 00:00:00 2001 From: valdrinkoshi Date: Fri, 30 Mar 2018 18:05:22 -0700 Subject: [PATCH 15/15] [skip ci] format --- iron-dropdown.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iron-dropdown.html b/iron-dropdown.html index 69b43e3..7249cd6 100644 --- a/iron-dropdown.html +++ b/iron-dropdown.html @@ -295,9 +295,9 @@ this.scrollAction = this.allowOutsideScroll ? 'refit' : 'lock'; } if (this.openAnimationConfig || this.closeAnimationConfig || this.animationConfig) { - console.warn('Configuring animations through animationConfig, openAnimationConfig, '+ - 'or closeAnimationConfig is no longer supported.' + - 'Use entryAnimation and exitAnimation instead.'); + console.warn('Configuring animations through animationConfig, openAnimationConfig, ' + + 'or closeAnimationConfig is no longer supported. ' + + 'Use entryAnimation and exitAnimation instead.'); // Set this for backwards-compat. this.animationConfig = this.animationConfig || { open: this.openAnimationConfig,