fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

Need a way to control Dialog Visibility

Open aygarg opened this issue 10 years ago • 9 comments

I am using the react fabric dialog control inside which we load an iframe to render a web page. I am setting isOpen to false as I want the dialog to be invisible. When an event occurs I want the dialog to be visible which will get hidden again when another event occurs.

The issue is that setting isOpen to false does not render the child components. I looked at the code of the control and it looks like we are returning null when isOpen is false.

Can we get some kind of isVisible property or equivalent to be able to accomplish this scenario. We are currently blocked on this issue and looking for a fast resolution.

I know it might seem weird at first on the kind of requirement we have. There is a feature that we support known as the UiLess Addin. Its Hidden all the time but displayed temporarily when a user action is needed inside a dialog. I cannot dynamically move the iframe inside a dialog as mike suggested without causing a re-render. I tried all these things out myself to try and overcome the need to alter the visibility of the dialog but nothing works.

aygarg avatar Aug 11 '16 22:08 aygarg

Wrapping the dialog in a div and hiding that does not work? Or moving it outside of screenspace?

kevicency avatar Aug 11 '16 23:08 kevicency

This really isn't a thing you would want to hack like this. What you're after is a place to run code in the background, and occasionally show a dialog, right? Dialogs by nature are modal, so trying to leave one up permanently is going to cause more issues. You should look at creating a new component instead.

On Thu, Aug 11, 2016 at 4:48 PM, Kevin Mees [email protected] wrote:

Wrapping the dialog in a div and hiding that does not work? Or moving it outside of screenspace?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/OfficeDev/office-ui-fabric-react/issues/127#issuecomment-239326950, or mute the thread https://github.com/notifications/unsubscribe-auth/ATa0jxnjC0EvbrqYG8lbj7nHUkNeICp2ks5qe7TJgaJpZM4JiocU .

cschlechty avatar Aug 12 '16 00:08 cschlechty

Can you just conditionalize rendering?

<div>
  { isDialogOpen && (
  <Dialog ... />
  ) }
</div>

It's better to avoid rendering unnecessary things than to hide all the unnecessary work you're doing.

dzearing avatar Aug 12 '16 00:08 dzearing

@dzearing and @kmees - I already tried doing what you suggested but it causes a re-render of the child component.

Out requirement is to render the child component even when the dialog is hidden. I tried hacking this around by copying the full dialog code and changing the following things in it:

  1. making isOpen just change the visibility of the div and nothing else:
var style = {
            display: "block"
        };
        if (!isOpen) {
            style = {
                display: "none"
            };
        }
  1. In the parent Div I used this inline style defined above:
                <div style={style}>
                    {/*<Layer onLayerMounted={ onLayerMounted }>*/}
                    <Popup
                        className= {dialogClassName}
                        role='dialog'
                        ariaLabelledBy={title ? id + '-title' : ''}
                        ariaDescribedBy={subText ? id + '-subText' : ''}
                        onDismiss={onDismiss}
                        >...</Popup>
                    {/*</Layer>*/}
                </div>
  1. I commented out Layer for now since I didn't need it. Not sure what needs to be done with it.
  2. When using this component I provided isBlocking value to be the same as isOpen value which took care about not interfering in clicks when dialog is hidden

This worked out smoothly and I did not see any more issues being introduced by this as mentioned by @cschlechty . I think providing a isHidden property isn't that bad an idea. You can make isOpen behave in the same way as today to not break existing implementations and introduce an optional isHidden parameter which can be used for scenarios like this.

aygarg avatar Aug 16 '16 00:08 aygarg

@dzearing @kmees @cschlechty Ping! We really need this to work as we plan to ship in few weeks. Please look into this on an urgent basis.

aygarg avatar Sep 08 '16 18:09 aygarg

@aygarg If you have urgent changes, we accept PRs if they're reasonable.

dzearing avatar Oct 24 '16 18:10 dzearing

@dzearing We were able to work around this by using the className property added in later builds. We provide a display:none value to className to keep the dialog hidden and setting the rest of the properties the right way makes it work smoothly for us today.

I can close this issue if you want, had left it open originally in case you want to consider providing a more explicit way to achieve this.

aygarg avatar Oct 24 '16 19:10 aygarg

I will leave it opened. Thanks!

dzearing avatar Oct 24 '16 19:10 dzearing

We have an isOpen flag now (which should be renamed to hidden, as the default value should be true.)

dzearing avatar Nov 18 '16 01:11 dzearing