Skip to content

Commit b97a54e

Browse files
authored
Add height to popupOption (#114)
* add `height` option * pass height to constructor
1 parent 18a655b commit b97a54e

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

src/authsignal.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ export class Authsignal {
154154
private launchWithPopup(url: string, options: PopupLaunchOptions) {
155155
const {popupOptions} = options;
156156

157-
const popupHandler = new PopupHandler({width: popupOptions?.width, isClosable: popupOptions?.isClosable});
157+
const popupHandler = new PopupHandler({
158+
width: popupOptions?.width,
159+
height: popupOptions?.height,
160+
isClosable: popupOptions?.isClosable,
161+
});
158162

159163
const popupUrl = `${url}&mode=popup`;
160164

src/handlers/popup-handler.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,25 @@ type PopupShowInput = {
1616

1717
type PopupHandlerOptions = {
1818
width?: string;
19+
height?: string;
1920
isClosable?: boolean;
2021
};
2122

2223
export class PopupHandler {
2324
private popup: A11yDialog | null = null;
25+
private height: string | undefined;
2426

25-
constructor({width, isClosable}: PopupHandlerOptions) {
27+
constructor({width, height, isClosable}: PopupHandlerOptions) {
2628
if (document.querySelector(`#${CONTAINER_ID}`)) {
2729
throw new Error("Multiple instances of Authsignal popup is not supported.");
2830
}
2931

30-
this.create({width, isClosable});
32+
this.height = height;
33+
34+
this.create({width, height, isClosable});
3135
}
3236

33-
create({width = DEFAULT_WIDTH, isClosable = true}: PopupHandlerOptions) {
37+
create({width = DEFAULT_WIDTH, height, isClosable = true}: PopupHandlerOptions) {
3438
const isWidthValidCSSValue = CSS.supports("width", width);
3539

3640
let popupWidth = width;
@@ -102,8 +106,8 @@ export class PopupHandler {
102106
width: 1px;
103107
min-width: 100%;
104108
border-radius: inherit;
105-
max-height: 95vh;
106-
height: ${INITIAL_HEIGHT};
109+
max-height: ${height ? "100%" : "95vh"};
110+
height: ${height ?? INITIAL_HEIGHT};
107111
}
108112
`;
109113

@@ -157,7 +161,10 @@ export class PopupHandler {
157161
dialogContent.appendChild(iframe);
158162
}
159163

160-
window.addEventListener("message", resizeIframe);
164+
// Dynamic resizing if no height is set.
165+
if (!this.height) {
166+
window.addEventListener("message", resizeIframe);
167+
}
161168

162169
this.popup?.show();
163170
}
@@ -179,6 +186,10 @@ export class PopupHandler {
179186
}
180187
}
181188

189+
/**
190+
* Resize the iframe to the height of the pre-built UI's (#widget_container)
191+
* @param event MessageEvent
192+
*/
182193
function resizeIframe(event: MessageEvent) {
183194
const iframeEl = document.querySelector<HTMLIFrameElement>(`#${IFRAME_ID}`);
184195

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type PopupLaunchOptions = BaseLaunchOptions & {
2020
/** Any valid CSS value for the `width` property. */
2121
width?: string;
2222
/**
23-
* @deprecated The popup will automatically resize to fit the content.
23+
* Set the height of the popup. If not set, the popup will automatically resize to fit the content.
2424
*/
2525
height?: string;
2626
/**

0 commit comments

Comments
 (0)