Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(): render tabs eagerly #1474

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions bricks/containers/src/tab/tab-group/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useRef, useState } from "react";
import React, { useEffect, useLayoutEffect, useRef, useState } from "react";
import { EventEmitter, createDecorators } from "@next-core/element";
import { ReactNextElement } from "@next-core/react-element";
import styleText from "./tab.shadow.css";
Expand Down Expand Up @@ -135,27 +135,27 @@ function TabGroupElement({
});
};

const initSetTab = () => {
const navSlot = navSlotRef.current;
const navSlotChildren = navSlot.assignedElements()[0]
?.childNodes as unknown as TabItem[];
navSlotChildren?.length > 0 &&
setTabs(() => {
const tabs: string[] = [];
navSlotChildren.forEach((item) => tabs.push(item.panel));
return tabs;
});
};
useLayoutEffect(() => {
const handleSetActive = (e: MouseEvent) => {
const panel = (e.target as TabItem).panel;
if (panel) {
setActiveItem(panel);
onTabSelect?.(panel);
}
};

const handleSetActive = useCallback((e: MouseEvent) => {
const panel = (e.target as TabItem).panel;
if (panel) {
setActiveItem(panel);
onTabSelect?.(panel);
}
}, []);
const initSetTab = () => {
const navSlot = navSlotRef.current;
const navSlotChildren = navSlot.assignedElements()[0]
?.childNodes as unknown as TabItem[];
navSlotChildren?.length > 0 &&
setTabs(() => {
const tabs: string[] = [];
navSlotChildren.forEach((item) => tabs.push(item.panel));
return tabs;
});
};

useEffect(() => {
const navSlot = navSlotRef.current;
initSetTab();

Expand All @@ -165,7 +165,7 @@ function TabGroupElement({
navSlot.removeEventListener("click", handleSetActive);
navSlot.removeEventListener("slotchange", initSetTab);
};
}, [activePanel, handleSetActive]);
}, [onTabSelect]);

useEffect(() => {
if (tabs.length) {
Expand Down
Loading