Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Commit

Permalink
fix(Popup): render element as body children (#302)
Browse files Browse the repository at this point in the history
* render popup as body children

* changelog
  • Loading branch information
kuzhelov authored Oct 3, 2018
1 parent 6c53400 commit fe60933
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Fixes
- Fix Attachment `styles` prop typing @levithomason ([#299](https://github.com/stardust-ui/react/pull/299))
- Fix generation of `key` for the `Accordion.Content` @mnajdova ([#305](https://github.com/stardust-ui/react/pull/305))
- Ensure `Popup` is rendered as direct child of `body` element in the DOM tree @kuzhelov ([#302](https://github.com/stardust-ui/react/pull/302))

### Features
- Add focus styles for `Menu.Item` component @Bugaa92 ([#286](https://github.com/stardust-ui/react/pull/286))
Expand Down
9 changes: 7 additions & 2 deletions src/components/Popup/Popup.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as React from 'react'
import { createPortal } from 'react-dom'
import * as PropTypes from 'prop-types'
import _ from 'lodash'
import { Popper, PopperChildrenProps } from 'react-popper'

import { childrenExist, AutoControlledComponent, IRenderResultConfig } from '../../lib'
import { childrenExist, AutoControlledComponent, IRenderResultConfig, isBrowser } from '../../lib'
import {
ComponentEventHandler,
ItemShorthand,
Expand Down Expand Up @@ -107,6 +108,8 @@ export default class Popup extends AutoControlledComponent<Extendable<IPopupProp

public static autoControlledProps = ['open']

private static isBrowserContext = isBrowser()

protected actionHandlers: AccessibilityActionHandlers = {
toggle: e =>
_.invoke(this.props, 'onOpenChange', e, { ...this.props, ...{ open: !this.props.open } }),
Expand Down Expand Up @@ -138,7 +141,9 @@ export default class Popup extends AutoControlledComponent<Extendable<IPopupProp
...accessibility.keyHandlers.trigger,
})}
</Ref>
{open && this.renderPopupContent(rtl, accessibility)}
{open &&
Popup.isBrowserContext &&
createPortal(this.renderPopupContent(rtl, accessibility), document.body)}
</>
)
}
Expand Down

0 comments on commit fe60933

Please sign in to comment.