From 67b5d1d240eaf66f85520f86012e0e8f4fbd01bf Mon Sep 17 00:00:00 2001 From: David Kirkland Date: Wed, 4 Nov 2026 06:10:31 +0000 Subject: [PATCH 01/13] fix(feedback): Improve dialog keyboard access and input contrast Fixes #26081 --- .../suites/feedback/accessibility/init.js | 9 + .../feedback/accessibility/template.html | 6 + .../suites/feedback/accessibility/test.ts | 195 ++++++++++++++++++ .../feedback/src/core/createMainStyles.ts | 4 + .../src/modal/components/Dialog.css.ts | 6 + .../feedback/src/modal/components/Dialog.tsx | 69 ++++++- .../src/modal/components/DialogHeader.tsx | 6 +- packages/feedback/src/modal/integration.tsx | 35 +++- 8 files changed, 320 insertions(+), 10 deletions(-) create mode 100644 dev-packages/browser-integration-tests/suites/feedback/accessibility/init.js create mode 100644 dev-packages/browser-integration-tests/suites/feedback/accessibility/template.html create mode 100644 dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts diff --git a/dev-packages/browser-integration-tests/suites/feedback/accessibility/init.js b/dev-packages/browser-integration-tests/suites/feedback/accessibility/init.js new file mode 100644 index 000000000000..b041bee3585a --- /dev/null +++ b/dev-packages/browser-integration-tests/suites/feedback/accessibility/init.js @@ -0,0 +1,9 @@ +import * as Sentry from '@sentry/browser'; +import { feedbackIntegration } from '@sentry/browser'; + +window.Sentry = Sentry; + +Sentry.init({ + dsn: 'https://public@dsn.ingest.sentry.io/1337', + integrations: [feedbackIntegration({ colorScheme: 'light' })], +}); diff --git a/dev-packages/browser-integration-tests/suites/feedback/accessibility/template.html b/dev-packages/browser-integration-tests/suites/feedback/accessibility/template.html new file mode 100644 index 000000000000..d8619fa4ffcd --- /dev/null +++ b/dev-packages/browser-integration-tests/suites/feedback/accessibility/template.html @@ -0,0 +1,6 @@ + + + + + + diff --git a/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts b/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts new file mode 100644 index 000000000000..4c8fb25907c5 --- /dev/null +++ b/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts @@ -0,0 +1,195 @@ +import { expect } from '@playwright/test'; +import type * as SentrySDK from '@sentry/browser'; +import { sentryTest } from '../../../utils/fixtures'; +import { shouldSkipFeedbackTest } from '../../../utils/helpers'; + +sentryTest.beforeEach(async ({ getLocalTestUrl, page }) => { + sentryTest.skip(shouldSkipFeedbackTest()); + await page.goto(await getLocalTestUrl({ testDir: __dirname, handleLazyLoadedFeedback: true })); +}); + +sentryTest('names the native modal and restores focus after repeated keyboard dismissal @firefox', async ({ page }) => { + const launcher = page.getByRole('button', { name: 'Report a Bug', exact: true }); + const dialog = page.locator('dialog'); + + for (const key of ['Escape', 'Enter', 'Escape']) { + await launcher.focus(); + await page.keyboard.press('Enter'); + await expect(dialog).toBeVisible(); + await expect(dialog).toHaveAccessibleName('Report a Bug'); + await expect(dialog).toHaveJSProperty('open', true); + expect(await dialog.evaluate(el => el.matches(':modal'))).toBe(true); + await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); + + await page.locator('#background').evaluate(el => (el as HTMLElement).focus()); + await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); + + if (key === 'Enter') { + await page.getByRole('button', { name: 'Cancel', exact: true }).focus(); + } else { + await page.getByRole('textbox', { name: 'Name', exact: true }).focus(); + } + await page.keyboard.press(key); + await expect(dialog).not.toBeVisible(); + await expect(launcher).toBeFocused(); + } +}); + +sentryTest('keeps keyboard navigation inside the modal @firefox', async ({ page }) => { + await page.getByRole('button', { name: 'Report a Bug', exact: true }).click(); + const cancel = page.getByRole('button', { name: 'Cancel', exact: true }); + await cancel.focus(); + await page.keyboard.press('Tab'); + await expect(page.getByRole('link', { name: 'Powered by Sentry' })).toBeFocused(); + await page.keyboard.press('Shift+Tab'); + await expect(cancel).toBeFocused(); + await page.keyboard.press('Escape'); + await expect(page.locator('dialog')).not.toBeVisible(); +}); + +sentryTest('returns to a custom launcher inside another native modal @firefox', async ({ page }) => { + await page.evaluate(() => { + const { Sentry } = window as unknown as { Sentry: typeof SentrySDK }; + const parent = document.createElement('dialog'); + parent.id = 'parent-modal'; + document.body.appendChild(parent); + parent.appendChild(document.querySelector('#background')!); + parent.showModal(); + Sentry.getFeedback()!.attachTo('#background', { + formTitle: 'Custom feedback title', + showName: false, + showEmail: false, + showBranding: false, + enableScreenshot: false, + }); + }); + const launcher = page.getByRole('button', { name: 'Background control' }); + await launcher.click(); + await expect(page.getByRole('dialog', { name: 'Custom feedback title' })).toBeVisible(); + await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); + await page.getByRole('button', { name: 'Cancel', exact: true }).focus(); + await page.keyboard.press('Tab'); + await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); + await page.keyboard.press('Shift+Tab'); + await expect(page.getByRole('button', { name: 'Cancel', exact: true })).toBeFocused(); + await page.keyboard.press('Escape'); + await expect(launcher).toBeFocused(); + expect(await page.locator('#parent-modal').evaluate(el => el.matches(':modal'))).toBe(true); +}); + +sentryTest('dismisses on backdrop click and restores focus @firefox', async ({ page }) => { + const launcher = page.getByRole('button', { name: 'Report a Bug', exact: true }); + await launcher.focus(); + await page.keyboard.press('Enter'); + await page.locator('dialog').click({ position: { x: 1, y: 1 } }); + await expect(page.locator('dialog')).not.toBeVisible(); + await expect(launcher).toBeFocused(); +}); + +sentryTest( + 'programmatic close and removal release modal state and preserve body overflow @firefox', + async ({ page }) => { + const launcher = page.locator('#background'); + await launcher.focus(); + const form = await page.evaluateHandle(async () => { + const { Sentry } = window as unknown as { Sentry: typeof SentrySDK }; + document.body.style.overflow = 'scroll'; + const form = await Sentry.getFeedback()!.createForm(); + form.appendToDom(); + return form; + }); + + for (const remove of [false, true]) { + await form.evaluate(form => { + form.open(); + form.open(); + }); + await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); + await form.evaluate((form, remove) => (remove ? form.removeFromDom() : form.close()), remove); + await expect(page.locator('dialog:modal')).toHaveCount(0); + await expect(launcher).toBeFocused(); + expect(await page.evaluate(() => document.body.style.overflow)).toBe('scroll'); + } + await form.evaluate(form => { + form.appendToDom(); + form.open(); + }); + await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); + }, +); + +sentryTest('restores the launcher after successful submission @firefox', async ({ page }) => { + const launcher = page.getByRole('button', { name: 'Report a Bug', exact: true }); + await launcher.focus(); + await page.keyboard.press('Enter'); + await page.getByRole('textbox', { name: 'Description' }).fill('Feedback sent to the local test transport'); + await page.getByRole('button', { name: 'Send Bug Report' }).click(); + await expect(page.locator('dialog:modal')).toHaveCount(0); + await expect(page.locator('.success__content')).toBeVisible(); + await page.locator('.success__content').click(); + await expect(launcher).toBeFocused(); + await page.keyboard.press('Enter'); + await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); +}); + +sentryTest('preserves input border overrides @firefox', async ({ page }) => { + await page.locator('#sentry-feedback').evaluate(el => { + (el as HTMLElement).style.setProperty('--input-border', '2px solid rgb(0, 0, 255)'); + }); + await page.getByRole('button', { name: 'Report a Bug', exact: true }).click(); + await expect(page.locator('[name="name"]')).toHaveCSS('border-top-color', 'rgb(0, 0, 255)'); + await expect(page.locator('[name="name"]')).toHaveCSS('border-top-width', '2px'); +}); + +sentryTest('keeps the form usable without native dialog methods @firefox', async ({ page }) => { + await page.evaluate(() => { + Object.defineProperty(HTMLDialogElement.prototype, 'showModal', { value: undefined }); + Object.defineProperty(HTMLDialogElement.prototype, 'close', { value: undefined }); + }); + const launcher = page.getByRole('button', { name: 'Report a Bug', exact: true }); + for (const key of ['Escape', 'Enter']) { + await launcher.focus(); + await page.keyboard.press('Enter'); + await expect(page.getByRole('dialog', { name: 'Report a Bug' })).toBeVisible(); + await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); + await page.getByRole('button', { name: 'Cancel', exact: true }).focus(); + await page.keyboard.press('Tab'); + await expect(page.getByRole('link', { name: 'Powered by Sentry' })).toBeFocused(); + await page.keyboard.press('Shift+Tab'); + await page.keyboard.press(key); + await expect(page.locator('dialog')).not.toBeVisible(); + await expect(launcher).toBeFocused(); + } +}); + +for (const scheme of ['light', 'dark'] as const) { + sentryTest(`enabled input boundaries have 3:1 contrast in ${scheme} mode @firefox`, async ({ page }) => { + await page.evaluate(scheme => { + const { Sentry } = window as unknown as { Sentry: typeof SentrySDK }; + Sentry.getFeedback()!.setTheme(scheme); + }, scheme); + await page.getByRole('button', { name: 'Report a Bug', exact: true }).click(); + await page.getByRole('button', { name: 'Cancel', exact: true }).focus(); + + for (const name of ['name', 'email', 'message']) { + const contrast = await page.locator(`[name="${name}"]`).evaluate(el => { + const rgb = (color: string): number[] => color.match(/[\d.]+/g)!.map(Number); + const background = rgb(getComputedStyle(el.closest('.dialog__content')!).backgroundColor); + const border = rgb(getComputedStyle(el).borderTopColor); + const alpha = border[3] ?? 1; + const composited = border.slice(0, 3).map((channel, i) => channel * alpha + background[i] * (1 - alpha)); + const luminance = (channels: number[]): number => + channels.slice(0, 3).reduce((sum, channel, i) => { + const value = channel / 255; + return ( + sum + (value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4) * [0.2126, 0.7152, 0.0722][i] + ); + }, 0); + const a = luminance(composited); + const b = luminance(background); + return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05); + }); + expect(contrast).toBeGreaterThanOrEqual(3); + } + }); +} diff --git a/packages/feedback/src/core/createMainStyles.ts b/packages/feedback/src/core/createMainStyles.ts index 36d38e62740a..3977f165448d 100644 --- a/packages/feedback/src/core/createMainStyles.ts +++ b/packages/feedback/src/core/createMainStyles.ts @@ -5,6 +5,7 @@ const PURPLE = 'rgba(88, 74, 192, 1)'; interface InternalTheme extends NonNullable { border: string; + inputBorder: string; interactiveFilter: string; } @@ -16,6 +17,7 @@ const DEFAULT_LIGHT: InternalTheme = { successColor: '#268d75', errorColor: '#df3338', border: '1.5px solid rgba(41, 35, 47, 0.13)', + inputBorder: '1.5px solid rgba(41, 35, 47, 0.6)', boxShadow: '0px 4px 24px 0px rgba(43, 34, 51, 0.12)', outline: '1px auto var(--accent-background)', interactiveFilter: 'brightness(95%)', @@ -28,6 +30,7 @@ const DEFAULT_DARK: InternalTheme = { successColor: '#2da98c', errorColor: '#f55459', border: '1.5px solid rgba(235, 230, 239, 0.15)', + inputBorder: '1.5px solid rgba(235, 230, 239, 0.6)', boxShadow: '0px 4px 24px 0px rgba(43, 34, 51, 0.12)', outline: '1px auto var(--accent-background)', interactiveFilter: 'brightness(150%)', @@ -42,6 +45,7 @@ function getThemedCssVariables(theme: InternalTheme): string { --success-color: ${theme.successColor}; --error-color: ${theme.errorColor}; --border: ${theme.border}; + --input-border: ${theme.inputBorder}; --box-shadow: ${theme.boxShadow}; --outline: ${theme.outline}; --interactive-filter: ${theme.interactiveFilter}; diff --git a/packages/feedback/src/modal/components/Dialog.css.ts b/packages/feedback/src/modal/components/Dialog.css.ts index 369321343f61..b1256bfe26a1 100644 --- a/packages/feedback/src/modal/components/Dialog.css.ts +++ b/packages/feedback/src/modal/components/Dialog.css.ts @@ -13,6 +13,8 @@ const DIALOG = ` padding: 0; height: 100vh; width: 100vw; + max-height: none; + max-width: none; color: var(--dialog-color, var(--foreground)); fill: var(--dialog-color, var(--foreground)); @@ -25,6 +27,10 @@ const DIALOG = ` transition: opacity 0.2s ease-in-out; } +.dialog::backdrop { + background: transparent; +} + .dialog__position { position: fixed; z-index: var(--z-index); diff --git a/packages/feedback/src/modal/components/Dialog.tsx b/packages/feedback/src/modal/components/Dialog.tsx index dceaec5e468b..cd5ff86e6f3b 100644 --- a/packages/feedback/src/modal/components/Dialog.tsx +++ b/packages/feedback/src/modal/components/Dialog.tsx @@ -1,7 +1,7 @@ import type { FeedbackFormData, FeedbackInternalOptions } from '@sentry/core'; import type { VNode } from 'preact'; import { Fragment, h } from 'preact'; // eslint-disable-line @typescript-eslint/no-unused-vars -import { useCallback, useMemo, useState } from 'preact/hooks'; +import { useCallback, useId, useLayoutEffect, useMemo, useRef, useState } from 'preact/hooks'; import { SUCCESS_MESSAGE_TIMEOUT } from '../../constants'; import type { Props as HeaderProps } from './DialogHeader'; import { DialogHeader } from './DialogHeader'; @@ -20,6 +20,35 @@ export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode { const successIconHtml = useMemo(() => ({ __html: SuccessIcon().outerHTML }), []); const [timeoutId, setTimeoutId] = useState(null); + const dialogRef = useRef(null); + const titleId = useId(); + + useLayoutEffect(() => { + const dialog = dialogRef.current; + if (open && dialog && !dialog.open) { + if (typeof dialog.showModal === 'function') { + dialog.showModal(); + } else { + dialog.setAttribute('open', ''); + dialog.querySelector('[autofocus]')?.focus(); + } + } + return () => { + if (typeof dialog?.close === 'function') { + dialog.close(); + } else { + dialog?.removeAttribute('open'); + } + }; + }, [open, timeoutId]); + + useLayoutEffect(() => { + return () => { + if (timeoutId) { + clearTimeout(timeoutId); + } + }; + }, [timeoutId]); const handleOnSuccessClick = useCallback(() => { if (timeoutId) { @@ -52,7 +81,41 @@ export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode { ) : ( - + { + event.preventDefault(); + props.onFormClose(); + }} + onKeyDown={event => { + if (event.key === 'Escape' && typeof event.currentTarget.showModal !== 'function') { + event.preventDefault(); + props.onFormClose(); + return; + } + if (event.key !== 'Tab') { + return; + } + const controls = Array.from( + event.currentTarget.querySelectorAll('a[href], button, input, textarea, select, [tabindex]'), + ).filter( + control => control.tabIndex >= 0 && !control.matches(':disabled') && control.getClientRects().length > 0, + ); + const first = controls[0]; + const last = controls[controls.length - 1]; + if (event.shiftKey && event.target === first) { + event.preventDefault(); + last?.focus(); + } else if (!event.shiftKey && event.target === last) { + event.preventDefault(); + first?.focus(); + } + }} + >
- +
diff --git a/packages/feedback/src/modal/components/DialogHeader.tsx b/packages/feedback/src/modal/components/DialogHeader.tsx index 8820b91d8a3a..f5d00659ab18 100644 --- a/packages/feedback/src/modal/components/DialogHeader.tsx +++ b/packages/feedback/src/modal/components/DialogHeader.tsx @@ -8,12 +8,14 @@ export interface Props { options: FeedbackInternalOptions; } -export function DialogHeader({ options }: Props): VNode { +export function DialogHeader({ options, titleId }: Props & { titleId: string }): VNode { const logoHtml = useMemo(() => ({ __html: SentryLogo().outerHTML }), []); return (

- {options.formTitle} + + {options.formTitle} + {options.showBranding ? ( { const style = createDialogStyles(options.styleNonce); let originalOverflow = ''; + let isOpen = false; + let previousFocus: Element | null = null; + + const restoreFocus = (): void => { + const target = previousFocus; + // The launcher is shown by the close/submitted callback after the dialog closes. + void Promise.resolve().then(() => { + if (!isOpen && target === previousFocus && target instanceof HTMLElement && target.isConnected) { + target.focus(); + } + }); + }; const dialog: ReturnType = { get el() { return el; @@ -43,20 +55,33 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => { } }, removeFromDom(): void { + dialog.close(); + render(null, el); el.remove(); style.remove(); - DOCUMENT.body.style.overflow = originalOverflow; }, open() { + if (isOpen) { + return; + } + previousFocus = DOCUMENT.activeElement; + while (previousFocus?.shadowRoot?.activeElement) { + previousFocus = previousFocus.shadowRoot.activeElement; + } + originalOverflow = DOCUMENT.body.style.overflow; + isOpen = true; renderContent(true); options.onFormOpen?.(); getClient()?.emit('openFeedbackWidget'); - originalOverflow = DOCUMENT.body.style.overflow; DOCUMENT.body.style.overflow = 'hidden'; }, close() { + if (isOpen) { + isOpen = false; + DOCUMENT.body.style.overflow = originalOverflow; + } renderContent(false); - DOCUMENT.body.style.overflow = originalOverflow; + restoreFocus(); }, }; @@ -72,12 +97,12 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => { defaultName={String((userKey && user?.[userKey.name]) || '')} defaultEmail={String((userKey && user?.[userKey.email]) || '')} onFormClose={() => { - renderContent(false); + dialog.close(); options.onFormClose?.(); }} onSubmit={sendFeedback} onSubmitSuccess={(data: FeedbackFormData, eventId: string) => { - renderContent(false); + dialog.close(); options.onSubmitSuccess?.(data, eventId); }} onSubmitError={(error: Error) => { From e4535c13e4acde495f4ca1f457dc09956b13ed93 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 10:49:44 +0000 Subject: [PATCH 02/13] fix(feedback): Give each feedback dialog a unique title id Preact's useId restarts for every render() root, so every dialog in the shared shadow root got the same id and aria-labelledby resolved to the first dialog's title. Co-Authored-By: Martin Sonnberger <26038247+msonnb@users.noreply.github.com> --- .../suites/feedback/accessibility/test.ts | 14 ++++++++++++++ packages/feedback/src/modal/components/Dialog.tsx | 7 +++---- .../feedback/src/modal/components/DialogHeader.tsx | 3 ++- packages/feedback/src/modal/integration.tsx | 5 +++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts b/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts index 4c8fb25907c5..e117ba5b76ca 100644 --- a/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts +++ b/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts @@ -193,3 +193,17 @@ for (const scheme of ['light', 'dark'] as const) { } }); } + +sentryTest('names each dialog after its own title @firefox', async ({ page }) => { + await page.evaluate(async () => { + const { Sentry } = window as unknown as { Sentry: typeof SentrySDK }; + const first = await Sentry.getFeedback()!.createForm({ formTitle: 'First form' }); + first.appendToDom(); + first.open(); + first.close(); + const second = await Sentry.getFeedback()!.createForm({ formTitle: 'Second form' }); + second.appendToDom(); + second.open(); + }); + await expect(page.getByRole('dialog', { name: 'Second form' })).toBeVisible(); +}); diff --git a/packages/feedback/src/modal/components/Dialog.tsx b/packages/feedback/src/modal/components/Dialog.tsx index cd5ff86e6f3b..3400edd08b30 100644 --- a/packages/feedback/src/modal/components/Dialog.tsx +++ b/packages/feedback/src/modal/components/Dialog.tsx @@ -1,7 +1,7 @@ import type { FeedbackFormData, FeedbackInternalOptions } from '@sentry/core'; import type { VNode } from 'preact'; import { Fragment, h } from 'preact'; // eslint-disable-line @typescript-eslint/no-unused-vars -import { useCallback, useId, useLayoutEffect, useMemo, useRef, useState } from 'preact/hooks'; +import { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'preact/hooks'; import { SUCCESS_MESSAGE_TIMEOUT } from '../../constants'; import type { Props as HeaderProps } from './DialogHeader'; import { DialogHeader } from './DialogHeader'; @@ -21,7 +21,6 @@ export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode { const [timeoutId, setTimeoutId] = useState(null); const dialogRef = useRef(null); - const titleId = useId(); useLayoutEffect(() => { const dialog = dialogRef.current; @@ -85,7 +84,7 @@ export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode { class="dialog" ref={dialogRef} role="dialog" - aria-labelledby={titleId} + aria-labelledby={props.titleId} onClick={props.onFormClose} onCancel={event => { event.preventDefault(); @@ -124,7 +123,7 @@ export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode { e.stopPropagation(); }} > - + diff --git a/packages/feedback/src/modal/components/DialogHeader.tsx b/packages/feedback/src/modal/components/DialogHeader.tsx index f5d00659ab18..d98f21676a32 100644 --- a/packages/feedback/src/modal/components/DialogHeader.tsx +++ b/packages/feedback/src/modal/components/DialogHeader.tsx @@ -6,9 +6,10 @@ import { SentryLogo } from './SentryLogo'; export interface Props { options: FeedbackInternalOptions; + titleId: string; } -export function DialogHeader({ options, titleId }: Props & { titleId: string }): VNode { +export function DialogHeader({ options, titleId }: Props): VNode { const logoHtml = useMemo(() => ({ __html: SentryLogo().outerHTML }), []); return ( diff --git a/packages/feedback/src/modal/integration.tsx b/packages/feedback/src/modal/integration.tsx index 5816a3374e0a..d2a853825ba6 100644 --- a/packages/feedback/src/modal/integration.tsx +++ b/packages/feedback/src/modal/integration.tsx @@ -19,6 +19,8 @@ function getUser(): User | undefined { return globalUser; } +let dialogCount = 0; + export const feedbackModalIntegration = ((): FeedbackModalIntegration => { return { name: 'FeedbackModal' as const, @@ -30,6 +32,8 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => { const el = DOCUMENT.createElement('div'); const style = createDialogStyles(options.styleNonce); + // Preact's `useId` restarts for every `render()` root, and all dialogs share one shadow root. + const titleId = `sentry-feedback-title-${++dialogCount}`; let originalOverflow = ''; let isOpen = false; @@ -91,6 +95,7 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => { render( Date: Tue, 17 Nov 2026 10:50:09 +0000 Subject: [PATCH 03/13] fix(feedback): Fall back to a non-modal dialog when showModal throws showModal() throws in iframes sandboxed without allow-modals. The exception escaped the layout effect and left the widget unable to open again. Also focus the autofocus control explicitly, since WebKit did not move focus there in CI. Co-Authored-By: Martin Sonnberger <26038247+msonnb@users.noreply.github.com> --- .../suites/feedback/accessibility/test.ts | 18 ++++++++++++++++++ .../feedback/src/modal/components/Dialog.tsx | 13 +++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts b/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts index e117ba5b76ca..2e1c78ee7ae5 100644 --- a/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts +++ b/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts @@ -207,3 +207,21 @@ sentryTest('names each dialog after its own title @firefox', async ({ page }) => }); await expect(page.getByRole('dialog', { name: 'Second form' })).toBeVisible(); }); + +sentryTest('falls back to a non-modal dialog when showModal throws @firefox', async ({ page }) => { + await page.evaluate(() => { + HTMLDialogElement.prototype.showModal = () => { + throw new DOMException('The document is sandboxed', 'InvalidStateError'); + }; + }); + const launcher = page.getByRole('button', { name: 'Report a Bug', exact: true }); + for (let attempt = 0; attempt < 2; attempt++) { + await launcher.focus(); + await page.keyboard.press('Enter'); + await expect(page.getByRole('dialog', { name: 'Report a Bug' })).toBeVisible(); + await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); + await page.keyboard.press('Escape'); + await expect(page.locator('dialog')).not.toBeVisible(); + await expect(launcher).toBeFocused(); + } +}); diff --git a/packages/feedback/src/modal/components/Dialog.tsx b/packages/feedback/src/modal/components/Dialog.tsx index 3400edd08b30..315bac0a50ac 100644 --- a/packages/feedback/src/modal/components/Dialog.tsx +++ b/packages/feedback/src/modal/components/Dialog.tsx @@ -21,16 +21,21 @@ export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode { const [timeoutId, setTimeoutId] = useState(null); const dialogRef = useRef(null); + const isModalRef = useRef(false); useLayoutEffect(() => { const dialog = dialogRef.current; if (open && dialog && !dialog.open) { - if (typeof dialog.showModal === 'function') { + try { dialog.showModal(); - } else { + isModalRef.current = true; + } catch { + // `showModal` is missing in older browsers and throws in iframes sandboxed without `allow-modals`. + isModalRef.current = false; dialog.setAttribute('open', ''); - dialog.querySelector('[autofocus]')?.focus(); } + // WebKit does not always move focus to the `autofocus` control of a modal inside a shadow root. + dialog.querySelector('[autofocus]')?.focus(); } return () => { if (typeof dialog?.close === 'function') { @@ -91,7 +96,7 @@ export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode { props.onFormClose(); }} onKeyDown={event => { - if (event.key === 'Escape' && typeof event.currentTarget.showModal !== 'function') { + if (event.key === 'Escape' && !isModalRef.current) { event.preventDefault(); props.onFormClose(); return; From fd505f1685513f4006c7783a9d71c629e2275e06 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 10:50:37 +0000 Subject: [PATCH 04/13] fix(feedback): Restore focus after the success message, not on submit On a successful submit the dialog closed through close(), which moved focus to the still-hidden launcher while the success message showed, and the later close() could pull focus away from wherever the user had moved it. Hide the dialog without restoring focus on submit, and only restore focus when it has not moved elsewhere. Co-Authored-By: Martin Sonnberger <26038247+msonnb@users.noreply.github.com> --- .../suites/feedback/accessibility/test.ts | 12 +++++++++ packages/feedback/src/modal/integration.tsx | 27 ++++++++++++++----- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts b/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts index 2e1c78ee7ae5..119dd3bb5971 100644 --- a/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts +++ b/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts @@ -225,3 +225,15 @@ sentryTest('falls back to a non-modal dialog when showModal throws @firefox', as await expect(launcher).toBeFocused(); } }); + +sentryTest('does not take focus back when the success message times out @firefox', async ({ page }) => { + await page.getByRole('button', { name: 'Report a Bug', exact: true }).click(); + await page.getByRole('textbox', { name: 'Description' }).fill('Feedback sent to the local test transport'); + await page.getByRole('button', { name: 'Send Bug Report' }).click(); + await expect(page.locator('.success__content')).toBeVisible(); + const background = page.locator('#background'); + await background.focus(); + await expect(page.locator('.success__content')).not.toBeVisible({ timeout: 10_000 }); + await expect(page.getByRole('button', { name: 'Report a Bug', exact: true })).toBeVisible(); + await expect(background).toBeFocused(); +}); diff --git a/packages/feedback/src/modal/integration.tsx b/packages/feedback/src/modal/integration.tsx index d2a853825ba6..3b4ace571388 100644 --- a/packages/feedback/src/modal/integration.tsx +++ b/packages/feedback/src/modal/integration.tsx @@ -43,11 +43,27 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => { const target = previousFocus; // The launcher is shown by the close/submitted callback after the dialog closes. void Promise.resolve().then(() => { - if (!isOpen && target === previousFocus && target instanceof HTMLElement && target.isConnected) { + const active = DOCUMENT.activeElement; + const focusMovedElsewhere = + !!active && active !== DOCUMENT.body && active !== shadowRoot.host && active !== target; + if ( + !isOpen && + !focusMovedElsewhere && + target === previousFocus && + target instanceof HTMLElement && + target.isConnected + ) { target.focus(); } }); }; + const hide = (): void => { + if (isOpen) { + isOpen = false; + DOCUMENT.body.style.overflow = originalOverflow; + } + renderContent(false); + }; const dialog: ReturnType = { get el() { return el; @@ -80,11 +96,7 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => { DOCUMENT.body.style.overflow = 'hidden'; }, close() { - if (isOpen) { - isOpen = false; - DOCUMENT.body.style.overflow = originalOverflow; - } - renderContent(false); + hide(); restoreFocus(); }, }; @@ -107,7 +119,8 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => { }} onSubmit={sendFeedback} onSubmitSuccess={(data: FeedbackFormData, eventId: string) => { - dialog.close(); + // Focus is restored once the success message goes away and `onFormSubmitted` closes the dialog. + hide(); options.onSubmitSuccess?.(data, eventId); }} onSubmitError={(error: Error) => { From a05f740e9bc9382d9f8285d0061004a2fb808875 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:08:45 +0000 Subject: [PATCH 05/13] ref(feedback): Drop redundant dialog role --- packages/feedback/src/modal/components/Dialog.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/feedback/src/modal/components/Dialog.tsx b/packages/feedback/src/modal/components/Dialog.tsx index 315bac0a50ac..621f8afcbbbe 100644 --- a/packages/feedback/src/modal/components/Dialog.tsx +++ b/packages/feedback/src/modal/components/Dialog.tsx @@ -88,7 +88,6 @@ export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode { { From 9e95c2403c83e242658be08daa19f3ed03c56be4 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:08:52 +0000 Subject: [PATCH 06/13] fix(feedback): Close the dialog once on backdrop click and Escape The dialog element called the modal integration's onFormClose, which closes the dialog and then calls the core wrapper that closes it again. Call options.onFormClose directly, as before this change. --- packages/feedback/src/modal/components/Dialog.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/feedback/src/modal/components/Dialog.tsx b/packages/feedback/src/modal/components/Dialog.tsx index 621f8afcbbbe..54b55907c3d3 100644 --- a/packages/feedback/src/modal/components/Dialog.tsx +++ b/packages/feedback/src/modal/components/Dialog.tsx @@ -89,15 +89,15 @@ export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode { class="dialog" ref={dialogRef} aria-labelledby={props.titleId} - onClick={props.onFormClose} + onClick={options.onFormClose} onCancel={event => { event.preventDefault(); - props.onFormClose(); + options.onFormClose?.(); }} onKeyDown={event => { if (event.key === 'Escape' && !isModalRef.current) { event.preventDefault(); - props.onFormClose(); + options.onFormClose?.(); return; } if (event.key !== 'Tab') { From 9416f57d419f600ca084a134ef53c92007ebf08d Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:24:45 +0000 Subject: [PATCH 07/13] test(feedback): Split looped accessibility tests into separate cases --- .../suites/feedback/accessibility/test.ts | 98 ++++++++++--------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts b/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts index 119dd3bb5971..904fe10e09d6 100644 --- a/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts +++ b/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts @@ -8,32 +8,37 @@ sentryTest.beforeEach(async ({ getLocalTestUrl, page }) => { await page.goto(await getLocalTestUrl({ testDir: __dirname, handleLazyLoadedFeedback: true })); }); -sentryTest('names the native modal and restores focus after repeated keyboard dismissal @firefox', async ({ page }) => { - const launcher = page.getByRole('button', { name: 'Report a Bug', exact: true }); - const dialog = page.locator('dialog'); +const keyboardDismissals = [ + { description: 'Escape in a field', role: 'textbox', name: 'Name', key: 'Escape' }, + { description: 'Enter on Cancel', role: 'button', name: 'Cancel', key: 'Enter' }, +] as const; + +for (const { description, role, name, key } of keyboardDismissals) { + sentryTest(`names the native modal and restores focus after ${description} @firefox`, async ({ page }) => { + const launcher = page.getByRole('button', { name: 'Report a Bug', exact: true }); + const dialog = page.locator('dialog'); + const messageInput = page.getByRole('textbox', { name: 'Description' }); - for (const key of ['Escape', 'Enter', 'Escape']) { await launcher.focus(); await page.keyboard.press('Enter'); await expect(dialog).toBeVisible(); await expect(dialog).toHaveAccessibleName('Report a Bug'); await expect(dialog).toHaveJSProperty('open', true); expect(await dialog.evaluate(el => el.matches(':modal'))).toBe(true); - await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); + await expect(messageInput).toBeFocused(); await page.locator('#background').evaluate(el => (el as HTMLElement).focus()); - await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); + await expect(messageInput).toBeFocused(); - if (key === 'Enter') { - await page.getByRole('button', { name: 'Cancel', exact: true }).focus(); - } else { - await page.getByRole('textbox', { name: 'Name', exact: true }).focus(); - } + await page.getByRole(role, { name, exact: true }).focus(); await page.keyboard.press(key); await expect(dialog).not.toBeVisible(); await expect(launcher).toBeFocused(); - } -}); + + await page.keyboard.press('Enter'); + await expect(messageInput).toBeFocused(); + }); +} sentryTest('keeps keyboard navigation inside the modal @firefox', async ({ page }) => { await page.getByRole('button', { name: 'Report a Bug', exact: true }).click(); @@ -86,9 +91,8 @@ sentryTest('dismisses on backdrop click and restores focus @firefox', async ({ p await expect(launcher).toBeFocused(); }); -sentryTest( - 'programmatic close and removal release modal state and preserve body overflow @firefox', - async ({ page }) => { +for (const method of ['close', 'removeFromDom'] as const) { + sentryTest(`${method}() releases modal state and preserves body overflow @firefox`, async ({ page }) => { const launcher = page.locator('#background'); await launcher.focus(); const form = await page.evaluateHandle(async () => { @@ -99,24 +103,23 @@ sentryTest( return form; }); - for (const remove of [false, true]) { - await form.evaluate(form => { - form.open(); - form.open(); - }); - await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); - await form.evaluate((form, remove) => (remove ? form.removeFromDom() : form.close()), remove); - await expect(page.locator('dialog:modal')).toHaveCount(0); - await expect(launcher).toBeFocused(); - expect(await page.evaluate(() => document.body.style.overflow)).toBe('scroll'); - } + await form.evaluate(form => { + form.open(); + form.open(); + }); + await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); + await form.evaluate((form, method) => form[method](), method); + await expect(page.locator('dialog:modal')).toHaveCount(0); + await expect(launcher).toBeFocused(); + expect(await page.evaluate(() => document.body.style.overflow)).toBe('scroll'); + await form.evaluate(form => { form.appendToDom(); form.open(); }); await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); - }, -); + }); +} sentryTest('restores the launcher after successful submission @firefox', async ({ page }) => { const launcher = page.getByRole('button', { name: 'Report a Bug', exact: true }); @@ -141,13 +144,13 @@ sentryTest('preserves input border overrides @firefox', async ({ page }) => { await expect(page.locator('[name="name"]')).toHaveCSS('border-top-width', '2px'); }); -sentryTest('keeps the form usable without native dialog methods @firefox', async ({ page }) => { - await page.evaluate(() => { - Object.defineProperty(HTMLDialogElement.prototype, 'showModal', { value: undefined }); - Object.defineProperty(HTMLDialogElement.prototype, 'close', { value: undefined }); - }); - const launcher = page.getByRole('button', { name: 'Report a Bug', exact: true }); - for (const key of ['Escape', 'Enter']) { +for (const key of ['Escape', 'Enter'] as const) { + sentryTest(`keeps the form usable without native dialog methods, closing with ${key} @firefox`, async ({ page }) => { + await page.evaluate(() => { + Object.defineProperty(HTMLDialogElement.prototype, 'showModal', { value: undefined }); + Object.defineProperty(HTMLDialogElement.prototype, 'close', { value: undefined }); + }); + const launcher = page.getByRole('button', { name: 'Report a Bug', exact: true }); await launcher.focus(); await page.keyboard.press('Enter'); await expect(page.getByRole('dialog', { name: 'Report a Bug' })).toBeVisible(); @@ -159,8 +162,8 @@ sentryTest('keeps the form usable without native dialog methods @firefox', async await page.keyboard.press(key); await expect(page.locator('dialog')).not.toBeVisible(); await expect(launcher).toBeFocused(); - } -}); + }); +} for (const scheme of ['light', 'dark'] as const) { sentryTest(`enabled input boundaries have 3:1 contrast in ${scheme} mode @firefox`, async ({ page }) => { @@ -215,15 +218,16 @@ sentryTest('falls back to a non-modal dialog when showModal throws @firefox', as }; }); const launcher = page.getByRole('button', { name: 'Report a Bug', exact: true }); - for (let attempt = 0; attempt < 2; attempt++) { - await launcher.focus(); - await page.keyboard.press('Enter'); - await expect(page.getByRole('dialog', { name: 'Report a Bug' })).toBeVisible(); - await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); - await page.keyboard.press('Escape'); - await expect(page.locator('dialog')).not.toBeVisible(); - await expect(launcher).toBeFocused(); - } + await launcher.focus(); + await page.keyboard.press('Enter'); + await expect(page.getByRole('dialog', { name: 'Report a Bug' })).toBeVisible(); + await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); + await page.keyboard.press('Escape'); + await expect(page.locator('dialog')).not.toBeVisible(); + await expect(launcher).toBeFocused(); + + await page.keyboard.press('Enter'); + await expect(page.getByRole('dialog', { name: 'Report a Bug' })).toBeVisible(); }); sentryTest('does not take focus back when the success message times out @firefox', async ({ page }) => { From ecbbd94c6cf69f90e4dcc27ede308b9e6799edfc Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:24:45 +0000 Subject: [PATCH 08/13] ref(feedback): Clarify when focus returns after a successful submit --- packages/feedback/src/modal/integration.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/feedback/src/modal/integration.tsx b/packages/feedback/src/modal/integration.tsx index 3b4ace571388..6d970dfca4b8 100644 --- a/packages/feedback/src/modal/integration.tsx +++ b/packages/feedback/src/modal/integration.tsx @@ -119,7 +119,7 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => { }} onSubmit={sendFeedback} onSubmitSuccess={(data: FeedbackFormData, eventId: string) => { - // Focus is restored once the success message goes away and `onFormSubmitted` closes the dialog. + // A launcher hidden while the form is open gets focus back when `onFormSubmitted` closes the dialog. hide(); options.onSubmitSuccess?.(data, eventId); }} From acc0bef0ce8bd7c8224ff4c758c0430538da76e4 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:33:58 +0000 Subject: [PATCH 09/13] ref(feedback): Drop the manual focus trap showModal() already makes the rest of the page inert, so a manual Tab trap is not needed. --- .../suites/feedback/accessibility/test.ts | 20 ------------------- .../feedback/src/modal/components/Dialog.tsx | 18 ----------------- 2 files changed, 38 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts b/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts index 904fe10e09d6..73a29233aa36 100644 --- a/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts +++ b/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts @@ -40,18 +40,6 @@ for (const { description, role, name, key } of keyboardDismissals) { }); } -sentryTest('keeps keyboard navigation inside the modal @firefox', async ({ page }) => { - await page.getByRole('button', { name: 'Report a Bug', exact: true }).click(); - const cancel = page.getByRole('button', { name: 'Cancel', exact: true }); - await cancel.focus(); - await page.keyboard.press('Tab'); - await expect(page.getByRole('link', { name: 'Powered by Sentry' })).toBeFocused(); - await page.keyboard.press('Shift+Tab'); - await expect(cancel).toBeFocused(); - await page.keyboard.press('Escape'); - await expect(page.locator('dialog')).not.toBeVisible(); -}); - sentryTest('returns to a custom launcher inside another native modal @firefox', async ({ page }) => { await page.evaluate(() => { const { Sentry } = window as unknown as { Sentry: typeof SentrySDK }; @@ -72,11 +60,6 @@ sentryTest('returns to a custom launcher inside another native modal @firefox', await launcher.click(); await expect(page.getByRole('dialog', { name: 'Custom feedback title' })).toBeVisible(); await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); - await page.getByRole('button', { name: 'Cancel', exact: true }).focus(); - await page.keyboard.press('Tab'); - await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); - await page.keyboard.press('Shift+Tab'); - await expect(page.getByRole('button', { name: 'Cancel', exact: true })).toBeFocused(); await page.keyboard.press('Escape'); await expect(launcher).toBeFocused(); expect(await page.locator('#parent-modal').evaluate(el => el.matches(':modal'))).toBe(true); @@ -156,9 +139,6 @@ for (const key of ['Escape', 'Enter'] as const) { await expect(page.getByRole('dialog', { name: 'Report a Bug' })).toBeVisible(); await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); await page.getByRole('button', { name: 'Cancel', exact: true }).focus(); - await page.keyboard.press('Tab'); - await expect(page.getByRole('link', { name: 'Powered by Sentry' })).toBeFocused(); - await page.keyboard.press('Shift+Tab'); await page.keyboard.press(key); await expect(page.locator('dialog')).not.toBeVisible(); await expect(launcher).toBeFocused(); diff --git a/packages/feedback/src/modal/components/Dialog.tsx b/packages/feedback/src/modal/components/Dialog.tsx index 54b55907c3d3..94e5d5d41fe9 100644 --- a/packages/feedback/src/modal/components/Dialog.tsx +++ b/packages/feedback/src/modal/components/Dialog.tsx @@ -98,24 +98,6 @@ export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode { if (event.key === 'Escape' && !isModalRef.current) { event.preventDefault(); options.onFormClose?.(); - return; - } - if (event.key !== 'Tab') { - return; - } - const controls = Array.from( - event.currentTarget.querySelectorAll('a[href], button, input, textarea, select, [tabindex]'), - ).filter( - control => control.tabIndex >= 0 && !control.matches(':disabled') && control.getClientRects().length > 0, - ); - const first = controls[0]; - const last = controls[controls.length - 1]; - if (event.shiftKey && event.target === first) { - event.preventDefault(); - last?.focus(); - } else if (!event.shiftKey && event.target === last) { - event.preventDefault(); - first?.focus(); } }} > From 10aeec80a2bc8d47eff2bf79adfdcdf19fa2852e Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:47:12 +0000 Subject: [PATCH 10/13] ref(feedback): Name the dialog with aria-label Gives the same accessible name without a generated title id. Co-Authored-By: Martin Sonnberger <26038247+msonnb@users.noreply.github.com> --- packages/feedback/src/modal/components/Dialog.tsx | 4 ++-- packages/feedback/src/modal/components/DialogHeader.tsx | 7 ++----- packages/feedback/src/modal/integration.tsx | 5 ----- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/packages/feedback/src/modal/components/Dialog.tsx b/packages/feedback/src/modal/components/Dialog.tsx index 94e5d5d41fe9..4c5876d64af5 100644 --- a/packages/feedback/src/modal/components/Dialog.tsx +++ b/packages/feedback/src/modal/components/Dialog.tsx @@ -88,7 +88,7 @@ export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode { { event.preventDefault(); @@ -109,7 +109,7 @@ export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode { e.stopPropagation(); }} > - + diff --git a/packages/feedback/src/modal/components/DialogHeader.tsx b/packages/feedback/src/modal/components/DialogHeader.tsx index d98f21676a32..8820b91d8a3a 100644 --- a/packages/feedback/src/modal/components/DialogHeader.tsx +++ b/packages/feedback/src/modal/components/DialogHeader.tsx @@ -6,17 +6,14 @@ import { SentryLogo } from './SentryLogo'; export interface Props { options: FeedbackInternalOptions; - titleId: string; } -export function DialogHeader({ options, titleId }: Props): VNode { +export function DialogHeader({ options }: Props): VNode { const logoHtml = useMemo(() => ({ __html: SentryLogo().outerHTML }), []); return (

- - {options.formTitle} - + {options.formTitle} {options.showBranding ? ( { return { name: 'FeedbackModal' as const, @@ -32,8 +30,6 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => { const el = DOCUMENT.createElement('div'); const style = createDialogStyles(options.styleNonce); - // Preact's `useId` restarts for every `render()` root, and all dialogs share one shadow root. - const titleId = `sentry-feedback-title-${++dialogCount}`; let originalOverflow = ''; let isOpen = false; @@ -107,7 +103,6 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => { render( Date: Tue, 17 Nov 2026 13:47:27 +0000 Subject: [PATCH 11/13] ref(feedback): Handle Escape in keydown for both modal and fallback dialogs Cancelling the Escape keydown stops the native cancel event, so the dialog closes once. onCancel stays for other close requests, such as the Android back button. Co-Authored-By: Martin Sonnberger <26038247+msonnb@users.noreply.github.com> --- .../suites/feedback/accessibility/test.ts | 19 +++++++++++++++++++ .../feedback/src/modal/components/Dialog.tsx | 5 +---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts b/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts index 73a29233aa36..539ee0f9a094 100644 --- a/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts +++ b/dev-packages/browser-integration-tests/suites/feedback/accessibility/test.ts @@ -221,3 +221,22 @@ sentryTest('does not take focus back when the success message times out @firefox await expect(page.getByRole('button', { name: 'Report a Bug', exact: true })).toBeVisible(); await expect(background).toBeFocused(); }); + +sentryTest('calls onFormClose once when Escape closes the modal @firefox', async ({ page }) => { + await page.evaluate(async () => { + const { Sentry } = window as unknown as { Sentry: typeof SentrySDK }; + const win = window as unknown as { closeCount: number }; + win.closeCount = 0; + const form = await Sentry.getFeedback()!.createForm({ + onFormClose: () => { + win.closeCount++; + }, + }); + form.appendToDom(); + form.open(); + }); + await expect(page.getByRole('textbox', { name: 'Description' })).toBeFocused(); + await page.keyboard.press('Escape'); + await expect(page.locator('dialog:modal')).toHaveCount(0); + expect(await page.evaluate(() => (window as unknown as { closeCount: number }).closeCount)).toBe(1); +}); diff --git a/packages/feedback/src/modal/components/Dialog.tsx b/packages/feedback/src/modal/components/Dialog.tsx index 4c5876d64af5..1edec67bc374 100644 --- a/packages/feedback/src/modal/components/Dialog.tsx +++ b/packages/feedback/src/modal/components/Dialog.tsx @@ -21,17 +21,14 @@ export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode { const [timeoutId, setTimeoutId] = useState(null); const dialogRef = useRef(null); - const isModalRef = useRef(false); useLayoutEffect(() => { const dialog = dialogRef.current; if (open && dialog && !dialog.open) { try { dialog.showModal(); - isModalRef.current = true; } catch { // `showModal` is missing in older browsers and throws in iframes sandboxed without `allow-modals`. - isModalRef.current = false; dialog.setAttribute('open', ''); } // WebKit does not always move focus to the `autofocus` control of a modal inside a shadow root. @@ -95,7 +92,7 @@ export function Dialog({ open, onFormSubmitted, ...props }: Props): VNode { options.onFormClose?.(); }} onKeyDown={event => { - if (event.key === 'Escape' && !isModalRef.current) { + if (event.key === 'Escape') { event.preventDefault(); options.onFormClose?.(); } From b3868deb800eb557e6cddca551b572e96b594a8b Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:47:36 +0000 Subject: [PATCH 12/13] ref(feedback): Simplify restoreFocus Co-Authored-By: Martin Sonnberger <26038247+msonnb@users.noreply.github.com> --- packages/feedback/src/modal/integration.tsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/feedback/src/modal/integration.tsx b/packages/feedback/src/modal/integration.tsx index 593ad246ab12..381347c1c922 100644 --- a/packages/feedback/src/modal/integration.tsx +++ b/packages/feedback/src/modal/integration.tsx @@ -40,14 +40,10 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => { // The launcher is shown by the close/submitted callback after the dialog closes. void Promise.resolve().then(() => { const active = DOCUMENT.activeElement; - const focusMovedElsewhere = - !!active && active !== DOCUMENT.body && active !== shadowRoot.host && active !== target; if ( !isOpen && - !focusMovedElsewhere && - target === previousFocus && - target instanceof HTMLElement && - target.isConnected + (!active || active === DOCUMENT.body || active === shadowRoot.host) && + target instanceof HTMLElement ) { target.focus(); } From d87aeb9c7e51385f6d1f14f46f301e08ce133795 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 19:09:12 +0000 Subject: [PATCH 13/13] fix(feedback): Clear previous focus after restoring it Calling removeFromDom() on an already-closed form would otherwise move focus back to the old launcher. --- packages/feedback/src/modal/integration.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/feedback/src/modal/integration.tsx b/packages/feedback/src/modal/integration.tsx index 381347c1c922..d9c00e8093b4 100644 --- a/packages/feedback/src/modal/integration.tsx +++ b/packages/feedback/src/modal/integration.tsx @@ -37,6 +37,7 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => { const restoreFocus = (): void => { const target = previousFocus; + previousFocus = null; // The launcher is shown by the close/submitted callback after the dialog closes. void Promise.resolve().then(() => { const active = DOCUMENT.activeElement;