Skip to content

fix: Radix components bugs during edit #4558

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

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 13 additions & 5 deletions apps/builder/app/canvas/collapsed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ const findFirstNonContentsParent = (element: Element) => {
// Get the computed style of the parent
const computedStyle = window.getComputedStyle(parent);

const isHidden = parent.getAttribute("hidden") !== null;

// Check if the display is not 'contents'
if (computedStyle.display !== "contents") {
if (computedStyle.display !== "contents" && !isHidden) {
return parent;
}

Expand Down Expand Up @@ -196,14 +198,20 @@ const recalculate = () => {
continue;
}

const elementStyle = window.getComputedStyle(element);

// Find all Leaf like elements
// Leaf like elements are elements that have no children or all children are absolute or fixed
// Excluding hidden elements without size
if (element.childElementCount === 0) {
elementsToRecalculate.push(element);
}
if (element.offsetParent !== null) {
elementsToRecalculate.push(element);
}

const elementStyle = window.getComputedStyle(element);
// const elementPosition = window.getComputedStyle(element).position;
if (elementStyle.position === "fixed") {
elementsToRecalculate.push(element);
}
}

const parentElement = findFirstNonContentsParent(element);

Expand Down
14 changes: 14 additions & 0 deletions packages/sdk-components-react-radix/src/collapsible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,18 @@ export const hooksCollapsible: Hook = {
}
}
},
onNavigatorUnselect: (context, event) => {
for (const instance of event.instancePath) {
if (instance.component === `${namespace}:CollapsibleContent`) {
const collapsible = getClosestInstance(
event.instancePath,
instance,
`${namespace}:Collapsible`
);
if (collapsible) {
context.setMemoryProp(collapsible, "open", undefined);
}
}
}
},
};
25 changes: 24 additions & 1 deletion packages/sdk-components-react-radix/src/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ const namespace = "@webstudio-is/sdk-components-react-radix";
export const hooksTabs: Hook = {
onNavigatorSelect: (context, event) => {
for (const instance of event.instancePath) {
if (instance.component === `${namespace}:TabsContent`) {
if (
instance.component === `${namespace}:TabsContent` ||
instance.component === `${namespace}:TabsTrigger`
) {
const tabs = getClosestInstance(
event.instancePath,
instance,
Expand All @@ -59,4 +62,24 @@ export const hooksTabs: Hook = {
}
}
},
onNavigatorUnselect: (context, event) => {
for (const instance of event.instancePath) {
if (
instance.component === `${namespace}:TabsContent` ||
instance.component === `${namespace}:TabsTrigger`
) {
const tabs = getClosestInstance(
event.instancePath,
instance,
`${namespace}:Tabs`
);
const contentValue =
context.getPropValue(instance, "value") ??
context.indexesWithinAncestors.get(instance.id)?.toString();
if (tabs && contentValue) {
context.setMemoryProp(tabs, "value", undefined);
}
}
}
},
};
Loading