Skip to content

Commit 81d3cd1

Browse files
fxOnelayershifter
authored andcommitted
feat(Popup): add positionFixed to support fixed mode in Popper.JS (#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
1 parent 6e5234e commit 81d3cd1

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/modules/Popup/Popup.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ export interface StrictPopupProps extends StrictPortalProps {
107107
| 'top center'
108108
| 'bottom center'
109109

110+
/** Tells `Popper.js` to use the `position: fixed` strategy to position the popover. */
111+
positionFixed?: boolean
112+
110113
/** An object containing custom settings for the Popper.js modifiers. */
111114
popperModifiers?: object
112115

src/modules/Popup/Popup.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ export default class Popup extends Component {
127127
/** Position for the popover. */
128128
position: PropTypes.oneOf(positions),
129129

130+
/** Tells `Popper.js` to use the `position: fixed` strategy to position the popover. */
131+
positionFixed: PropTypes.bool,
132+
130133
/** An object containing custom settings for the Popper.js modifiers. */
131134
popperModifiers: PropTypes.object,
132135

@@ -333,6 +336,7 @@ export default class Popup extends Component {
333336
pinned,
334337
popperModifiers,
335338
position,
339+
positionFixed,
336340
trigger,
337341
} = this.props
338342
const { closed, portalRestProps } = this.state
@@ -369,6 +373,7 @@ export default class Popup extends Component {
369373
eventsEnabled={eventsEnabled}
370374
modifiers={modifiers}
371375
placement={positionsMapping[position]}
376+
positionFixed={positionFixed}
372377
referenceElement={referenceElement}
373378
>
374379
{this.renderContent}

test/specs/modules/Popup/Popup-test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from 'react'
44
import Portal from 'src/addons/Portal/Portal'
55
import { SUI } from 'src/lib'
66
import Popup from 'src/modules/Popup/Popup'
7-
import { positionsMapping } from 'src/modules/Popup/lib/positions.js'
7+
import { positionsMapping } from 'src/modules/Popup/lib/positions'
88
import PopupHeader from 'src/modules/Popup/PopupHeader'
99
import PopupContent from 'src/modules/Popup/PopupContent'
1010
import * as common from 'test/specs/commonTests'
@@ -289,6 +289,20 @@ describe('Popup', () => {
289289
})
290290
})
291291

292+
describe('positionFixed', () => {
293+
it(`is not defiend by default`, () => {
294+
wrapperMount(<Popup open />)
295+
296+
wrapper.should.not.have.prop('positionFixed')
297+
wrapper.find('Popper').should.not.have.prop('positionFixed')
298+
})
299+
300+
it(`can be set to "true"`, () => {
301+
wrapperMount(<Popup positionFixed open />)
302+
wrapper.find('Popper').should.have.prop('positionFixed', true)
303+
})
304+
})
305+
292306
describe('popperModifiers', () => {
293307
it('are passed to Popper', () => {
294308
const modifiers = {

0 commit comments

Comments
 (0)