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 3 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 @@ -95,6 +95,9 @@ export interface PortalProps {
/** Controls whether or not the portal should open when mousing over the trigger. */
openOnTriggerMouseEnter?: boolean;

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

/** Controls whether the portal should be prepended to the mountNode instead of appended. */
prepend?: boolean;

Expand Down
15 changes: 11 additions & 4 deletions src/addons/Portal/Portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ class Portal extends Component {
/** Controls whether or not the portal should open when mousing over the trigger. */
openOnTriggerMouseEnter: PropTypes.bool,

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add prop in alphabetical order.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't know about this, done :)


/** Controls whether the portal should be prepended to the mountNode instead of appended. */
prepend: PropTypes.bool,

Expand All @@ -126,6 +129,7 @@ class Portal extends Component {
closeOnDocumentClick: true,
closeOnEscape: true,
openOnTriggerClick: true,
eventPool: 'default',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

}

static autoControlledProps = [
Expand Down Expand Up @@ -374,6 +378,7 @@ class Portal extends Component {
const {
mountNode = isBrowser ? document.body : null,
prepend,
eventPool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

} = this.props

this.rootNode = document.createElement('div')
Expand All @@ -384,8 +389,8 @@ 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)
}

Expand All @@ -394,6 +399,8 @@ class Portal extends Component {

debug('unmountPortal()')

const { eventPool } = this.props
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New line before this declaration is useless.


ReactDOM.unmountComponentAtNode(this.rootNode)
this.rootNode.parentNode.removeChild(this.rootNode)

Expand All @@ -403,8 +410,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 @@ -34,6 +34,9 @@ export interface ModalProps extends PortalProps {
/** Whether or not the Modal should close when the document is clicked. */
closeOnDocumentClick?: boolean;

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

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

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 @@ -58,6 +58,9 @@ class Modal extends Component {
/** Whether or not the Modal should close when the document is clicked. */
closeOnDocumentClick: PropTypes.bool,

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

/** Simple text content for the Modal. */
content: 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 @@ -359,6 +363,7 @@ class Modal extends Component {
onMount={this.handlePortalMount}
onOpen={this.handleOpen}
onUnmount={this.handlePortalUnmount}
eventPool={eventPool}
>
{this.renderContent(rest)}
</Portal>
Expand Down