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

Missing prop forwarding (Link component) #990

Closed
LekoArts opened this issue Jun 8, 2020 · 5 comments
Closed

Missing prop forwarding (Link component) #990

LekoArts opened this issue Jun 8, 2020 · 5 comments
Labels
bug Something isn't working

Comments

@LekoArts
Copy link
Collaborator

LekoArts commented Jun 8, 2020

Describe the bug

A user reported a bug on my repository: LekoArts/gatsby-themes#415

The activeClassName doesn't get passed to the Link element of Theme UI:

https://github.com/LekoArts/gatsby-themes/blob/4b576244c4f00ab1a20c84a63a91ea3f0f777303/themes/gatsby-theme-minimal-blog/src/components/navigation.tsx#L23-L25

I made sure that it's not a bug on Gatsby's side with this codesandbox:
https://codesandbox.io/s/activeclassname-rpus4

So I bisected the behavior and found two deploys of that starter project, one with theme-ui v0.2 and v0.3

v0.2: https://build-2b524a52-2d7f-4d8b-be3f-4608001dc6b9.gtsb.io/blog
v0.3: https://build-8841d060-d85a-47fe-a2a5-199d312f0ebb.gtsb.io/blog

The difference of that change was this PR where I changed Styled.a to Link from Theme UI and updated from 0.2 to 0.3:

https://github.com/LekoArts/gatsby-themes/pull/371/files#diff-2571259472ecb4e0dfebe1380900f4eb

To Reproduce

You can clone https://github.com/LekoArts/gatsby-starter-minimal-blog to see the missing active class on the items in the navigation

Expected behavior

Like in v0.2 version, a active in the className.

Additional context

Related issue: #376

@LekoArts

This comment has been minimized.

@LekoArts LekoArts mentioned this issue Jun 26, 2020
7 tasks
@LekoArts
Copy link
Collaborator Author

LekoArts commented Jun 26, 2020

I’m currently looking into the issue I mentioned here and started with a failing test.

describe('Link', () => {
  test('components with `as` receive all props', () => {
    const Beep = props => <div {...props} />
    const json = renderJSON(<Link as={Beep} activeClassName="active" />)
    expect(json.type).toBe('div')
    expect(json.props.activeClassName).toBe('active')
  })
})

This test fails (as expected). At the moment my conclusion is that the culprit is “shouldForwardProp” in the Box component:
https://github.com/system-ui/theme-ui/blob/master/packages/components/src/Box.js#L18
When I remove that line the test is successful.

So I guess that config https://github.com/system-ui/theme-ui/blob/master/packages/components/src/Box.js#L7-L10 would also need to allow names from reach-router.

However, the PR #823 adds a new way of creating this Box component so getting this in would be the best way to solve this.

@jxnblk
Copy link
Member

jxnblk commented Jun 26, 2020

Also related to #668 -- I think the best path forward is to make some of the changes to the jsx createElement function in #823 and remove the dependencies on styled and shouldForwardProp

@aaronadamsCA
Copy link
Contributor

aaronadamsCA commented Aug 4, 2020

Here's a simple workaround until this is fixed:

/** @jsx jsx */

import { Link as GatsbyLink } from "gatsby";
import { jsx, Link as ThemeUiLink } from "theme-ui";

export default function Link(props) {
  return (
    <ThemeUiLink as={AsLink} variant="default" {...props} __themeKey="links" />
  );
}

function AsLink(props) {
  return <GatsbyLink activeClassName="active" {...props} />;
}

Note that by default this component uses styles in theme.links.default, since (to me) it's weird for a non-Styled component to use MDX styles.

@lachlanjc lachlanjc added the bug Something isn't working label Dec 3, 2020
@lachlanjc
Copy link
Member

There isn’t a simple solution on our end for this, so we encourage using with framework-provided (Gatsby, Next, Reach/React Router, etc) Link components with a solution like the one above (#990 (comment)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants