@springernature/global-expander
Advanced tools
Comparing version 2.0.0 to 2.0.1
# History | ||
## 2.0.1 (2020-07-20) | ||
* Replace switch with if/else if when detecting AUTOFOCUS option | ||
* Move AUTOFOCUS into private helper class | ||
## 2.0.0 (2020-07-15) | ||
@@ -4,0 +8,0 @@ * Refactor AUTOFOCUS from boolean to string to set options |
@@ -19,2 +19,3 @@ import {makeArray, createEvent} from '@springernature/global-javascript/src/helpers'; | ||
this._options = Object.assign({}, defaultOptions, options); | ||
this._autoFocusElement = trigger; | ||
this._triggerEl = trigger; | ||
@@ -26,3 +27,2 @@ this._targetEl = target; | ||
)); | ||
this._isOpen = false; | ||
@@ -129,2 +129,20 @@ | ||
/** | ||
* AutoFocus | ||
*/ | ||
_handleAutoFocus() { | ||
if (this._options.AUTOFOCUS === 'target') { | ||
this._autoFocusElement = this._targetEl; | ||
this._targetEl.setAttribute('tabindex', '-1'); | ||
} | ||
if (this._options.AUTOFOCUS === 'firstTabbable') { | ||
this._autoFocusElement = this._targetTabbableItems.length > 0 && this._targetTabbableItems[0]; | ||
if (this._autoFocusElement.setSelectionRange) { | ||
this._autoFocusElement.setSelectionRange(0, this._autoFocusElement.value.length); | ||
} | ||
} | ||
this._autoFocusElement.focus(); | ||
} | ||
/** | ||
* @public | ||
@@ -157,24 +175,5 @@ */ | ||
} | ||
switch (this._options.AUTOFOCUS) { | ||
case 'firstTabbable': | ||
if (this._targetTabbableItems.length > 0) { | ||
const firstTabbableItem = this._targetTabbableItems[0]; | ||
firstTabbableItem.focus(); | ||
if (firstTabbableItem.setSelectionRange) { | ||
firstTabbableItem.setSelectionRange(0, firstTabbableItem.value.length); | ||
} | ||
} | ||
break; | ||
case 'target': | ||
this._targetEl.setAttribute('tabindex', '-1'); | ||
this._targetEl.focus(); | ||
break; | ||
default: | ||
break; | ||
} | ||
this._updateAriaAttributes(); | ||
this._setupTemporaryEventListeners(); | ||
this._handleAutoFocus(); | ||
} | ||
@@ -181,0 +180,0 @@ |
{ | ||
"name": "@springernature/global-expander", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Frontend package for expanding a target when clicking a toggle", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31669
762