Merge pull request #216 from webzard-io/fix/windlike-patch

fix: set slot to different types depend on slot children's num
This commit is contained in:
tanbowensg 2022-01-20 10:35:25 +08:00 committed by GitHub
commit 951f8c8dd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 4 deletions

View File

@ -74,7 +74,7 @@ export default implementRuntimeComponent({
</TabList>
<TabPanels>
{tabNames.map((_, idx) => {
const ele = slotsElements.content ? slotsElements.content[idx] : placeholder;
const ele = slotsElements.content ? ([] as React.ReactElement[]).concat(slotsElements.content)[idx] : placeholder;
return (
<TabPanel
key={idx}

View File

@ -150,15 +150,17 @@ const _ImplWrapper = React.forwardRef<HTMLDivElement, ImplWrapperProps>((props,
if (!childrenMap[c.id]) {
return {};
}
const res: Record<string, React.ReactElement[]> = {};
const res: Record<string, React.ReactElement[] | React.ReactElement> = {};
for (const slot in childrenMap[c.id]) {
res[slot] = childrenMap[c.id][slot].map(child => {
const slotChildren = childrenMap[c.id][slot].map(child => {
if (!childrenCache.get(child)) {
const ele = <ImplWrapper key={child.id} {...props} component={child} />;
childrenCache.set(child, ele);
}
return childrenCache.get(child)!;
});
res[slot] = slotChildren.length === 1 ? slotChildren[0] : slotChildren;
}
return res;
}

View File

@ -24,7 +24,7 @@ export type ComponentImplProps<
> = ImplWrapperProps<KSlot> &
TraitResult<KStyleSlot, KEvent>['props'] &
RuntimeFunctions<TState, TMethods> & {
slotsElements: Record<KSlot, React.ReactElement[]>;
slotsElements: Record<KSlot, React.ReactElement[] | React.ReactElement>;
};
export type ComponentImpl<