Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Modal|Popup|Portal): fix usage of eventStack sub/unsub #2099

Merged
merged 4 commits into from
Sep 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/addons/Portal/Portal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export interface PortalProps {
/** Initial value of open. */
defaultOpen?: boolean;

/** Event pool namespace that is used to handle component events. */
eventPool?: string;

/** The node where the portal should mount. */
mountNode?: any;

Expand Down
14 changes: 10 additions & 4 deletions src/addons/Portal/Portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class Portal extends Component {
/** Initial value of open. */
defaultOpen: PropTypes.bool,

/** Event pool namespace that is used to handle component events */
eventPool: PropTypes.string,

/** The node where the portal should mount. */
mountNode: PropTypes.any,

Expand Down Expand Up @@ -125,6 +128,7 @@ class Portal extends Component {
static defaultProps = {
closeOnDocumentClick: true,
closeOnEscape: true,
eventPool: 'default',
openOnTriggerClick: true,
}

Expand Down Expand Up @@ -372,6 +376,7 @@ class Portal extends Component {
debug('mountPortal()')

const {
eventPool,
mountNode = isBrowser ? document.body : null,
prepend,
} = this.props
Expand All @@ -384,15 +389,16 @@ class Portal extends Component {
mountNode.appendChild(this.rootNode)
}

eventStack.sub('click', this.handleDocumentClick, 'Portal')
eventStack.sub('keydown', this.handleEscape, 'Portal')
eventStack.sub('click', this.handleDocumentClick, eventPool)
eventStack.sub('keydown', this.handleEscape, eventPool)
_.invoke(this.props, 'onMount', null, this.props)
}

unmountPortal = () => {
if (!isBrowser || !this.rootNode) return

debug('unmountPortal()')
const { eventPool } = this.props

ReactDOM.unmountComponentAtNode(this.rootNode)
this.rootNode.parentNode.removeChild(this.rootNode)
Expand All @@ -403,8 +409,8 @@ class Portal extends Component {
this.rootNode = null
this.portalNode = null

eventStack.unsub('click', this.handleDocumentClick, 'Portal')
eventStack.unsub('keydown', this.handleEscape, 'Portal')
eventStack.unsub('click', this.handleDocumentClick, eventPool)
eventStack.unsub('keydown', this.handleEscape, eventPool)
_.invoke(this.props, 'onUnmount', null, this.props)
}

Expand Down
3 changes: 3 additions & 0 deletions src/modules/Modal/Modal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export interface ModalProps extends PortalProps {
/** A modal can appear in a dimmer. */
dimmer?: boolean | 'blurring' | 'inverted';

/** Event pool namespace that is used to handle component events */
eventPool?: string;

/** A Modal can be passed header via shorthand. */
header?: SemanticShorthandItem<ModalHeaderProps>;

Expand Down
7 changes: 6 additions & 1 deletion src/modules/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class Modal extends Component {
PropTypes.oneOf(['inverted', 'blurring']),
]),

/** Event pool namespace that is used to handle component events */
eventPool: PropTypes.string,

/** Modal displayed above the content in bold. */
header: customPropTypes.itemShorthand,

Expand Down Expand Up @@ -135,6 +138,7 @@ class Modal extends Component {
dimmer: true,
closeOnDimmerClick: true,
closeOnDocumentClick: false,
eventPool: 'Modal',
}

static autoControlledProps = [
Expand Down Expand Up @@ -315,7 +319,7 @@ class Modal extends Component {

render() {
const { open } = this.state
const { closeOnDimmerClick, closeOnDocumentClick, dimmer } = this.props
const { closeOnDimmerClick, closeOnDocumentClick, dimmer, eventPool } = this.props
const mountNode = this.getMountNode()

// Short circuit when server side rendering
Expand Down Expand Up @@ -353,6 +357,7 @@ class Modal extends Component {
closeOnRootNodeClick={closeOnDimmerClick}
{...portalProps}
className={dimmerClasses}
eventPool={eventPool}
mountNode={mountNode}
open={open}
onClose={this.handleClose}
Expand Down