Fix bug in btngroup anchoring when anchor doesn't exist
Change-Id: Id89aa31edf6d9ee06046b22f6f4cefa34366f46e
diff --git a/Changes b/Changes
index 24aebd0..edb7691 100755
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.43 2021-09-15
+0.43 2021-09-24
- New menu class that has an entry at the very end,
similar to the input text prefix,
that is always available. (lerepp)
@@ -31,6 +31,7 @@
- Add plugin service to redirect to a certain location.
- Add support for pagination information to retrieve by plugins.
- Buttongroup menus can be opened at different positions.
+ - Fix buttongroup anchoring if anchor doesn't exist.
0.42 2021-06-18
- Added GitHub based CI for perl.
diff --git a/dev/js/spec/buttongroupSpec.js b/dev/js/spec/buttongroupSpec.js
index 258d847..07183f2 100644
--- a/dev/js/spec/buttongroupSpec.js
+++ b/dev/js/spec/buttongroupSpec.js
@@ -256,8 +256,11 @@
const c1 = el.appendChild(document.createElement('c1'));
const c2 = el.appendChild(document.createElement('c2'));
const c3 = el.appendChild(document.createElement('c3'));
+
+ let group = buttonGroupClass.adopt(el);
+ expect(group.anchor(null)).toBeFalsy();
- const group = buttonGroupClass.adopt(el);
+ group = buttonGroupClass.adopt(el);
expect(group.anchor(c3)).toBeTruthy();
group.add('Meta', {'cls':['meta', 'top']}, function (e) {});
diff --git a/dev/js/src/buttongroup.js b/dev/js/src/buttongroup.js
index 721fdcb..dabe710 100644
--- a/dev/js/src/buttongroup.js
+++ b/dev/js/src/buttongroup.js
@@ -57,7 +57,7 @@
* Define element following newly added buttons.
*/
anchor : function (anchor) {
- if (anchor.parentNode == this._el) {
+ if (anchor !== null && anchor.parentNode == this._el) {
this._anchor = anchor;
return true;
};