Skip to content

🐛[BUG] 当StyleProvider挂载在shadowRoot节点时,style样式表挂载位置不对 #195

@lajidemo

Description

@lajidemo

🐛 bug 描述

我在主工程上设置StyleProvider挂载节点为shadowRoot时,通过antd-style开发的二次封装组件样式无法正确的挂载在shadowRoot节点上

📷 复现步骤

  1. 主工程设置StyleProvider的container为shadowRoot
  2. 在独立的组件库工程上通过antd-style开发自定义组件
  3. 组件样式表挂载到了head标签上

🏞 期望结果

组件样式表挂载到shadowRoot节点上

💻 复现代码

// index.tsx
  const shadowRoot = document.getElementById('copilot-root')?.shadowRoot;
  const popupContainer = shadowRoot?.getElementById('copilot-panel');
  return shadowRoot ? (
    <StyleProvider container={shadowRoot}>
      <XProvider
        locale={zhCN}
        // @ts-ignore
        getPopupContainer={() => popupContainer}
        theme={props.themeConfig}
      >
        <Foo {...props} />
      </XProvider>
    </StyleProvider>
  ) : null;
// Foo.tsx
import { createStyles } from 'antd-style';
import React, { type FC } from 'react';

const Foo: FC<{ title: string }> = (props) => {
  const useStyle = createStyles(({ token, css }) => ({
    asd: css`
      color: ${token.colorPrimary};
    `,
  }));
  const { styles } = useStyle();
  return <h4 className={styles.asd}>{props.title}</h4>;
};

export default Foo;

Image

可复现 demo

© 版本信息

  • antd-style 版本: 3.7.1
  • 浏览器环境 Chrome
  • 开发环境 windows 10

🚑 其他信息

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions