Skip to content

Commit de68699

Browse files
committed
fix: Use the form background behind the fullscreen mobile popup
On phones the popup fills the viewport and iOS Safari paints the status bar and bottom toolbar from the fixed container's own background, so the dark scrim shows up as grey bands around the form. Set a CSS custom property from the form-theme message (as the widget fullscreen modal already does) and consume it only inside the mobile media query, keeping the dark scrim on desktop and until the theme arrives. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RkM7Yh51Sqg4iADSZnyJXL
1 parent ffcede3 commit de68699

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎packages/embed/src/css/popup.scss‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
@include mobile {
3535
.tf-v1-popup {
3636
@include fullsize;
37+
background: var(--tf-popup-background, rgba(0, 0, 0, 0.75));
3738

3839
.tf-v1-iframe-wrapper {
3940
position: relative;

‎packages/embed/src/factories/create-popup/create-popup.spec.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ describe('create-popup', () => {
4141
expect(wrapper.style.width).toBe('200px')
4242
expect(wrapper.style.height).toBe('100px')
4343
})
44+
45+
it('should set the popup background from the form theme', () => {
46+
const popupElement = container.querySelector('.tf-v1-popup') as HTMLElement
47+
const iframe = popupElement.querySelector('iframe') as HTMLIFrameElement
48+
const embedId = new URL(iframe.src).searchParams.get('typeform-embed-id')
49+
50+
window.dispatchEvent(
51+
new MessageEvent('message', {
52+
data: { type: 'form-theme', embedId: 'other-embed-id', theme: { backgroundColor: 'rgba(0, 0, 255, 0)' } },
53+
})
54+
)
55+
expect(popupElement.style.getPropertyValue('--tf-popup-background')).toBe('')
56+
57+
window.dispatchEvent(
58+
new MessageEvent('message', {
59+
data: { type: 'form-theme', embedId, theme: { backgroundColor: 'rgba(255, 200, 0, 0)' } },
60+
})
61+
)
62+
expect(popupElement.style.getPropertyValue('--tf-popup-background')).toBe('rgba(255, 200, 0, 255)')
63+
})
4464
})
4565

4666
describe('#close', () => {

‎packages/embed/src/factories/create-popup/create-popup.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import {
1010
invokeWithoutDefault,
1111
handlePreventReopenOnClose,
1212
closeIconSvg,
13+
changeColorOpacity,
1314
} from '../../utils'
1415
import type { RemoveHandler } from '../../utils'
16+
import { getFormThemeHandler } from '../../utils/create-iframe/get-form-event-handler'
1517
import { POPUP_SIZE } from '../../constants'
1618
import { isInPage, isOpen } from '../../utils'
1719
import { EmbedPopup } from '../../base'
@@ -84,6 +86,16 @@ export const createPopup = (formId: string, userOptions: PopupOptions = {}): Pop
8486
popup.append(spinner)
8587
popup.append(wrapper)
8688

89+
window.addEventListener(
90+
'message',
91+
getFormThemeHandler(embedId, (data) => {
92+
const backgroundColor = data?.theme?.backgroundColor
93+
if (backgroundColor) {
94+
popup.style.setProperty('--tf-popup-background', changeColorOpacity(backgroundColor))
95+
}
96+
})
97+
)
98+
8799
const container = options.container || document.body
88100

89101
iframe.onload = (event) => {

0 commit comments

Comments
 (0)