Fixed an error in containermenu where applying a prefix filter would
leave no item in the entire menu marked as active, causing pressing
enter to throw an error.
Change-Id: Iebdb778629a85cdb77aa7f4a6982dba25484bff5
diff --git a/dev/js/src/container/container.js b/dev/js/src/container/container.js
index 60bc0d9..9cf5205 100644
--- a/dev/js/src/container/container.js
+++ b/dev/js/src/container/container.js
@@ -41,13 +41,19 @@
// after having upgraded a new item scss style to the prefix object.
this.items = new Array();
+ //items are stored in the order they are added in. This includes the prefix.
if (listOfContainerItems !== undefined) {
for (let item of listOfContainerItems) {
this.addItem(item);
}
}
- this.position = undefined; //undefined = not in container, 0 to length-1 = in container
+ this.position = undefined; //undefined = not in container,
+ // 0 to length-1 = in container
+
+ this._prefixPosition = undefined; //Required so that switching
+ // to prefix by default is supported
+
//t._el.classList.add('visible'); //Done by containermenu
@@ -77,6 +83,7 @@
prefix.isSelectable = function () {
return this.isSet(); //TODO check!
}
+ this._prefixPosition = this.items.length;
var prefItem = this.addItem(prefix);
this._prefix = prefItem;
if (this._menu !== undefined){
@@ -124,6 +131,26 @@
},
/**
+ *
+ * Make the container active without having called prev or next.
+ * Occurs whenever the prefix makes the
+ * menus list empty while we had it selected.
+ * This potentially requires adjusting this.position.
+ */
+ makeActive : function () {
+ if (this.position === undefined) {
+ if (this._prefix.isSelectable()) {
+ this.position = this._prefixPosition; //make prefix active if it exists
+ this.item().active(true);
+ } else if (this.liveLength() > 0) {
+ this.position = 0;
+ this._prefix.active(false); // usually the menu makes the prefix active anyway.
+ this.item().active(true);
+ }
+ }
+ },
+
+ /**
* Move on to the next item in container. Returns true if we then leave the container, false otherwise.
*/
next : function() {