Skip to content

Commit d452b02

Browse files
dpolevodinПолеводин Дмитрий Игоревич (4094029)makhnatkin
authored
fix(toolbar): use helper to adjust z-index for popups (#544)
Co-authored-by: Полеводин Дмитрий Игоревич (4094029) <[email protected]> Co-authored-by: Sergey Makhnatkin <[email protected]>
1 parent fcb4008 commit d452b02

File tree

6 files changed

+36
-1
lines changed

6 files changed

+36
-1
lines changed

src/bundle/ToolbarView.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {useLayoutEffect, useRef} from 'react';
33
import type {QAProps} from '@gravity-ui/uikit';
44
import {useUpdate} from 'react-use';
55

6+
import {LAYOUT} from 'src/common/layout';
7+
68
import type {ClassNameProps} from '../classname';
79
import {i18n} from '../i18n/menubar';
810
import {useSticky} from '../react-utils/useSticky';
@@ -65,6 +67,7 @@ export function ToolbarView<T>({
6567
},
6668
[className],
6769
)}
70+
data-layout={LAYOUT.STICKY_TOOLBAR}
6871
>
6972
<FlexToolbar
7073
data={toolbarConfig}

src/bundle/settings/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import {
1515
type QAProps,
1616
} from '@gravity-ui/uikit';
1717

18+
import {LAYOUT} from 'src/common/layout';
19+
import {getTargetZIndex} from 'src/utils/get-target-z-index';
20+
1821
import {type ClassNameProps, cn} from '../../classname';
1922
import {i18n} from '../../i18n/bundle';
2023
import WysiwygModeIcon from '../../icons/WysiwygMode';
@@ -90,6 +93,7 @@ export const EditorSettings = memo<EditorSettingsProps>(function EditorSettings(
9093
anchorElement={chevronElement}
9194
placement={placement}
9295
onOpenChange={hidePopup}
96+
zIndex={getTargetZIndex(LAYOUT.STICKY_TOOLBAR)}
9397
>
9498
<SettingsContent
9599
{...props}
@@ -174,6 +178,7 @@ const SettingsContent: React.FC<SettingsContentProps> = function SettingsContent
174178
popoverProps={{
175179
placement: mdHelpPlacement,
176180
modal: false,
181+
zIndex: getTargetZIndex(LAYOUT.STICKY_TOOLBAR),
177182
}}
178183
className={bContent('mode-help')}
179184
>

src/bundle/toolbar/ToolbarButtonWithPopupMenu.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import {
1111
type PopupProps,
1212
} from '@gravity-ui/uikit';
1313

14+
import {LAYOUT} from 'src/common/layout';
15+
import {getTargetZIndex} from 'src/utils/get-target-z-index';
16+
1417
import {cn} from '../../classname';
1518
import type {Action} from '../../core';
1619
import {groupBy, isFunction} from '../../lodash';
@@ -127,6 +130,7 @@ export const ToolbarButtonWithPopupMenu: React.FC<ToolbarButtonWithPopupMenuProp
127130
onOpenChange={(open) => {
128131
if (!open) hide();
129132
}}
133+
zIndex={getTargetZIndex(LAYOUT.STICKY_TOOLBAR)}
130134
>
131135
<Menu size="l" qa={qaMenu} data-toolbar-menu-for={textTitle}>
132136
{Object.entries(groups).map(([label, items], key) => {

src/common/layout.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const LAYOUT = {
2+
STICKY_TOOLBAR: 'sticky-toolbar',
3+
};

src/toolbar/ToolbarListButton.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import {Fragment, useEffect, useState} from 'react';
33
import {ChevronDown} from '@gravity-ui/icons';
44
import {HelpMark, Hotkey, Icon, Menu, Popover, Popup} from '@gravity-ui/uikit';
55

6+
import {LAYOUT} from 'src/common/layout';
7+
import {getTargetZIndex} from 'src/utils/get-target-z-index';
8+
69
import {cn} from '../classname';
710
import {i18n} from '../i18n/common';
811
import {isFunction} from '../lodash';
@@ -94,7 +97,12 @@ export function ToolbarListButton<E>({
9497
>
9598
{buttonContent}
9699
</ToolbarButtonView>
97-
<Popup anchorElement={anchorElement} open={popupOpen} onOpenChange={hide}>
100+
<Popup
101+
anchorElement={anchorElement}
102+
open={popupOpen}
103+
onOpenChange={hide}
104+
zIndex={getTargetZIndex(LAYOUT.STICKY_TOOLBAR)}
105+
>
98106
<Menu size="l" className={b('menu')} qa={qaMenu} data-toolbar-menu-for={titleText}>
99107
{data
100108
.map((data) => {

src/utils/get-target-z-index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export function getTargetZIndex(dataLayoutSelector: string, offset = 10) {
2+
const targetLayerElement = document.querySelector(`[data-layout="${dataLayoutSelector}"]`);
3+
4+
if (!targetLayerElement) {
5+
return offset;
6+
}
7+
8+
const computedStyle = window.getComputedStyle(targetLayerElement);
9+
const targetZIndex = parseInt(computedStyle.zIndex, 10);
10+
11+
return Number.isFinite(targetZIndex) ? targetZIndex + offset : offset;
12+
}

0 commit comments

Comments
 (0)