[Dialog] Expose Dialog context
See original GitHub issueFeature request
Overview
Expose Dialog context so it’s possible to use it in components inside DialogProvider.
Who does this impact? Who is this for?
I want to create a custom Dialog Content component which turns off onPointerDownOutside
behaviour and adds click listener on Overlay which closes Dialog so Dialog isn’t closed when clicking Overlay’s scrollbar (https://github.com/radix-ui/primitives/issues/1280).
Raw example:
export function DialogContent(props) {
const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);
const onPointerDownOutside = useCallback(event => {
event.preventDefault();
}, []);
const onClickOverlay = useCallback(
event => {
// ...implementation
context.onOpenChange(false);
},
[context.onOpenChange],
);
return (
<DialogPortal>
<DialogOverlay onClick={onClickOverlay}>
<BaseDialogContent
{...props}
onPointerDownOutside={onPointerDownOutside}
>
{children}
</BaseDialogContent>
</DialogOverlay>
</DialogPortal>
);
}
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
The Dialog element - HTML: HyperText Markup Language
Indicates that the dialog is active and can be interacted with. When the open attribute is not set, the dialog shouldn't be shown...
Read more >Using electron save dialog in renderer with context isolation
What is the proper way to expose the save/open dialogs to the renderer now? main.js const mainWindow = new BrowserWindow({ width: 800, height: ......
Read more >Displaying dialogs with DialogFragment - Android Developers
Stay organized with collections Save and categorize content based on your preferences. A DialogFragment is a special fragment subclass that is ...
Read more >Use the Office dialog API in Office Add-ins - Microsoft Learn
To open a dialog box, your code, typically a page in a task pane, calls the displayDialogAsync method and passes to it the...
Read more >Dialogs | IntelliJ Platform Plugin SDK
Usage · Override the getPreferredFocusedComponent() method and return the component that should be focused when the dialog is first displayed.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @lesha1201,
I’ll close this issue and we’ll take a look at #1280
@jjenzz From primitive, I expect it to be as much customizable as possible and one of the keys is having access to its internal context. That way it would cover a lot of use-cases (e.g. ability to add lazy-rendering to Dialog.Portal or any other components). It’s impossible to predict many use-cases but from primitive I expect it to be a minimal building block for building more complex components that covers user’s use-cases.
I understand that users still can wrap it in their own context and sync it with the internal context but I think it unnecessary complicates everything.
Dialog already exposes
createDialogScope
which I think is something internal and it’s not documented anywhere. It could be the same foruseDialogContext
.Anyway thank you for the quick replies. I’m going to introduce my own context and wrap in it Dialog for my use-cases. I think it can be closed then.