-
Notifications
You must be signed in to change notification settings - Fork 97
feat(modals, tooltips): adds fallbackPlacements support to Tooltip and TooltipModal
#2020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,7 +9,14 @@ import React, { HTMLAttributes, useState, useContext, useEffect, useRef } from ' | |||||||||||||||||||||||||||||||||||||||||||
| import PropTypes from 'prop-types'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { ThemeContext } from 'styled-components'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { CSSTransition } from 'react-transition-group'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { autoPlacement, autoUpdate, offset, platform, useFloating } from '@floating-ui/react-dom'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||
| autoPlacement, | ||||||||||||||||||||||||||||||||||||||||||||
| autoUpdate, | ||||||||||||||||||||||||||||||||||||||||||||
| flip, | ||||||||||||||||||||||||||||||||||||||||||||
| offset, | ||||||||||||||||||||||||||||||||||||||||||||
| platform, | ||||||||||||||||||||||||||||||||||||||||||||
| useFloating | ||||||||||||||||||||||||||||||||||||||||||||
| } from '@floating-ui/react-dom'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { useModal } from '@zendeskgarden/container-modal'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { mergeRefs } from 'react-merge-refs'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { TooltipDialogContext } from '../../utils/useTooltipDialogContext'; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -18,7 +25,7 @@ import { | |||||||||||||||||||||||||||||||||||||||||||
| StyledTooltipDialog, | ||||||||||||||||||||||||||||||||||||||||||||
| StyledTooltipDialogBackdrop | ||||||||||||||||||||||||||||||||||||||||||||
| } from '../../styled'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { ITooltipDialogProps } from '../../types'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { ITooltipDialogProps, PLACEMENT } from '../../types'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { Title } from './Title'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { Body } from './Body'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { Close } from './Close'; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -35,6 +42,7 @@ const TooltipDialogComponent = React.forwardRef<HTMLDivElement, ITooltipDialogPr | |||||||||||||||||||||||||||||||||||||||||||
| appendToNode, | ||||||||||||||||||||||||||||||||||||||||||||
| referenceElement, | ||||||||||||||||||||||||||||||||||||||||||||
| placement: _placement, | ||||||||||||||||||||||||||||||||||||||||||||
| fallbackPlacements: _fallbackPlacements, | ||||||||||||||||||||||||||||||||||||||||||||
| offset: _offset, | ||||||||||||||||||||||||||||||||||||||||||||
| onClose, | ||||||||||||||||||||||||||||||||||||||||||||
| hasArrow, | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -64,9 +72,10 @@ const TooltipDialogComponent = React.forwardRef<HTMLDivElement, ITooltipDialogPr | |||||||||||||||||||||||||||||||||||||||||||
| restoreFocus: false | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| const [floatingPlacement] = getFloatingPlacements( | ||||||||||||||||||||||||||||||||||||||||||||
| const [floatingPlacement, fallbackPlacements] = getFloatingPlacements( | ||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if react-components/packages/theming/src/utils/getFloatingPlacements.ts Lines 57 to 77 in 0101f3c
Should we set a sensible default (e.g.:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't due to the fact that |
||||||||||||||||||||||||||||||||||||||||||||
| theme, | ||||||||||||||||||||||||||||||||||||||||||||
| _placement === 'auto' ? PLACEMENT_DEFAULT : _placement! | ||||||||||||||||||||||||||||||||||||||||||||
| _placement === 'auto' ? PLACEMENT_DEFAULT : _placement!, | ||||||||||||||||||||||||||||||||||||||||||||
| _fallbackPlacements | ||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| const { | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -83,7 +92,7 @@ const TooltipDialogComponent = React.forwardRef<HTMLDivElement, ITooltipDialogPr | |||||||||||||||||||||||||||||||||||||||||||
| placement: floatingPlacement, | ||||||||||||||||||||||||||||||||||||||||||||
| middleware: [ | ||||||||||||||||||||||||||||||||||||||||||||
| offset(_offset === undefined ? theme.space.base * 3 : _offset), | ||||||||||||||||||||||||||||||||||||||||||||
| _placement === 'auto' ? autoPlacement() : undefined | ||||||||||||||||||||||||||||||||||||||||||||
| _placement === 'auto' ? autoPlacement() : flip({ fallbackPlacements }) | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -194,6 +203,10 @@ TooltipDialogComponent.propTypes = { | |||||||||||||||||||||||||||||||||||||||||||
| appendToNode: PropTypes.any, | ||||||||||||||||||||||||||||||||||||||||||||
| referenceElement: PropTypes.any, | ||||||||||||||||||||||||||||||||||||||||||||
| placement: PropTypes.any, | ||||||||||||||||||||||||||||||||||||||||||||
| // @ts-expect-error Validation error due to incorrect type inference when component is wrapped in forwardRef | ||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably why George went with |
||||||||||||||||||||||||||||||||||||||||||||
| fallbackPlacements: PropTypes.arrayOf( | ||||||||||||||||||||||||||||||||||||||||||||
| PropTypes.oneOf(PLACEMENT.filter(placement => placement !== 'auto')) | ||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||
| isAnimated: PropTypes.bool, | ||||||||||||||||||||||||||||||||||||||||||||
| hasArrow: PropTypes.bool, | ||||||||||||||||||||||||||||||||||||||||||||
| zIndex: PropTypes.number, | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Offset story content to allow for overlay flip.