question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Dialog] Expose Dialog context

See original GitHub issue

Feature 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:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
benoitgrelardcommented, Apr 4, 2022

Hi @lesha1201,

I’ll close this issue and we’ll take a look at #1280

1reaction
lesha1201commented, Mar 30, 2022

@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 for useDialogContext.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found