Skip to content

[useClickAway][Antd Input] 在 Antd Input 组件使用 useClickAway 页面报错 #2702

@justsso1

Description

@justsso1

报错:

image

最小可复现代码:

import { useClickAway } from 'ahooks';
import { Input } from 'antd';
import { useRef } from 'react';

const { TextArea } = Input;

const Comp = () => {
  const ref = useRef(null);

  useClickAway(() => {
    console.log('ClickAway');
  }, ref);

  return <TextArea ref={ref} />;
};

出错的代码位置是 packages/hooks/src/utils/getDocumentOrShadow.ts:

const checkIfAllInShadow = (targets: BasicTarget[]): boolean => {
  return targets.every((item) => {
    const targetElement = getTargetElement(item);
    if (!targetElement) return false;
    if (targetElement.getRootNode() instanceof ShadowRoot) return true; // 就是这里
    return false;
  });
};

使用原生的input元素是没有问题,但是使用 antd 的Input或者 TextArea 都会有问题。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions