Skip to content

Commit

Permalink
feat(Popup): add positionFixed to support fixed mode in Popper.JS (
Browse files Browse the repository at this point in the history
…#3760)

* feat(Popup): add positionFixed to support popper fixed mode (#3718)

Add support for popper.js to position the popup correctly if used with a mountNode inside a `position: fixed` container

* feat(Popup): add `positionFixed` to support fixed mode in `Popper.JS`

Simplify code

* Update Popup-test.js

* Update Popup.d.ts

* Update Popup.js
  • Loading branch information
fxOne authored and layershifter committed Aug 29, 2019
1 parent 6e5234e commit 81d3cd1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/modules/Popup/Popup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ export interface StrictPopupProps extends StrictPortalProps {
| 'top center'
| 'bottom center'

/** Tells `Popper.js` to use the `position: fixed` strategy to position the popover. */
positionFixed?: boolean

/** An object containing custom settings for the Popper.js modifiers. */
popperModifiers?: object

Expand Down
5 changes: 5 additions & 0 deletions src/modules/Popup/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ export default class Popup extends Component {
/** Position for the popover. */
position: PropTypes.oneOf(positions),

/** Tells `Popper.js` to use the `position: fixed` strategy to position the popover. */
positionFixed: PropTypes.bool,

/** An object containing custom settings for the Popper.js modifiers. */
popperModifiers: PropTypes.object,

Expand Down Expand Up @@ -333,6 +336,7 @@ export default class Popup extends Component {
pinned,
popperModifiers,
position,
positionFixed,
trigger,
} = this.props
const { closed, portalRestProps } = this.state
Expand Down Expand Up @@ -369,6 +373,7 @@ export default class Popup extends Component {
eventsEnabled={eventsEnabled}
modifiers={modifiers}
placement={positionsMapping[position]}
positionFixed={positionFixed}
referenceElement={referenceElement}
>
{this.renderContent}
Expand Down
16 changes: 15 additions & 1 deletion test/specs/modules/Popup/Popup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react'
import Portal from 'src/addons/Portal/Portal'
import { SUI } from 'src/lib'
import Popup from 'src/modules/Popup/Popup'
import { positionsMapping } from 'src/modules/Popup/lib/positions.js'
import { positionsMapping } from 'src/modules/Popup/lib/positions'
import PopupHeader from 'src/modules/Popup/PopupHeader'
import PopupContent from 'src/modules/Popup/PopupContent'
import * as common from 'test/specs/commonTests'
Expand Down Expand Up @@ -289,6 +289,20 @@ describe('Popup', () => {
})
})

describe('positionFixed', () => {
it(`is not defiend by default`, () => {
wrapperMount(<Popup open />)

wrapper.should.not.have.prop('positionFixed')
wrapper.find('Popper').should.not.have.prop('positionFixed')
})

it(`can be set to "true"`, () => {
wrapperMount(<Popup positionFixed open />)
wrapper.find('Popper').should.have.prop('positionFixed', true)
})
})

describe('popperModifiers', () => {
it('are passed to Popper', () => {
const modifiers = {
Expand Down

0 comments on commit 81d3cd1

Please sign in to comment.