add jsdoc for menu.collapse and provide ability to opt-out of updating the scroll position if needed

This commit is contained in:
Braden Napier 2019-03-18 21:14:12 -07:00
parent 574c1c15b9
commit e304e79290

View File

@ -220,16 +220,25 @@ export class MenuStore {
} }
} }
collapse(item: IMenuItem) { /**
* Collapsed the given item without collapsing all parent items like
* `deactivate` does. This is used to close a group item when clicked
* if it is already expanded.
*
* @param {IMenuItem} item
*/
collapse(item: IMenuItem, updateScrollPosition: boolean = true) {
this.activate(item.parent, true, true, false); this.activate(item.parent, true, true, false);
const activeItem = this.activeItem; if (updateScrollPosition) {
if (item.items.length > 0) { const activeItem = this.activeItem;
this.scroll.scrollIntoView(this.getElementAt(item.absoluteIdx || -1)); if (item.items.length > 0) {
} else if (!activeItem) { this.scroll.scrollIntoView(this.getElementAt(item.absoluteIdx || -1));
const parentIdx = (item.parent && item.parent.absoluteIdx) || -1; } else if (!activeItem) {
this.scroll.scrollIntoView(this.getElementAt(parentIdx)); const parentIdx = (item.parent && item.parent.absoluteIdx) || -1;
} else { this.scroll.scrollIntoView(this.getElementAt(parentIdx));
this.scroll.scrollIntoView(this.getElementAt(activeItem.absoluteIdx || -1)); } else {
this.scroll.scrollIntoView(this.getElementAt(activeItem.absoluteIdx || -1));
}
} }
} }