Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #51 from lsirivong/fix/onClick-handlers
Browse files Browse the repository at this point in the history
Handle onClick prop explicitly
  • Loading branch information
TylerBarnes authored Mar 14, 2019
2 parents 64e65a4 + 4fa8251 commit efb4e70
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
7 changes: 7 additions & 0 deletions example/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ class Index extends Component {
and give us a dark theme when we get there.
</TransitionLink>
<br />
<AniLink
to="/page-2"
onClick={() => console.log('Link clicked')}
>
Go to page 2 normally (with an `onClick`)
</AniLink>
<br />
<DisplayState />
</section>
<TransitionPortal>
Expand Down
7 changes: 7 additions & 0 deletions example/src/pages/page-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ export default class SecondPage extends Component {
👉
</span>
</TransitionLink>
<br />
<TransitionLink
to="/"
onClick={() => console.log('Link clicked')}
>
Go home normally (with an `onClick`)
</TransitionLink>
<DisplayState />
<section
style={{
Expand Down
9 changes: 7 additions & 2 deletions src/components/TransitionLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const TransitionLink = ({
activeStyle,
style,
className,
onClick,
...rest
}) => {
return (
Expand All @@ -22,15 +23,19 @@ const TransitionLink = ({
activeStyle={activeStyle}
style={style}
className={className}
onClick={event =>
onClick={event => {
triggerTransition({
event,
to,
exit,
entry,
...context
})
}

if (typeof onClick === 'function') {
onClick(event)
}
}}
to={to} // use gatsby link so prefetching still happens. this is prevent defaulted in triggertransition
{...rest}
>
Expand Down

0 comments on commit efb4e70

Please sign in to comment.