react-component / react-component/trigger
Does not work when rendered inside an iframe
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- TypeScript
- Star
- 391
- Fork
- 245
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
Minimal reproduction
import { useEffect, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import RcTooltip from 'rc-tooltip';
import 'rc-tooltip/assets/bootstrap.css';
function IframeContent({ container }: { container: HTMLElement }) {
return createPortal(
<RcTooltip
overlay="Hello from tooltip"
placement="top"
getTooltipContainer={() => container}
>
<button>Hover me</button>
</RcTooltip>,
container,
);
}
export default function App() {
const iframeRef = useRef<HTMLIFrameElement>(null);
const [mountEl, setMountEl] = useState<HTMLElement | null>(null);
useEffect(() => {
const iframe = iframeRef.current;
if (!iframe) return;
const onLoad = () => {
setMountEl(iframe.contentDocument?.body ?? null);
};
iframe.addEventListener('load', onLoad);
if (iframe.contentDocument?.readyState === 'complete') onLoad();
return () => iframe.removeEventListener('load', onLoad);
}, []);
return (
<>
<iframe
ref={iframeRef}
srcDoc="<!DOCTYPE html><html><body></body></html>"
style={{ width: '100%', height: 200, border: '1px solid #ccc' }}
/>
{mountEl && <IframeContent container={mountEl} />}
</>
);
}
Expected behavior
@rc-component/trigger should support trigger and popup elements rendered inside iframe documents.
Popup positioning and visible area calculation should work regardless of whether the DOM elements come from the parent document or an iframe document.
Actual behavior
When rendered inside an iframe, popup alignment/visible area calculation can be incorrect because iframe <body> and <html> elements fail the instanceof HTMLBodyElement / instanceof HTMLHtmlElement checks.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách tìm đoạn mã định vị trigger và popup có kiểm tra HTMLBodyElement và HTMLHtmlElement bằng instanceof. Tái hiện ví dụ iframe bằng TypeScript được cung cấp và kiểm tra cách phép tính vùng hiển thị xử lý các phần tử thuộc một tài liệu khác. Công việc được xem là hoàn tất khi việc căn chỉnh trigger và popup hoạt động chính xác cả bên trong các tài liệu iframe lẫn tài liệu cha.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- react, typescript
- Lĩnh vực
- frontend
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 58/100