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(Sticky): add styleElement prop #3202

Merged
Merged
Show file tree
Hide file tree
Changes from all 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/Sticky/Sticky.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export interface StrictStickyProps {

/** Context which sticky should attach onscroll events. */
scrollContext?: object

/** Custom style for sticky element. */
styleElement?: object
}

declare const Sticky: React.ComponentClass<StickyProps>
Expand Down
7 changes: 6 additions & 1 deletion src/modules/Sticky/Sticky.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export default class Sticky extends Component {

/** Context which sticky should attach onscroll events. */
scrollContext: PropTypes.object,

/** Custom style for sticky element. */
styleElement: PropTypes.object,
}

static defaultProps = {
Expand Down Expand Up @@ -200,13 +203,15 @@ export default class Sticky extends Component {
}

computeStyle() {
const { styleElement } = this.props
const { bottom, bound, sticky, top } = this.state

if (!sticky) return {}
if (!sticky) return styleElement
return {
bottom: bound ? 0 : bottom,
top: bound ? undefined : top,
width: this.triggerRect.width,
...styleElement,
}
}

Expand Down
9 changes: 9 additions & 0 deletions test/specs/modules/Sticky/Sticky-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,15 @@ describe('Sticky', () => {
})
})

describe('styleElement', () => {
it('is passed to macthing element', () => {
wrapperMount(<Sticky styleElement={{ zIndex: 10 }} />)
const element = wrapper.childAt(0).childAt(1)

element.should.have.style('z-index', '10')
})
})

describe('update', () => {
it('is called on scroll', () => {
const instance = mount(<Sticky />).instance()
Expand Down