Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Updates Dropdown to have fade in and out transitions #148

Closed
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
34 changes: 32 additions & 2 deletions packages/marble-dropdown/src/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,28 @@ class Dropdown extends Component {
* Toggles the dropdown, closing it when open or opening it when closed.
*/
toggle() {
this.expanded = !this.expanded;
this.hideConfirmation();
if (this.expanded) {
this.hiding = true;

this.callAsync_(() => {
this.expanded = !this.expanded;
this.hiding = false;
this.hideConfirmation();
}, 300);
} else {
this.expanded = !this.expanded;
this.hideConfirmation();
}
}

/**
* @param {!function()} fn
* @param {number} delay
* @private
*/
callAsync_(fn, delay) {
clearTimeout(this.delay_);
this.delay_ = setTimeout(fn.bind(this), delay);
}

/**
Expand Down Expand Up @@ -280,6 +300,16 @@ Dropdown.STATE = {
internal: true,
},

/**
* Flag indicating if the dropdown is hiding or not.
* @type {boolean}
* @default false
*/
hiding: {
value: false,
internal: true,
},

/**
* The position of the dropdown (either 'up', 'down' or any of the position
* constants available in `Align`).
Expand Down
3 changes: 2 additions & 1 deletion packages/marble-dropdown/src/Dropdown.soy
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @param? classMap
* @param? elementClasses
* @param? expanded
* @param? hiding
* @param? position
* @param? positionClassOnMenu
* @param? showConfirmationBody
Expand All @@ -17,7 +18,7 @@
{let $classes: $classMap ? $classMap : ['dropup', 'dropup', 'dropright', 'dropdown', 'dropdown', 'dropdown', 'dropleft', 'dropup'] /}
{let $currentPosition: isNonnull($alignedPosition) ? $alignedPosition : $position /}
{let $positionClass: isNonnull($currentPosition) ? $classes[$currentPosition] : 'dropdown' /}
<div class="{$positionClassOnMenu ? 'dropdown' : $positionClass}{$elementClasses ? ' ' + $elementClasses : ''}{$expanded ? ' open' : ''}">
<div class="{$positionClassOnMenu ? 'dropdown' : $positionClass}{$elementClasses ? ' ' + $elementClasses : ''}{$expanded ? ' open' : ''}{$hiding ? ' hiding' : ''}">
{if $header}
{$header}
{/if}
Expand Down
8 changes: 5 additions & 3 deletions packages/marble-dropdown/src/Dropdown.soy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var soyIdom = goog.require('soy.idom');
* classMap: (?),
* elementClasses: (?),
* expanded: (?),
* hiding: (?),
* position: (?),
* positionClassOnMenu: (?),
* showConfirmationBody: (?),
Expand All @@ -52,7 +53,7 @@ function $render(opt_data, opt_ijData, opt_ijData_deprecated) {
var currentPosition__soy9 = (opt_data.alignedPosition != null) ? opt_data.alignedPosition : opt_data.position;
var positionClass__soy11 = (currentPosition__soy9 != null) ? classes__soy7[currentPosition__soy9] : 'dropdown';
incrementalDom.elementOpenStart('div');
incrementalDom.attr('class', (opt_data.positionClassOnMenu ? 'dropdown' : positionClass__soy11) + (opt_data.elementClasses ? ' ' + opt_data.elementClasses : '') + (opt_data.expanded ? ' open' : ''));
incrementalDom.attr('class', (opt_data.positionClassOnMenu ? 'dropdown' : positionClass__soy11) + (opt_data.elementClasses ? ' ' + opt_data.elementClasses : '') + (opt_data.expanded ? ' open' : '') + (opt_data.hiding ? ' hiding' : ''));
incrementalDom.elementOpenEnd();
if (header) {
header();
Expand Down Expand Up @@ -81,6 +82,7 @@ exports.render = $render;
* classMap: (?),
* elementClasses: (?),
* expanded: (?),
* hiding: (?),
* position: (?),
* positionClassOnMenu: (?),
* showConfirmationBody: (?),
Expand All @@ -94,8 +96,8 @@ if (goog.DEBUG) {
$render.soyTemplateName = 'Dropdown.render';
}

exports.render.params = ["body","confirmationBody","header","alignedPosition","classMap","elementClasses","expanded","position","positionClassOnMenu","showConfirmationBody"];
exports.render.types = {"body":"html","confirmationBody":"html","header":"html","alignedPosition":"any","classMap":"any","elementClasses":"any","expanded":"any","position":"any","positionClassOnMenu":"any","showConfirmationBody":"any"};
exports.render.params = ["body","confirmationBody","header","alignedPosition","classMap","elementClasses","expanded","hiding","position","positionClassOnMenu","showConfirmationBody"];
exports.render.types = {"body":"html","confirmationBody":"html","header":"html","alignedPosition":"any","classMap":"any","elementClasses":"any","expanded":"any","hiding":"any","position":"any","positionClassOnMenu":"any","showConfirmationBody":"any"};
templates = exports;
return exports;

Expand Down
13 changes: 9 additions & 4 deletions packages/marble-dropdown/test/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ describe('Dropdown', () => {
expect(dom.hasClass(component.element, 'open')).toBeTruthy();
component.toggle();
component.once('stateChanged', () => {
expect(!component.expanded).toBeTruthy();
expect(!dom.hasClass(component.element, 'open')).toBeTruthy();
component.dispose();
done();
expect(component.hiding).toBeTruthy();
expect(dom.hasClass(component.element, 'hiding')).toBeTruthy();
component.once('stateChanged', () => {
expect(!component.expanded).toBeTruthy();
expect(!component.hiding).toBeTruthy();
expect(!dom.hasClass(component.element, 'open')).toBeTruthy();
component.dispose();
done();
});
});
});
});
Expand Down
10 changes: 10 additions & 0 deletions packages/marble/src/_animations.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
}
}

@keyframes fadeOut {
0% {
opacity: 1;
}

100% {
opacity: 0;
}
}

@keyframes fadeInToRight {
0% {
opacity: 0;
Expand Down
5 changes: 5 additions & 0 deletions packages/marble/src/_dropdowns.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@
}

.open .dropdown-menu {
animation: fadeIn 300ms cubic-bezier(0.455, 0.03, 0.515, 0.955) forwards;
display: inline-block;
}

.hiding .dropdown-menu {
animation: fadeOut 300ms cubic-bezier(0.455, 0.03, 0.515, 0.955) forwards;
}

.dropdown-section-title {
color: rgba($white, 0.4);
display: block;
Expand Down