diff --git a/core/misc/splitbutton/splitbutton.es6.js b/core/misc/splitbutton/splitbutton.es6.js index b1bdaa3357..88fe3f5982 100644 --- a/core/misc/splitbutton/splitbutton.es6.js +++ b/core/misc/splitbutton/splitbutton.es6.js @@ -70,7 +70,8 @@ // If this.menuItems is empty, the initialization hasn't occurred yet. if (this.menuItems.length === 0) { const itemTags = - this.menu.getAttribute('data-drupal-splitbutton-item-tags') || 'a, input, button'; + this.menu.getAttribute('data-drupal-splitbutton-item-tags') || + 'a, input, button'; Array.prototype.slice .call(this.menu.querySelectorAll(itemTags)) .forEach((item, index) => { @@ -132,7 +133,7 @@ ) ? 'close' : 'open'; - this[state](); + this[state](e.detail === 0); } /** @@ -158,7 +159,7 @@ /** * Opens splitbutton menu. */ - open() { + open(focusFirst = true) { this.initMenuItems(); this.toggle(true); if (!this.hasOwnProperty('popper')) { @@ -166,9 +167,12 @@ } else { this.popper.forceUpdate(); } - // Wrap in a zero-wait timeout to ensure it isn't called until - // initMenuItems() completes. - setTimeout(() => this.focusFirst(), 0); + + if (focusFirst) { + // Wrap in a zero-wait timeout to ensure it isn't called until + // initMenuItems() completes. + setTimeout(() => this.focusFirst(), 0); + } } /** diff --git a/core/misc/splitbutton/splitbutton.js b/core/misc/splitbutton/splitbutton.js index e8b37a30a3..645be5dac1 100644 --- a/core/misc/splitbutton/splitbutton.js +++ b/core/misc/splitbutton/splitbutton.js @@ -106,7 +106,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d e.preventDefault(); e.stopPropagation(); var state = this.splitbutton.hasAttribute('data-drupal-splitbutton-open') ? 'close' : 'open'; - this[state](); + this[state](e.detail === 0); } }, { key: "toggle", @@ -128,6 +128,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d value: function open() { var _this3 = this; + var focusFirst = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; this.initMenuItems(); this.toggle(true); @@ -137,9 +138,11 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d this.popper.forceUpdate(); } - setTimeout(function () { - return _this3.focusFirst(); - }, 0); + if (focusFirst) { + setTimeout(function () { + return _this3.focusFirst(); + }, 0); + } } }, { key: "close",