Skip to content

【关于给styled.div等声明方式生成的组件,赋予class属性时,出现的bug,请详见描述和代码截图】 #32

@panchaoco

Description

@panchaoco

bug描述

当我给styled.div等声明方式生成的组件,赋予class属性时,由插件自动生成的styled-xxxx类名被覆盖了而不是合并,导致样式失效

Reproduce link

No response

To reproduce

const GameHeaderLayout = styled.div`
  display: flex;
  align-items: center;
  gap: 0 4px;
  padding: 12px 0;
  position: relative;
  &.is-line {
    &::after {
      position: absolute;
      content: '';
      left: 0;
      bottom: 0;
      width: 100%;
      height: 1px;
      background-color: ${props => props.theme.border100};
      transform: scaleY(0.5);
    }
  }
  .title {
    color: ${props => props.theme.primary};
    font-family: 'PingFang SC';
    font-size: 14px;
    font-style: normal;
    font-weight: 500;
    line-height: 16px; /* 114.286% */
  }
`

type StatisticsHeaderProps = {
  title: string
  icon: VNode
  isLine?: boolean
}

export const GameHeader: FunctionalComponent<StatisticsHeaderProps> = props => {
  const { isLine = true } = props
  return (
    <GameHeaderLayout
      className={classNames('game-header', {
        'is-line': isLine,
      })}
    >
      {props.icon}
      <div className="title">{props.title}</div>
    </GameHeaderLayout>
  )
}

以上的代码,如果给GameHeaderLayout复制一个class或者className, 会导致样式丢失, 经过排查,发现如下截图描述的问题:

image

Expected behavior

期望当我赋值类名给styled的组件时,类名是应该是合并而不是覆盖重置

Actual behavior

No response

Package version

No response

Framework version

No response

Node version

No response

Browsers version

No response

OS version

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions