-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Try obviating Popover pointer event trap #59449
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
513eeec
Partially revert "ColorPicker: improve UX of dragging the handle when…
stokesman 4d4b915
Use pointer capture to improve drag gesture UX
stokesman 067dc50
Use the context system again
stokesman 9f94226
Update snapshot
stokesman 78d23f0
Remove unnecessary context provider
stokesman 21acd77
Add changelog entry
stokesman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,11 +53,7 @@ import { | |
placementToMotionAnimationProps, | ||
getReferenceElement, | ||
} from './utils'; | ||
import { | ||
contextConnect, | ||
useContextSystem, | ||
ContextSystemProvider, | ||
} from '../context'; | ||
import { contextConnect, useContextSystem } from '../context'; | ||
import type { WordPressComponentProps } from '../context'; | ||
import type { | ||
PopoverProps, | ||
|
@@ -113,7 +109,7 @@ const getPopoverFallbackContainer = () => { | |
return container; | ||
}; | ||
|
||
const UnconnectedPopover = ( | ||
const UnforwardedPopover = ( | ||
props: Omit< | ||
WordPressComponentProps< PopoverProps, 'div', false >, | ||
// To avoid overlaps between the standard HTML attributes and the props | ||
|
@@ -390,100 +386,63 @@ const UnconnectedPopover = ( | |
const isPositioned = | ||
( ! shouldAnimate || animationFinished ) && x !== null && y !== null; | ||
|
||
// In case a `ColorPicker` component is rendered as a child of `Popover`, | ||
// the `Popover` component can be notified of when the user is dragging | ||
// parts of the `ColorPicker` UI (this is possible because the `ColorPicker` | ||
// component exposes the `onPickerDragStart` and `onPickerDragEnd` props | ||
// via internal context). | ||
// While the user is performing a pointer drag, the `Popover` will render | ||
// a transparent backdrop element that will serve as a "pointer events trap", | ||
// making sure that no pointer events reach any potential `iframe` element | ||
// underneath (like, for example, the editor canvas in the WordPress editor). | ||
const [ showBackdrop, setShowBackdrop ] = useState( false ); | ||
const contextValue = useMemo( | ||
() => ( { | ||
ColorPicker: { | ||
onPickerDragStart() { | ||
setShowBackdrop( true ); | ||
}, | ||
onPickerDragEnd() { | ||
setShowBackdrop( false ); | ||
}, | ||
}, | ||
} ), | ||
[] | ||
); | ||
|
||
let content = ( | ||
<> | ||
{ showBackdrop && ( | ||
<div | ||
className="components-popover-pointer-events-trap" | ||
aria-hidden="true" | ||
onClick={ () => setShowBackdrop( false ) } | ||
/> | ||
<motion.div | ||
className={ classnames( className, { | ||
'is-expanded': isExpanded, | ||
'is-positioned': isPositioned, | ||
// Use the 'alternate' classname for 'toolbar' variant for back compat. | ||
[ `is-${ | ||
computedVariant === 'toolbar' | ||
? 'alternate' | ||
: computedVariant | ||
}` ]: computedVariant, | ||
} ) } | ||
{ ...animationProps } | ||
{ ...contentProps } | ||
ref={ mergedFloatingRef } | ||
{ ...dialogProps } | ||
tabIndex={ -1 } | ||
> | ||
{ /* Prevents scroll on the document */ } | ||
{ isExpanded && <ScrollLock /> } | ||
{ isExpanded && ( | ||
<div className="components-popover__header"> | ||
<span className="components-popover__header-title"> | ||
{ headerTitle } | ||
</span> | ||
<Button | ||
className="components-popover__close" | ||
icon={ close } | ||
onClick={ onClose } | ||
/> | ||
</div> | ||
) } | ||
<motion.div | ||
className={ classnames( 'components-popover', className, { | ||
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. Good catch 🙏 |
||
'is-expanded': isExpanded, | ||
'is-positioned': isPositioned, | ||
// Use the 'alternate' classname for 'toolbar' variant for back compat. | ||
[ `is-${ | ||
computedVariant === 'toolbar' | ||
? 'alternate' | ||
: computedVariant | ||
}` ]: computedVariant, | ||
} ) } | ||
{ ...animationProps } | ||
{ ...contentProps } | ||
ref={ mergedFloatingRef } | ||
{ ...dialogProps } | ||
tabIndex={ -1 } | ||
> | ||
{ /* Prevents scroll on the document */ } | ||
{ isExpanded && <ScrollLock /> } | ||
{ isExpanded && ( | ||
<div className="components-popover__header"> | ||
<span className="components-popover__header-title"> | ||
{ headerTitle } | ||
</span> | ||
<Button | ||
className="components-popover__close" | ||
icon={ close } | ||
onClick={ onClose } | ||
/> | ||
</div> | ||
) } | ||
<div className="components-popover__content"> | ||
<ContextSystemProvider value={ contextValue }> | ||
{ children } | ||
</ContextSystemProvider> | ||
<div className="components-popover__content">{ children }</div> | ||
{ hasArrow && ( | ||
<div | ||
ref={ arrowCallbackRef } | ||
className={ [ | ||
'components-popover__arrow', | ||
`is-${ computedPlacement.split( '-' )[ 0 ] }`, | ||
].join( ' ' ) } | ||
style={ { | ||
left: | ||
typeof arrowData?.x !== 'undefined' && | ||
Number.isFinite( arrowData.x ) | ||
? `${ arrowData.x }px` | ||
: '', | ||
top: | ||
typeof arrowData?.y !== 'undefined' && | ||
Number.isFinite( arrowData.y ) | ||
? `${ arrowData.y }px` | ||
: '', | ||
} } | ||
> | ||
<ArrowTriangle /> | ||
</div> | ||
{ hasArrow && ( | ||
<div | ||
ref={ arrowCallbackRef } | ||
className={ [ | ||
'components-popover__arrow', | ||
`is-${ computedPlacement.split( '-' )[ 0 ] }`, | ||
].join( ' ' ) } | ||
style={ { | ||
left: | ||
typeof arrowData?.x !== 'undefined' && | ||
Number.isFinite( arrowData.x ) | ||
? `${ arrowData.x }px` | ||
: '', | ||
top: | ||
typeof arrowData?.y !== 'undefined' && | ||
Number.isFinite( arrowData.y ) | ||
? `${ arrowData.y }px` | ||
: '', | ||
} } | ||
> | ||
<ArrowTriangle /> | ||
</div> | ||
) } | ||
</motion.div> | ||
</> | ||
) } | ||
</motion.div> | ||
); | ||
|
||
const shouldRenderWithinSlot = slot.ref && ! inline; | ||
|
@@ -533,7 +492,7 @@ const UnconnectedPopover = ( | |
* ``` | ||
* | ||
*/ | ||
export const Popover = contextConnect( UnconnectedPopover, 'Popover' ); | ||
export const Popover = contextConnect( UnforwardedPopover, 'Popover' ); | ||
|
||
function PopoverSlot( | ||
{ name = SLOT_NAME }: { name?: string }, | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
TIL
setPointerCapture
!