Skip to content

Commit

Permalink
Merge pull request #645 from illacloud/fix/trigger_zIndex
Browse files Browse the repository at this point in the history
fix: trigger's zindex
  • Loading branch information
AruSeito committed Dec 29, 2022
2 parents 6a0cfdc + faaa3b6 commit fd044e1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/modal/src/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const Modal = forwardRef<HTMLDivElement, ModalProps>((props, ref) => {
}, [title, type])

return (
<TriggerProvider renderInBody={false}>
<TriggerProvider renderInBody={false} zIndex={10}>
<AnimatePresence>
{visible && (
<>
Expand Down
1 change: 1 addition & 0 deletions packages/trigger/src/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type TriggerTrigger = "hover" | "click" | "focus" | "contextmenu"

export interface TriggerContext {
renderInBody?: boolean
zIndex?: number
children?: ReactNode
}

Expand Down
4 changes: 3 additions & 1 deletion packages/trigger/src/trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ export const Trigger: FC<TriggerProps> = (props) => {
trigger = "hover",
alignPoint,
renderInBody,
zIndex,
} = props

const tipsContainerRef = useRef<HTMLDivElement>(null)
const [visible, setVisible] = useState<boolean>(false)
const finalVisible = popupVisible === undefined ? visible : popupVisible
const triggerContext = useContext(TriggerProviderContext)
const _renderInBody = renderInBody ?? triggerContext.renderInBody ?? true
const _zIndex = zIndex ?? triggerContext.zIndex ?? 1

useEffect(() => {
if (defaultPopupVisible) {
Expand Down Expand Up @@ -359,7 +361,7 @@ export const Trigger: FC<TriggerProps> = (props) => {
css={[
css`
display: inline-flex;
z-index: 1;
z-index: ${_zIndex};
`,
applyBoxStyle(props),
]}
Expand Down
7 changes: 4 additions & 3 deletions packages/trigger/src/triggerContext.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { TriggerContext } from "./interface"
import { createContext, FC, useEffect } from "react"
import { createContext, FC } from "react"

export const TriggerProviderContext = createContext<TriggerContext>({
renderInBody: true,
zIndex: 1,
} as TriggerContext)

export const TriggerProvider: FC<TriggerContext> = (props) => {
const { renderInBody } = props
const { renderInBody, zIndex } = props

return (
<TriggerProviderContext.Provider value={{ renderInBody }}>
<TriggerProviderContext.Provider value={{ renderInBody, zIndex }}>
{props.children}
</TriggerProviderContext.Provider>
)
Expand Down

0 comments on commit fd044e1

Please sign in to comment.