Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Add a transparent backdrop to all dashboard dropdowns (#6769)

Sanne de Vries4037bb1c3581
diff --git a/assets/js/dashboard/components/popover.tsx b/assets/js/dashboard/components/popover.tsx
index c03bafc99e..64a438118d 100644
--- a/assets/js/dashboard/components/popover.tsx
+++ b/assets/js/dashboard/components/popover.tsx
@@ -31,8 +31,19 @@ const panel = {
}
}
+/**
+ * Blocks hover and clicks on the rest of the page while a dropdown is open.
+ * Render it before the trigger, and give the trigger `aboveBackdrop`.
+ */
+const backdrop = {
+ classNames: {
+ transparent: 'fixed inset-0 z-10'
+ }
+}
+
const toggleButton = {
classNames: {
+ aboveBackdrop: 'relative aria-expanded:z-10',
rounded: 'flex items-center rounded-md text-sm h-8',
shadow:
'bg-white dark:bg-gray-750 shadow-sm text-gray-800 dark:text-gray-200 dark:hover:bg-gray-700',
@@ -93,6 +104,7 @@ const items = {
}
export const popover = {
+ backdrop,
toggleButton,
panel,
transition,
diff --git a/assets/js/dashboard/components/tabs.tsx b/assets/js/dashboard/components/tabs.tsx
index ce56ab0219..3bb24f5294 100644
--- a/assets/js/dashboard/components/tabs.tsx
+++ b/assets/js/dashboard/components/tabs.tsx
@@ -93,6 +93,9 @@ export const DropdownTabButton = ({
<Popover className={className}>
{({ close: closeDropdown }) => (
<>
+ <Popover.Overlay
+ className={popover.backdrop.classNames.transparent}
+ />
<BlurMenuButtonOnEscape targetRef={dropdownButtonRef} />
<div
className={classNames('-mb-px pb-4', {
@@ -101,7 +104,10 @@ export const DropdownTabButton = ({
>
<Popover.Button
data-testid="tab-button-with-dropdown"
- className="group/tab relative inline-flex justify-between rounded-xs before:absolute before:inset-[-16px_-6px] before:content-[' ']"
+ className={classNames(
+ popover.toggleButton.classNames.aboveBackdrop,
+ "group/tab inline-flex justify-between rounded-xs before:absolute before:inset-[-16px_-6px] before:content-[' ']"
+ )}
ref={dropdownButtonRef}
>
<TabButtonText active={active}>{children}</TabButtonText>
diff --git a/assets/js/dashboard/extra/exploration/exploration-column.tsx b/assets/js/dashboard/extra/exploration/exploration-column.tsx
index 0a62221d6f..fb8ec9a017 100644
--- a/assets/js/dashboard/extra/exploration/exploration-column.tsx
+++ b/assets/js/dashboard/extra/exploration/exploration-column.tsx
@@ -57,38 +57,47 @@ function DirectionDropdown({
)?.label
return (
- <div ref={containerRef} className="relative shrink-0">
- <button
- data-testid={`exploration-direction-${direction}`}
- onClick={() => setOpen((o) => !o)}
- className="flex items-center gap-0.5 text-xs font-semibold text-gray-900 dark:text-gray-100 hover:text-gray-700 dark:hover:text-gray-200"
- >
- {currentLabel}
- <ChevronUpDownIcon className="size-3.5 shrink-0" />
- </button>
-
+ <>
{open && (
<div
- className={`absolute -left-1 top-full mt-1 z-10 min-w-44 dark:!bg-gray-900 ${popover.panel.classNames.roundedSheet}`}
- >
- {DIRECTION_OPTIONS.map(({ value, label }) => (
- <button
- key={value}
- data-testid={`exploration-direction-${value}`}
- data-selected={direction === value}
- onClick={() => {
- onChange(value)
- setOpen(false)
- }}
- className={`w-full text-left text-sm rounded-md dark:hover:!bg-gray-750 data-[selected=true]:dark:!bg-gray-750 ${popover.items.classNames.navigationLink} ${popover.items.classNames.hoverLink} ${direction === value ? popover.items.classNames.selectedOption : ''}`}
- >
- {label}
- <SelectedCheckmark selected={direction === value} />
- </button>
- ))}
- </div>
+ aria-hidden="true"
+ className={popover.backdrop.classNames.transparent}
+ />
)}
- </div>
+ <div ref={containerRef} className="relative shrink-0">
+ <button
+ data-testid={`exploration-direction-${direction}`}
+ aria-expanded={open}
+ onClick={() => setOpen((o) => !o)}
+ className={`${popover.toggleButton.classNames.aboveBackdrop} flex items-center gap-0.5 text-xs font-semibold text-gray-900 dark:text-gray-100 hover:text-gray-700 dark:hover:text-gray-200`}
+ >
+ {currentLabel}
+ <ChevronUpDownIcon className="size-3.5 shrink-0" />
+ </button>
+
+ {open && (
+ <div
+ className={`absolute -left-1 top-full mt-1 z-10 min-w-44 dark:!bg-gray-900 ${popover.panel.classNames.roundedSheet}`}
+ >
+ {DIRECTION_OPTIONS.map(({ value, label }) => (
+ <button
+ key={value}
+ data-testid={`exploration-direction-${value}`}
+ data-selected={direction === value}
+ onClick={() => {
+ onChange(value)
+ setOpen(false)
+ }}
+ className={`w-full text-left text-sm rounded-md dark:hover:!bg-gray-750 data-[selected=true]:dark:!bg-gray-750 ${popover.items.classNames.navigationLink} ${popover.items.classNames.hoverLink} ${direction === value ? popover.items.classNames.selectedOption : ''}`}
+ >
+ {label}
+ <SelectedCheckmark selected={direction === value} />
+ </button>
+ ))}
+ </div>
+ )}
+ </div>
+ </>
)
}
diff --git a/assets/js/dashboard/nav-menu/dashboard-options-menu.tsx b/assets/js/dashboard/nav-menu/dashboard-options-menu.tsx
index f844fda6f7..4864021294 100644
--- a/assets/js/dashboard/nav-menu/dashboard-options-menu.tsx
+++ b/assets/js/dashboard/nav-menu/dashboard-options-menu.tsx
@@ -82,6 +82,7 @@ function DashboardOptionsMenuItems({
shouldIgnoreWhen={[isModifierPressed, isTyping]}
/>
)}
+ <Popover.Overlay className={popover.backdrop.classNames.transparent} />
<BlurMenuButtonOnEscape targetRef={buttonRef} />
<Popover.Button
ref={buttonRef}
@@ -89,6 +90,7 @@ function DashboardOptionsMenuItems({
className={classNames(
popover.toggleButton.classNames.rounded,
popover.toggleButton.classNames.ghost,
+ popover.toggleButton.classNames.aboveBackdrop,
'justify-center'
)}
>
diff --git a/assets/js/dashboard/nav-menu/filter-menu.tsx b/assets/js/dashboard/nav-menu/filter-menu.tsx
index d8f375db4b..77f7e11c6c 100644
--- a/assets/js/dashboard/nav-menu/filter-menu.tsx
+++ b/assets/js/dashboard/nav-menu/filter-menu.tsx
@@ -42,6 +42,7 @@ const FilterMenuItems = ({
return (
<>
+ <Popover.Overlay className={popover.backdrop.classNames.transparent} />
<BlurMenuButtonOnEscape targetRef={buttonRef} />
{compact ? (
<Tooltip
@@ -54,7 +55,8 @@ const FilterMenuItems = ({
className={classNames(
popover.toggleButton.classNames.rounded,
popover.toggleButton.classNames.ghost,
- 'justify-center relative z-20'
+ popover.toggleButton.classNames.aboveBackdrop,
+ 'justify-center'
)}
>
<PlusIcon className="block size-4" />
@@ -66,7 +68,7 @@ const FilterMenuItems = ({
className={classNames(
popover.toggleButton.classNames.rounded,
popover.toggleButton.classNames.ghost,
- 'relative z-20'
+ popover.toggleButton.classNames.aboveBackdrop
)}
>
<FilterIcon className="block size-3.5" />
@@ -86,12 +88,8 @@ const FilterMenuItems = ({
: 'md:left-auto md:origin-top-right'
)}
>
- <div className="fixed top-0 left-0 w-full h-full"></div>
<Popover.Panel
- className={classNames(
- popover.panel.classNames.roundedSheet,
- 'relative'
- )}
+ className={popover.panel.classNames.roundedSheet}
data-testid="filtermenu"
>
<FilterMenuPanelContent closeDropdown={closeDropdown} />
diff --git a/assets/js/dashboard/nav-menu/filter-pill.tsx b/assets/js/dashboard/nav-menu/filter-pill.tsx
index 0a6a977e06..56bda300ad 100644
--- a/assets/js/dashboard/nav-menu/filter-pill.tsx
+++ b/assets/js/dashboard/nav-menu/filter-pill.tsx
@@ -156,11 +156,16 @@ const PillMenu = ({
<Popover className="flex h-full">
{({ open, close }) => (
<>
- {open && <div className="fixed top-0 left-0 w-full h-full"></div>}
+ <Popover.Overlay
+ className={popover.backdrop.classNames.transparent}
+ />
<BlurMenuButtonOnEscape targetRef={buttonRef} />
<Popover.Button
ref={setButton}
- className={classNames(className, 'relative')}
+ className={classNames(
+ className,
+ popover.toggleButton.classNames.aboveBackdrop
+ )}
aria-label={label}
>
{children}
@@ -232,92 +237,103 @@ export function FilterPill({
const roundedRight = !onRemoveClick && 'rounded-r-md'
return (
- <div
- ref={setContainerElement}
- role="group"
- aria-label={plainText}
- className="flex h-8 shrink-0 items-center rounded-md bg-white border border-gray-200 dark:border-gray-700 dark:bg-gray-800 text-gray-800 dark:text-gray-100 text-sm divide-x divide-gray-200 dark:divide-gray-700"
- >
- <span className={classNames(partClassName, 'rounded-l-md')}>
- {dimensionLabel}
- </span>
- {canChangeOperation ? (
- <button
- ref={setOperatorButton}
- type="button"
- className={buttonPartClassName}
- aria-label={`Change operator: ${plainText}`}
- aria-expanded={openPart === 'operator'}
- onClick={() => toggle('operator')}
- >
- {operation}
- </button>
- ) : (
- <span className={partClassName}>{operation}</span>
+ <>
+ {!!openPart && (
+ <div
+ aria-hidden="true"
+ className={popover.backdrop.classNames.transparent}
+ />
)}
- {action?.type === 'edit' ? (
- <button
- ref={setValuesButton}
- type="button"
- className={classNames(buttonPartClassName, roundedRight)}
- title={plainText}
- aria-label={`Edit filter: ${plainText}`}
- aria-expanded={openPart === 'values'}
- onClick={() => toggle('values')}
- >
- <PillValues values={values} />
- </button>
- ) : action?.type === 'menu' ? (
- <PillMenu
- className={classNames(buttonPartClassName, roundedRight)}
- label={`Open menu: ${plainText}${error ? ` (${error})` : ''}`}
- renderMenu={action.renderMenu}
- >
- <PillValues values={values} error={error} />
- </PillMenu>
- ) : (
- <span
- className={classNames(partClassName, roundedRight)}
- title={plainText}
- >
- <PillValues values={values} />
+ <div
+ ref={setContainerElement}
+ role="group"
+ aria-label={plainText}
+ className={classNames(
+ 'flex h-8 shrink-0 items-center rounded-md bg-white border border-gray-200 dark:border-gray-700 dark:bg-gray-800 text-gray-800 dark:text-gray-100 text-sm divide-x divide-gray-200 dark:divide-gray-700',
+ !!openPart && 'relative z-10'
+ )}
+ >
+ <span className={classNames(partClassName, 'rounded-l-md')}>
+ {dimensionLabel}
</span>
- )}
- {!!onRemoveClick && (
- <button
- type="button"
- title={`Remove filter: ${plainText}`}
- className="w-7.5 flex items-center justify-center h-full rounded-r-md cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-750"
- onClick={onRemoveClick}
- >
- <XMarkIcon className="size-4" />
- </button>
- )}
- {openPart === 'operator' && (
- <FilterPillPopover
- anchorElement={operatorButton}
- containerElement={containerElement}
- onClose={closeEditor}
- className="w-44"
- >
- <FilterOperatorList filter={filter} onSelect={onOperationSelect} />
- </FilterPillPopover>
- )}
- {openPart === 'values' && (
- <FilterPillPopover
- anchorElement={valuesButton}
- containerElement={containerElement}
- onClose={closeEditor}
- className="w-80 max-w-[calc(100vw-1rem)]"
- >
- <FilterValuePicker
- filter={filter}
- labels={labels}
- onChange={editor.update}
- onDone={() => closeEditor({ refocus: true })}
- />
- </FilterPillPopover>
- )}
- </div>
+ {canChangeOperation ? (
+ <button
+ ref={setOperatorButton}
+ type="button"
+ className={buttonPartClassName}
+ aria-label={`Change operator: ${plainText}`}
+ aria-expanded={openPart === 'operator'}
+ onClick={() => toggle('operator')}
+ >
+ {operation}
+ </button>
+ ) : (
+ <span className={partClassName}>{operation}</span>
+ )}
+ {action?.type === 'edit' ? (
+ <button
+ ref={setValuesButton}
+ type="button"
+ className={classNames(buttonPartClassName, roundedRight)}
+ title={plainText}
+ aria-label={`Edit filter: ${plainText}`}
+ aria-expanded={openPart === 'values'}
+ onClick={() => toggle('values')}
+ >
+ <PillValues values={values} />
+ </button>
+ ) : action?.type === 'menu' ? (
+ <PillMenu
+ className={classNames(buttonPartClassName, roundedRight)}
+ label={`Open menu: ${plainText}${error ? ` (${error})` : ''}`}
+ renderMenu={action.renderMenu}
+ >
+ <PillValues values={values} error={error} />
+ </PillMenu>
+ ) : (
+ <span
+ className={classNames(partClassName, roundedRight)}
+ title={plainText}
+ >
+ <PillValues values={values} />
+ </span>
+ )}
+ {!!onRemoveClick && (
+ <button
+ type="button"
+ title={`Remove filter: ${plainText}`}
+ className="w-7.5 flex items-center justify-center h-full rounded-r-md cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-750"
+ onClick={onRemoveClick}
+ >
+ <XMarkIcon className="size-4" />
+ </button>
+ )}
+ {openPart === 'operator' && (
+ <FilterPillPopover
+ anchorElement={operatorButton}
+ containerElement={containerElement}
+ onClose={closeEditor}
+ className="w-44"
+ >
+ <FilterOperatorList filter={filter} onSelect={onOperationSelect} />
+ </FilterPillPopover>
+ )}
+ {openPart === 'values' && (
+ <FilterPillPopover
+ anchorElement={valuesButton}
+ containerElement={containerElement}
+ onClose={closeEditor}
+ className="w-80 max-w-[calc(100vw-1rem)]"
+ >
+ <FilterValuePicker
+ filter={filter}
+ labels={labels}
+ onChange={editor.update}
+ onDone={() => closeEditor({ refocus: true })}
+ />
+ </FilterPillPopover>
+ )}
+ </div>
+ </>
)
}
diff --git a/assets/js/dashboard/nav-menu/query-periods/comparison-period-menu.tsx b/assets/js/dashboard/nav-menu/query-periods/comparison-period-menu.tsx
index 40d5c3f862..bb71334877 100644
--- a/assets/js/dashboard/nav-menu/query-periods/comparison-period-menu.tsx
+++ b/assets/js/dashboard/nav-menu/query-periods/comparison-period-menu.tsx
@@ -137,11 +137,13 @@ export const ComparisonPeriodMenu = ({
return (
<>
+ <Popover.Overlay className={popover.backdrop.classNames.transparent} />
<BlurMenuButtonOnEscape targetRef={buttonRef} />
<Popover.Button
className={classNames(
popover.toggleButton.classNames.rounded,
popover.toggleButton.classNames.ghost,
+ popover.toggleButton.classNames.aboveBackdrop,
'bg-gray-150/80 dark:bg-gray-800'
)}
ref={buttonRef}
@@ -169,6 +171,7 @@ export const ComparisonCalendarMenu = ({
return (
<>
+ <Popover.Overlay className={popover.backdrop.classNames.transparent} />
<BlurMenuButtonOnEscape targetRef={calendarButtonRef} />
<Popover.Button
className={hiddenCalendarButtonClassName}
diff --git a/assets/js/dashboard/nav-menu/query-periods/dashboard-period-menu.tsx b/assets/js/dashboard/nav-menu/query-periods/dashboard-period-menu.tsx
index 5de2fae719..8e876b577c 100644
--- a/assets/js/dashboard/nav-menu/query-periods/dashboard-period-menu.tsx
+++ b/assets/js/dashboard/nav-menu/query-periods/dashboard-period-menu.tsx
@@ -100,6 +100,7 @@ export const DashboardPeriodMenu = ({
return (
<>
+ <Popover.Overlay className={popover.backdrop.classNames.transparent} />
<BlurMenuButtonOnEscape targetRef={buttonRef} />
<div
className={classNames(
@@ -113,6 +114,7 @@ export const DashboardPeriodMenu = ({
<Popover.Button
ref={buttonRef}
className={classNames(
+ popover.toggleButton.classNames.aboveBackdrop,
'flex items-center gap-x-1.5 pl-2.5 text-sm text-gray-800 dark:text-gray-100 leading-tight h-full rounded-md focus-visible:ring-0 focus-visible:ring-offset-0',
periodsWithArrows.includes(dashboardState.period)
? 'pr-1.5'
@@ -242,6 +244,7 @@ export const MainCalendar = ({
return (
<>
+ <Popover.Overlay className={popover.backdrop.classNames.transparent} />
<BlurMenuButtonOnEscape targetRef={calendarButtonRef} />
<Popover.Button
className={hiddenCalendarButtonClassName}
diff --git a/assets/js/dashboard/site-switcher.tsx b/assets/js/dashboard/site-switcher.tsx
index af09d07878..be85352e8a 100644
--- a/assets/js/dashboard/site-switcher.tsx
+++ b/assets/js/dashboard/site-switcher.tsx
@@ -159,12 +159,16 @@ export const SiteSwitcher = () => {
/>
)}
+ <Popover.Overlay
+ className={popover.backdrop.classNames.transparent}
+ />
<BlurMenuButtonOnEscape targetRef={buttonRef} />
<Popover.Button
ref={buttonRef}
className={classNames(
popover.toggleButton.classNames.rounded,
popover.toggleButton.classNames.ghost,
+ popover.toggleButton.classNames.aboveBackdrop,
'!px-1.5 sm:!pl-1.5 sm:!pr-2.5'
)}
title={currentSite.domain}
diff --git a/assets/js/dashboard/stats/pages/index.tsx b/assets/js/dashboard/stats/pages/index.tsx
index 0b3ea1f0f5..06185d6f79 100644
--- a/assets/js/dashboard/stats/pages/index.tsx
+++ b/assets/js/dashboard/stats/pages/index.tsx
@@ -178,11 +178,15 @@ function PagesBreakdownMenu({
<Popover className="relative">
{({ close }) => (
<>
+ <Popover.Overlay
+ className={popover.backdrop.classNames.transparent}
+ />
<BlurMenuButtonOnEscape targetRef={buttonRef} />
<Popover.Button
ref={buttonRef}
className={classNames(
- 'relative flex rounded !text-gray-500 dark:!text-gray-400 hover:!text-gray-600 dark:hover:!text-gray-300 transition-colors duration-150 before:absolute before:inset-[-8px]',
+ popover.toggleButton.classNames.aboveBackdrop,
+ 'flex rounded !text-gray-500 dark:!text-gray-400 hover:!text-gray-600 dark:hover:!text-gray-300 transition-colors duration-150 before:absolute before:inset-[-8px]',
popover.toggleButton.classNames.linkLike,
'justify-center'
)}
diff --git a/e2e/tests/dashboard/behaviours.spec.ts b/e2e/tests/dashboard/behaviours.spec.ts
index 5172bc225f..02a366114e 100644
--- a/e2e/tests/dashboard/behaviours.spec.ts
+++ b/e2e/tests/dashboard/behaviours.spec.ts
@@ -839,6 +839,8 @@ test('props breakdown', async ({ page, request }) => {
})
await test.step('props modal', async () => {
+ await propsTabButton.click()
+ await expectDropdownClosed(report)
await detailsLink(report).click()
await expect(