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.

Nested Dialogs don't display correctly

See original GitHub issue

Description

If you have a Dialog component with a DatePicker field inside, then when you open the DatePicker, it is displayed behind the Dialog.

If you look at the DOM, you’ll see, that when Dialog is opened, new Span element is added as a first child of Body. When DatePicker dialog is opened, then the new Span element, which contains picker’s UI is again added as a first child of Body. If I reorder these Span elements in Chrome DevTools, then DatePicker is displayed correctly.

Images/Screenshots

screenshot 2017-01-25 18 52 53

Link to a gist or code sample where the issue can be reproduced

App class:

import React, { PureComponent } from 'react';
import Dialog from 'react-md/lib/Dialogs';
import Button from 'react-md/lib/Buttons/Button';
import DatePicker from 'react-md/lib/Pickers/DatePickerContainer';

export default class App extends PureComponent {
  constructor(props) {
    super(props);
    this.state = { visible: false };
  }

  openDialog = () => {
    this.setState({ visible: true });
  };

  closeDialog = () => {
    this.setState({ visible: false });
  };

  render() {
    const { visible } = this.state;
    return (
      <div>
        <Button raised onClick={this.openDialog} label="Open Modal Dialog" />
        <Dialog
          id="speedBoost"
          visible={visible}
          title="Use Google's location service?"
          onHide={this.closeDialog}
          aria-labelledby="speedBoostDescription"
          modal
          actions={[
          {
            onClick: this.closeDialog,
            primary: true,
            label: 'OK',
          }]}
        >
          <DatePicker/>
        </Dialog>
      </div>
    );
  }
}

Version

  • React 15.4.2,
  • React-MD 1.0.1

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
mlaursencommented, Feb 7, 2017

With the latest fix, you will no longer have to do any work yourself. If any component that uses the Portal component appears within the children of the Dialog, it will automatically render as a child in the dialog instead of rendering in the document.body by default.

<Dialog id="full-page" visible={fullPageVisible} onHide={this.hideFullPage}>
  <DatePicker id="birthdate" />
  <TimePicker id="appointment-time" />
  <Drawer id="nested-drawer" { ... } />
  <Snackbar { ... } />
  <Dialog { ... } />
</Dialog>

The date picker, time picker, snackbar, drawer, and dialog should now be rendered inside of the full page dialog.

1reaction
mlaursencommented, Jan 25, 2017

Yeah, this should be fixed in the library. I’ll think about how I want to fix it. It is really a problem with using the Portal component for dialogs – I should either update the Pickers to pass the renderNode and lastChild props correctly to the dialog, or update the z-index for .md-dialog.md-dialog--picker to be higher, or update the Portal component to optionally NOT render as a subtree (eventual feature that should be added).

Read more comments on GitHub >

github_iconTop Results From Across the Web

What are the accessibility issues with nested modal dialogs
There is no accessibility with nested modal dialogs per se. The problem is more often caused by the fact that the UI frameworks,...
Read more >
Some web application modal dialog boxes don't work correctly ...
Fixes an issue that triggers unexpected behavior when you interact with web application modal dialog boxes in Internet Explorer 11.
Read more >
Solved: Re: Script UI dialogs not displaying correctly on
ScriptUI has inner default values that we can use when creating our panels. Try this: var dlg = new Window('dialog', 'Test'); dlg.margins =...
Read more >
Dialog window positioning is not preserved in AutoCAD ...
AutoCAD product: Dialog box and palette positions are not preserved between sessions, or after closing the dialog box.
Read more >
Nested dialogs
Nesting dialogs is a questionable design pattern that is not referenced anywhere in the HTML 5.2 Dialog specification.
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