@springernature/global-popup
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -43,3 +43,3 @@ import {Popup} from '../js/popup'; | ||
expect(spy).toHaveBeenCalled(); | ||
expect(typeof spy.mock.results[0].value.top).toBe('number'); | ||
expect(typeof spy.mock.results[0].value).toBe('number'); | ||
@@ -46,0 +46,0 @@ }); |
# History | ||
## 1.0.1 (2020-08-05) | ||
* Fixes issue with position calculation | ||
* Makes styles js only | ||
## 1.0.0 (2020-07-31) | ||
@@ -4,0 +8,0 @@ * Removes min-width and max-width from css and sets in js as option. |
@@ -44,3 +44,3 @@ import {Expander} from '@springernature/global-expander/js/expander'; | ||
const pos = this._calcPositioning(); | ||
this._content.style.top = this._px(pos.top); | ||
this._content.style.top = this._px(pos); | ||
if (this._options.MAX_WIDTH) { | ||
@@ -111,17 +111,16 @@ this._content.style.maxWidth = this._options.MAX_WIDTH; | ||
// calc where to position the popup above the trigger | ||
// (trigger's distance from top of viewport - popup content's height - arrow's height) | ||
const abovePositioning = offset.top - this._content.offsetHeight - arrowHeight; | ||
// calc space above trigger | ||
const spaceAbove = offset.top - this._content.offsetHeight - arrowHeight; | ||
// calc where to position the popup below the trigger | ||
// (trigger's distance from top of viewport + trigger's height + arrow's height) | ||
const belowPositioning = offset.top + triggerMetrics.height + arrowHeight; | ||
const abovePosition = 0 - this._content.offsetHeight - arrowHeight; | ||
const belowPosition = 0 + triggerMetrics.height + arrowHeight; | ||
let position = 'above'; | ||
let top; | ||
// if there is not enough room for popup above trigger | ||
if (abovePositioning < distanceScrolled) { | ||
position = 'below'; | ||
if (spaceAbove < distanceScrolled) { | ||
top = belowPosition; | ||
arrow.classList.remove(this._arrowClass + '--above'); | ||
arrow.classList.add(this._arrowClass + '--below'); | ||
} else { | ||
top = abovePosition; | ||
arrow.classList.remove(this._arrowClass + '--below'); | ||
@@ -139,5 +138,3 @@ arrow.classList.add(this._arrowClass + '--above'); | ||
return { | ||
top: (position === 'above') ? abovePositioning : belowPositioning | ||
}; | ||
return top; | ||
} | ||
@@ -144,0 +141,0 @@ }; |
{ | ||
"name": "@springernature/global-popup", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Builds and styles a popup that can be opened and closed", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
17669
323