Skip to content

fix(Modal): spread the user's style prop on the Modal #1492

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

Merged
merged 3 commits into from
Mar 25, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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/modules/Modal/Modal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ export interface ModalProps extends PortalProps {

/** A modal can vary in size. */
size?: 'fullscreen' | 'large' | 'small';

/** Custom Modal style. */
style?: Object;
}

interface ModalComponent extends React.ComponentClass<ModalProps> {
Expand Down
7 changes: 5 additions & 2 deletions src/modules/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class Modal extends Component {
/** A modal can vary in size */
size: PropTypes.oneOf(['fullscreen', 'large', 'small']),

/** Custom Modal style. */
style: PropTypes.object,

/**
* NOTE: Any unhandled props that are defined in Portal are passed-through
* to the wrapping Portal.
Expand Down Expand Up @@ -236,6 +239,7 @@ class Modal extends Component {
closeOnDocumentClick,
dimmer,
size,
style,
} = this.props

const mountNode = this.getMountNode()
Expand All @@ -260,9 +264,8 @@ class Modal extends Component {
const ElementType = getElementType(Modal, this.props)

const closeIconName = closeIcon === true ? 'close' : closeIcon

const modalJSX = (
<ElementType {...rest} className={classes} style={{ marginTop }} ref={this.handleRef}>
<ElementType {...rest} className={classes} style={{ marginTop, ...style }} ref={this.handleRef}>
{Icon.create(closeIconName, { onClick: this.handleClose })}
{children}
</ElementType>
Expand Down
10 changes: 10 additions & 0 deletions test/specs/modules/Modal/Modal-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ describe('Modal', () => {
.should.not.equal(null, 'Modal did not render the child component.')
})

it('spreads the user\'s style prop on the Modal', () => {
const style = { marginTop: '1em', top: 0 }

wrapperMount(<Modal open style={style} />)
const element = document.querySelector('.ui.modal')

element.style.should.have.property('marginTop', '1em')
element.style.should.have.property('top', '0px')
})

describe('open', () => {
it('is not open by default', () => {
wrapperMount(<Modal />)
Expand Down