wujie icon indicating copy to clipboard operation
wujie copied to clipboard

Firefox浏览器模式下,使用ant design4的组件下拉框不兼容

Open LedoTao opened this issue 2 years ago • 20 comments

描述bug Firefox浏览器模式下,使用ant design4的组件,比如select,date组件下拉框无法出现,其他浏览器没有问题

如何复现 给出详细的复现步骤 1、第一步 在火狐浏览器中打开无界官网中的在线体验 2、 第二步 粘贴ant design4的组件官网https://4x.ant.design/components/select-cn/ 3、select的下拉框无法正常出现

LedoTao avatar Feb 07 '23 08:02 LedoTao

同样遇到这个问题

rodchen-king avatar Feb 09 '23 02:02 rodchen-king

复议

LaymanA avatar Feb 09 '23 06:02 LaymanA

复议,element-plus同样也是这个问题

MonderQJ avatar Feb 17 '23 03:02 MonderQJ

复议,我这边谷歌浏览器也不行

cater111 avatar Feb 27 '23 02:02 cater111

是下拉框的位置错了么,还是下拉框都出不来呢

JC-Guy avatar Mar 24 '23 02:03 JC-Guy

我这边正常 chrome 111,应该是资源没加载完毕阻塞了运行 建议你本地搭建一个应用测试下自己的子应用 image

fychinesepjj avatar Mar 24 '23 03:03 fychinesepjj

我这边正常 chrome 111,应该是资源没加载完毕阻塞了运行 建议你本地搭建一个应用测试下自己的子应用 image

用火狐浏览器

LedoTao avatar Mar 24 '23 07:03 LedoTao

需要设置弹出框不插入到body中,但是select官方提供的getPopupContainer在Firefox上不生效,最后我是外层套了ConfigProvider并设置getPopupContainer,然后将ant-select-dropdown的top和left写死,解决了Firefox的问题,同样Popover等弹出 也有相同的问题,这个方案也可以解决

<ConfigProvider getPopupContainer={() => selectRef.current}> <div ref={selectRef} className={styles.curSelect}> <Select options={options} popupClassName={'curSelectPopup'} // getPopupContainer={(triggerNode) => triggerNode.parentNode} /> </div> </ConfigProvider>

css .curSelect { position: relative; } .curSelectPopup.ant-select-dropdown { left: 0 !important; top: 36px !important; }

rensixuan001 avatar Apr 12 '23 07:04 rensixuan001

复议。谷歌正常,但火狐失效

lijie602 avatar May 16 '23 05:05 lijie602

复议

shixintian avatar May 23 '23 10:05 shixintian

复议 谷歌正常 火狐失效

peak1024 avatar May 30 '23 07:05 peak1024

目前看,firefox官网常规版会出现问题,但是ESR版本正常

lijie602 avatar May 30 '23 08:05 lijie602

/**
 * 原因: 由于 antd 依赖的 rc-util/es/dom/isVisible.js 中 判断元素是否显示的方法在火狐下失效。
 * 解法: 代理 instanceof Element 方法, 手动检验 element 是否是 dom 元素
 * 
 * 在项目入口处执行如下代码
 * */
Object.defineProperty(Element, Symbol.hasInstance, {
  value: function (left: any) {
    // const right = this;
    if (typeof left !== 'object' || !left) return false;
    const getType = (obj: any) => Object.prototype.toString.call(obj);
    let head = left.__proto__;
    const targetClass = getType(this);
    // eslint-disable-next-line no-constant-condition
    try {
      while (head) {
        // 重写 instanceof 判断逻辑
        if (getType(head) === targetClass) {
          return true;
        }
        head = head.__proto__;
      }
    } catch (e) {
      console.error(e);
    }

    return false;
  },
});

lin-123 avatar Jun 07 '23 12:06 lin-123

是下拉框的位置错了么,还是下拉框都出不来呢

下拉框出不来,位置是对的

wu529778790 avatar Jul 11 '23 02:07 wu529778790

使用该插件即可解决:https://wujie-polyfill.github.io/doc/plugins/instanceof.html

lijie602 avatar Jul 18 '23 07:07 lijie602

使用该插件即可解决:https://wujie-polyfill.github.io/doc/plugins/instanceof.html

antd4解决了,可是antd5出问题了,弹框位置不准确

LedoTao avatar Sep 07 '23 08:09 LedoTao

我们用Antd 5也遇到这个问题了,放弃了vite ,用rspack 先顶一顶,rspack的问题是不支持sentry 插件

faner11 avatar Sep 11 '23 03:09 faner11

使用该插件即可解决:https://wujie-polyfill.github.io/doc/plugins/instanceof.html

antd4解决了,可是antd5出问题了,弹框位置不准确

在firefox下,所有节点的基类都是指向基座的Node(chrome是iframe的Node),导致wujie的patchNodeEffect处理无效。 新增如下插件处理getRootNode指向,可以解决位置不准确问题

{
        patchElementHook(element: any, iframeWindow: any) {
              // 解决firefox下拉框无法对齐
              try {
                Object.defineProperties(element, {
                  getRootNode: {
                    configurable: true,
                    get: () => iframeWindow.Node.prototype.getRootNode,
                  },
                });
              } catch (error) {
                console.warn(error);
              }
       },
}

songdy avatar Jan 23 '24 04:01 songdy

使用该插件即可解决:https://wujie-polyfill.github.io/doc/plugins/instanceof.html

antd4解决了,可是antd5出问题了,弹框位置不准确

在firefox下,所有节点的基类都是指向基座的Node(chrome是iframe的Node),导致wujie的patchNodeEffect处理无效。 新增如下插件处理getRootNode指向,可以解决位置不准确问题

{
        patchElementHook(element: any, iframeWindow: any) {
              // 解决firefox下拉框无法对齐
              try {
                Object.defineProperties(element, {
                  getRootNode: {
                    configurable: true,
                    get: () => iframeWindow.Node.prototype.getRootNode,
                  },
                });
              } catch (error) {
                console.warn(error);
              }
       },
}

在firefox下,Select的弹出层位置计算错误的问题用这个方法可以, 感谢!!! image

WhiteWen avatar Jun 05 '24 08:06 WhiteWen

arco.design 也存在同样问题

Image

Stephen-Monster avatar Oct 30 '25 14:10 Stephen-Monster