Skip to content

Commit

Permalink
Move get clicked item logic to dropdown item | Fixes #660
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Lancha committed Feb 27, 2018
1 parent 274d1e8 commit 93ec641
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 48 deletions.
12 changes: 6 additions & 6 deletions packages/clay-dataset-display/src/ClayDatasetDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ class ClayDatasetDisplay extends Component {

/**
* Continues the propagation of the action item clicked event
* @param {!Event} event
* @param {!Object} item
* @private
*/
_handleActionClicked(event) {
this.emit('actionClicked', event);
_handleActionClicked(item) {
this.emit('actionClicked', item);
}

/**
Expand Down Expand Up @@ -213,14 +213,14 @@ class ClayDatasetDisplay extends Component {

/**
* Changes the view on management toolbar view type click.
* @param {!Event} event
* @param {!Object} item
* @private
*/
_handleViewTypeClicked(event) {
_handleViewTypeClicked(item) {
this.views[this.selectedView].active = false;

for (let [index, view] of this.views.entries()) {
if (view === event.viewType) {
if (view === item) {
this.views[index].active = true;
this.selectedView = index;
break;
Expand Down
6 changes: 3 additions & 3 deletions packages/clay-dropdown/src/ClayActionsDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class ClayActionsDropdown extends Component {

/**
* Continues the propagation of the item clicked event
* @param {!Event} event
* @param {!Object} item
* @protected
*/
_handleItemClick(event) {
this.emit('itemClicked', event);
_handleItemClick(item) {
this.emit('itemClicked', item);
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/clay-dropdown/src/ClayDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class ClayDropdown extends Component {

/**
* Continues the propagation of the item clicked event
* @param {!Event} event
* @param {!Object} item
* @protected
*/
_handleItemClick(event) {
this.emit('itemClicked', event);
_handleItemClick(item) {
this.emit('itemClicked', item);
}
}

Expand Down
23 changes: 22 additions & 1 deletion packages/clay-dropdown/src/ClayDropdownBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ class ClayDropdownBase extends Component {
this.expanded = false;
}

/**
* Returns the dropdown index of the element.
* @param {!Node} element
* @return {?array|undefined} the index.
* @private
*/
_getDropdownItemIndex(element) {
return Array.prototype.indexOf.call(
Array.prototype.filter.call(
element.parentElement.children,
childrenElement =>
childrenElement.getAttribute('role') !== 'presentation'
),
element
);
}

/**
* Handles document click in order to hide menu.
* @param {!Event} event
Expand Down Expand Up @@ -89,7 +106,11 @@ class ClayDropdownBase extends Component {
* @protected
*/
_handleItemClick(event) {
this.emit('itemClicked', event);
let element = event.delegateTarget;
let elementIndex = this._getDropdownItemIndex(element);
let item = this.items[elementIndex];

this.emit('itemClicked', item);
}

/**
Expand Down
41 changes: 6 additions & 35 deletions packages/clay-management-toolbar/src/ClayManagementToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,13 @@ import templates from './ClayManagementToolbar.soy.js';
* Metal ClayManagementToolbar component.
*/
class ClayManagementToolbar extends Component {
/**
* Returns the dropdown index of the element.
* @param {!Node} element
* @return {?array|undefined} the index.
* @private
*/
_getDropdownItemIndex(element) {
return Array.prototype.indexOf.call(
Array.prototype.filter.call(
element.parentElement.children,
childrenElement =>
childrenElement.getAttribute('role') !== 'presentation'
),
element
);
}

/**
* Continues the propagation of the action item clicked event
* @param {!Event} event
* @param {!Object} item
* @private
*/
_handleActionClicked(event) {
let element = event.delegateTarget;
let elementIndex = this._getDropdownItemIndex(element);
let item = this.actionItems[elementIndex];

this.emit('actionClicked', {
action: item,
});
_handleActionClicked(item) {
this.emit('actionClicked', item);
}

/**
Expand Down Expand Up @@ -149,17 +126,11 @@ class ClayManagementToolbar extends Component {

/**
* Continues the propagation of the view type item clicked event
* @param {!Event} event
* @param {!object} item
* @private
*/
_handleViewTypeClicked(event) {
let element = event.delegateTarget;
let elementIndex = this._getDropdownItemIndex(element);
let item = this.viewTypes[elementIndex];

this.emit('viewTypeClicked', {
viewType: item,
});
_handleViewTypeClicked(item) {
this.emit('viewTypeClicked', item);
}
}

Expand Down

0 comments on commit 93ec641

Please sign in to comment.