Skip to content

Commit a3165df

Browse files
Use dynamic z-index for tooltips too (#1883)
* Use Charlies dynamic z-index for tooltips too * Share `usePopoverZIndex`
1 parent 4f706c2 commit a3165df

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

libs/ui/lib/listbox/Listbox.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ import { Listbox as Select } from '@headlessui/react'
1717
import cn from 'classnames'
1818
import type { ReactNode } from 'react'
1919

20-
import { FieldLabel, SelectArrows6Icon, SpinnerLoader, TextInputHint } from '@oxide/ui'
21-
22-
import { useIsInModal } from '../modal/Modal'
23-
import { useIsInSideModal } from '../side-modal/SideModal'
20+
import {
21+
FieldLabel,
22+
SelectArrows6Icon,
23+
SpinnerLoader,
24+
TextInputHint,
25+
usePopoverZIndex,
26+
} from '@oxide/ui'
2427

2528
export type ListboxItem<Value extends string = string> = {
2629
value: Value
@@ -83,13 +86,7 @@ export const Listbox = <Value extends string = string>({
8386
const selectedItem = selected && items.find((i) => i.value === selected)
8487
const noItems = !isLoading && items.length === 0
8588
const isDisabled = disabled || noItems
86-
const isInModal = useIsInModal()
87-
const isInSideModal = useIsInSideModal()
88-
const zIndex = isInModal
89-
? 'z-modalDropdown'
90-
: isInSideModal
91-
? 'z-sideModalDropdown'
92-
: 'z-contentDropdown'
89+
const zIndex = usePopoverZIndex()
9390

9491
return (
9592
<div className={cn('relative', className)}>

libs/ui/lib/side-modal/SideModal.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import cn from 'classnames'
1111
import React, { createContext, useContext, useRef, type ReactNode } from 'react'
1212

1313
import { Close12Icon, Error12Icon } from '@oxide/design-system/icons/react'
14-
import { Message } from '@oxide/ui'
14+
import { Message, useIsInModal } from '@oxide/ui'
1515
import { classed } from '@oxide/util'
1616

1717
import { useIsOverflow } from 'app/hooks'
@@ -22,6 +22,16 @@ const SideModalContext = createContext(false)
2222

2323
export const useIsInSideModal = () => useContext(SideModalContext)
2424

25+
export function usePopoverZIndex() {
26+
const isInModal = useIsInModal()
27+
const isInSideModal = useIsInSideModal()
28+
return isInModal
29+
? 'z-modalDropdown'
30+
: isInSideModal
31+
? 'z-sideModalDropdown'
32+
: 'z-contentDropdown'
33+
}
34+
2535
export type SideModalProps = {
2636
title?: string
2737
subtitle?: ReactNode

libs/ui/lib/tooltip/Tooltip.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import {
3232
} from 'react'
3333
import { mergeRefs } from 'react-merge-refs'
3434

35+
import { usePopoverZIndex } from '@oxide/ui'
36+
3537
import './tooltip.css'
3638

3739
export interface TooltipProps {
@@ -83,14 +85,16 @@ export const Tooltip = forwardRef(
8385
ref: mergeRefs([refs.setReference, elRef]),
8486
})
8587

88+
const zIndex = usePopoverZIndex()
89+
8690
return (
8791
<>
8892
{child}
8993
<FloatingPortal>
9094
{open && (
9195
<div
9296
ref={refs.setFloating}
93-
className={cn('ox-tooltip max-content max-w-sm')}
97+
className={cn('ox-tooltip max-content max-w-sm', zIndex)}
9498
{...getFloatingProps()}
9599
style={floatingStyles}
96100
>

libs/ui/lib/tooltip/tooltip.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
.ox-tooltip {
10-
@apply z-20 rounded border p-2 text-sans-md text-secondary bg-raise border-secondary elevation-2;
10+
@apply rounded border p-2 text-sans-md text-secondary bg-raise border-secondary elevation-2;
1111
}
1212

1313
.ox-tooltip-arrow {

0 commit comments

Comments
 (0)