@ideal-postcodes/address-finder
Advanced tools
Comparing version 4.1.0 to 4.2.0
@@ -394,2 +394,8 @@ /** | ||
unhideClass?: string; | ||
/** | ||
* Set CSS display attribute to `fixed` on the Address Finder list element | ||
* | ||
* @default false | ||
*/ | ||
fixed?: boolean; | ||
} | ||
@@ -741,2 +747,3 @@ /** | ||
export declare const findOrCreate: <T>(scope: HTMLElement | Document, q: string | T | null, create?: (() => T) | undefined) => T; | ||
export declare const setPositionFixed: (mainComponent: HTMLElement, container: HTMLElement, document: Document) => void; | ||
export {}; |
@@ -9,3 +9,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.findOrCreate = exports._onKeyDown = exports.Controller = exports.defaults = exports.NOOP = void 0; | ||
exports.setPositionFixed = exports.findOrCreate = exports._onKeyDown = exports.Controller = exports.defaults = exports.NOOP = void 0; | ||
/* eslint-disable no-invalid-this */ | ||
@@ -85,2 +85,4 @@ const announcer_1 = require("./announcer"); | ||
hide: [], | ||
//change list position | ||
fixed: false, | ||
// Callbacks | ||
@@ -305,2 +307,6 @@ onOpen: exports.NOOP, | ||
(0, css_1.addStyle)(this); | ||
if (this.options.fixed) { | ||
//set position fixed and width calculation | ||
(0, exports.setPositionFixed)(this.mainComponent, this.container, this.document); | ||
} | ||
this.options.onLoaded.call(this); | ||
@@ -847,1 +853,18 @@ } | ||
exports.findOrCreate = findOrCreate; | ||
const setPositionFixed = (mainComponent, container, document) => { | ||
const setMinWith = (scope, component) => { | ||
if (scope === null) | ||
return; | ||
const box = scope.getBoundingClientRect(); | ||
component.style.minWidth = `${Math.round(box.width)}px`; | ||
}; | ||
const parent = container.parentElement; | ||
mainComponent.style.position = "fixed"; | ||
mainComponent.style.left = "auto"; | ||
setMinWith(parent, mainComponent); | ||
document.defaultView !== null && | ||
document.defaultView.addEventListener("resize", () => { | ||
setMinWith(parent, mainComponent); | ||
}); | ||
}; | ||
exports.setPositionFixed = setPositionFixed; |
@@ -394,2 +394,8 @@ /** | ||
unhideClass?: string; | ||
/** | ||
* Set CSS display attribute to `fixed` on the Address Finder list element | ||
* | ||
* @default false | ||
*/ | ||
fixed?: boolean; | ||
} | ||
@@ -741,2 +747,3 @@ /** | ||
export declare const findOrCreate: <T>(scope: HTMLElement | Document, q: string | T | null, create?: (() => T) | undefined) => T; | ||
export declare const setPositionFixed: (mainComponent: HTMLElement, container: HTMLElement, document: Document) => void; | ||
export {}; |
@@ -77,2 +77,4 @@ /** | ||
hide: [], | ||
//change list position | ||
fixed: false, | ||
// Callbacks | ||
@@ -297,2 +299,6 @@ onOpen: NOOP, | ||
addStyle(this); | ||
if (this.options.fixed) { | ||
//set position fixed and width calculation | ||
setPositionFixed(this.mainComponent, this.container, this.document); | ||
} | ||
this.options.onLoaded.call(this); | ||
@@ -836,1 +842,17 @@ } | ||
}; | ||
export const setPositionFixed = (mainComponent, container, document) => { | ||
const setMinWith = (scope, component) => { | ||
if (scope === null) | ||
return; | ||
const box = scope.getBoundingClientRect(); | ||
component.style.minWidth = `${Math.round(box.width)}px`; | ||
}; | ||
const parent = container.parentElement; | ||
mainComponent.style.position = "fixed"; | ||
mainComponent.style.left = "auto"; | ||
setMinWith(parent, mainComponent); | ||
document.defaultView !== null && | ||
document.defaultView.addEventListener("resize", () => { | ||
setMinWith(parent, mainComponent); | ||
}); | ||
}; |
{ | ||
"name": "@ideal-postcodes/address-finder", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "Address Finder JS library backed by the Ideal Postcodes UK address search API", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
244392
6996