Attempt to make dropdown item actions more consistent
Summary: See D17210. Currently, this handler needs to be installed on each menu that doesn't build with the default behavior. Rather than copy-pasting it to the user menu, try to make it a default behavior. This adds a new rule: don't close the menu if the item is a dynamic item built in JS with PHUIXActionView. This allows dynamic items to control the menu themselves, while giving static items the desired default behavior. Test Plan: - Opened menus on: dashboards, user menu, timeline comments. Clicked stuff. Menus went away. - Other menus still seemed to work right: Diffusion, Favorites, mobile menu. Reviewers: chad Reviewed By: chad Differential Revision: https://secure.phabricator.com/D17222
This commit is contained in:
@@ -34,13 +34,6 @@ JX.behavior('project-boards', function(config, statics) {
|
||||
data.menu = new JX.PHUIXDropdownMenu(button);
|
||||
data.menu.setContent(list);
|
||||
data.menu.open();
|
||||
|
||||
JX.DOM.listen(list, 'click', 'tag:a', function(e) {
|
||||
if (!e.isNormalClick()) {
|
||||
return;
|
||||
}
|
||||
data.menu.close();
|
||||
});
|
||||
});
|
||||
|
||||
JX.Stratcom.listen(
|
||||
|
||||
@@ -42,20 +42,6 @@ JX.behavior('phui-dropdown-menu', function() {
|
||||
});
|
||||
|
||||
data.menu.open();
|
||||
|
||||
JX.DOM.listen(list, 'click', 'tag:a', function(e) {
|
||||
if (!e.isNormalClick()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If this item opens a submenu, we don't want to close the current
|
||||
// menu. One submenu is "Edit Related Objects..." on mobile.
|
||||
if (JX.Stratcom.hasSigil(e.getTarget(), 'keep-open')) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.menu.close();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -96,6 +96,8 @@ JX.install('PHUIXActionView', {
|
||||
className: classes.join(' ')
|
||||
};
|
||||
this._node = JX.$N('li', attr, content);
|
||||
|
||||
JX.Stratcom.addSigil(this._node, 'phuix-action-view');
|
||||
}
|
||||
|
||||
return this._node;
|
||||
|
||||
@@ -40,6 +40,12 @@ JX.install('PHUIXDropdownMenu', {
|
||||
JX.Stratcom.listen('phuix.dropdown.open', null, JX.bind(this, this.close));
|
||||
|
||||
JX.Stratcom.listen('keydown', null, JX.bind(this, this._onkey));
|
||||
|
||||
JX.DOM.listen(
|
||||
this._getMenuNode(),
|
||||
'click',
|
||||
'tag:a',
|
||||
JX.bind(this, this._onlink));
|
||||
},
|
||||
|
||||
events: ['open', 'close'],
|
||||
@@ -112,6 +118,28 @@ JX.install('PHUIXDropdownMenu', {
|
||||
e.prevent();
|
||||
},
|
||||
|
||||
_onlink: function(e) {
|
||||
if (!e.isNormalClick()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If this action was built dynamically with PHUIXActionView, don't
|
||||
// do anything by default. The caller is repsonsible for installing a
|
||||
// handler if they want to react to clicks.
|
||||
if (e.getNode('phuix-action-view')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If this item opens a submenu, we don't want to close the current
|
||||
// menu. One submenu is "Edit Related Objects..." on mobile.
|
||||
var link = e.getNode('tag:a');
|
||||
if (JX.Stratcom.hasSigil(link, 'keep-open')) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.close();
|
||||
},
|
||||
|
||||
_onanyclick : function(e) {
|
||||
if (!this._open) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user