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

compose component not support "as" prop #979

Open
someok opened this issue Mar 8, 2022 · 2 comments
Open

compose component not support "as" prop #979

someok opened this issue Mar 8, 2022 · 2 comments

Comments

@someok
Copy link

someok commented Mar 8, 2022

Bug report

Describe the bug

It is normal for the original component to use "as" prop, However, after the compose the component and use "as", the original attributes are lost.

To Reproduce

image

const MyButton = styled(Button, {
    background: 'red',
});

<MyButton as="a" size="xl">
    hello world
</MyButton>

<Button as="a" rounded size="xl" color="gradient">
    hello world
</Button>

System information

  • OS: macOS
  • Browser Edge
  • Version of Stitches: v1.2.6
  • Version of Node.js: v16.14.0
@lesha1201
Copy link

lesha1201 commented Mar 30, 2022

It happens because it uses a instead of Button as a base component:

image

I think it should check whether DefaultType is a component or host-component (e.g. div, a, etc.). If it's a component then it should ignore as prop and pass it to this component.

@lesha1201
Copy link

lesha1201 commented Mar 30, 2022

From example, Button is probably a wrapper on styled component. Possible temporary workaround can be like this:

function Button(...) {
  //...
  return <StyledButton {...} />
}

Button[Symbol.for('sxs.internal')] = StyledButton[Symbol.for('sxs.internal')] ;

I don't like this but at least it can be as a temporary workaround until it's solved in Stitches.

UPD

This workaround still doesn't solve the problem when Button component has some custom props and you want to use it:

function Button({ customProp, ...rest }) {
  //...
  return <StyledButton {...rest} />
}

Button[Symbol.for('sxs.internal')] = StyledButton[Symbol.for('sxs.internal')] ;

const MyButton = styled(Button, {
    background: 'red',
});

// `customProp` won't work because it's passed to `a` instead of `Button`
<MyButton as="a" customProp="foo">
    hello world
</MyButton>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants