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

feat(Popup): add positionFixed to support fixed mode in Popper.JS #3760

Merged
merged 6 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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/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'

/** Enables the popper position 'fixed' mode */
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/** Enables the popper position 'fixed' mode */
/** 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),

/** Enables the popper position 'fixed' mode */
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/** Enables the popper position 'fixed' mode */
/** 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