-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Dialog, Menu, Select] Set
pointer-events
on InternalBackdrop
bas…
…ed on `open` state (#1221)
- Loading branch information
Showing
5 changed files
with
50 additions
and
6 deletions.
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 |
---|---|---|
@@ -1,8 +1,52 @@ | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* @ignore - internal component. | ||
*/ | ||
export function InternalBackdrop() { | ||
return <div role="presentation" style={{ position: 'fixed', inset: 0 }} />; | ||
function InternalBackdrop(props: InternalBackdrop.Props) { | ||
const { inert = false } = props; | ||
return ( | ||
<div | ||
role="presentation" | ||
style={{ | ||
position: 'fixed', | ||
inset: 0, | ||
// Allows `:hover` events immediately after `open` changes to `false`, | ||
// preventing a flicker when the cursor rests on the trigger. Flickers occur | ||
// because CSS `:hover` is temporarily blocked during an exit animation, | ||
// and `[data-popup-open]` is removed. | ||
// Keeping the backdrop in the DOM avoids `[data-floating-ui-inert]`, which | ||
// blocks outside clicks from closing the popup. This issue arises when | ||
// conditionally rendering the backdrop on `open` and using exit animations. | ||
// If the popup reopens before the exit animation finishes, the backdrop | ||
// receives this attribute, breaking outside click behavior. | ||
pointerEvents: inert ? 'none' : undefined, | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
namespace InternalBackdrop { | ||
export interface Props { | ||
/** | ||
* Whether the backdrop should be inert (not block pointer events). | ||
* @default false | ||
*/ | ||
inert?: boolean; | ||
} | ||
} | ||
|
||
InternalBackdrop.propTypes /* remove-proptypes */ = { | ||
// ┌────────────────────────────── Warning ──────────────────────────────┐ | ||
// │ These PropTypes are generated from the TypeScript type definitions. │ | ||
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │ | ||
// └─────────────────────────────────────────────────────────────────────┘ | ||
/** | ||
* Whether the backdrop should be inert (not block pointer events). | ||
* @default false | ||
*/ | ||
inert: PropTypes.bool, | ||
} as any; | ||
|
||
export { InternalBackdrop }; |