diff --git a/components/SnackBar/SnackBar.jsx b/components/SnackBar/SnackBar.jsx index 5f3d55070..495a2a535 100644 --- a/components/SnackBar/SnackBar.jsx +++ b/components/SnackBar/SnackBar.jsx @@ -1,9 +1,11 @@ import React from 'react'; +import ReactDOM from 'react-dom'; import styled from 'styled-components'; import PropTypes from 'prop-types'; import Colors from '../Colors'; import Button from '../Button'; import { Row, Col } from '../Grid'; +import uniqId from '../shared/uniqId'; const SnackBarDialog = styled.div` align-items: center; @@ -18,7 +20,6 @@ const SnackBarDialog = styled.div` const TextContainer = styled.strong` font-weight: normal; - max-width: 344px; padding-right: 8px; `; @@ -61,16 +62,36 @@ const DialogBlock = styled.section` `; class SnackBar extends React.Component { - componentDidMount() {} + constructor(props) { + super(props); + this.snackBarSection = document.createElement('section'); + } + + componentDidMount() { + const { body } = document; + body.appendChild(this.snackBarSection); + } + + componentWillUnmount() { + const { body } = document; + body.removeChild(this.snackBarSection); + } render() { + const _id = uniqId('snack-bar-dialog-'); const { text, onClose, closeButtonAriaLabel, ...rest } = this.props; - return ( + + return ReactDOM.createPortal( - - {text} + + {text} action {onClose && ( @@ -83,7 +104,8 @@ class SnackBar extends React.Component { - + , + this.snackBarSection, ); } }