Skip to content

Commit

Permalink
feat(Sticky): add styleElement prop (#3202)
Browse files Browse the repository at this point in the history
feat(Sticky): add `styleElement` prop
  • Loading branch information
Wattenberger authored and layershifter committed Oct 23, 2018
1 parent 79d5da8 commit 73f7d05
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
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

0 comments on commit 73f7d05

Please sign in to comment.