Skip to content

Commit

Permalink
fix: Radix components bugs during edit (#4558)
Browse files Browse the repository at this point in the history
## Description

Also small fix of collapsible calculations.

## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
0000)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env` file
  • Loading branch information
istarkov committed Dec 11, 2024
1 parent 5b5fc27 commit 634c712
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
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);
}
}
}
},
};

0 comments on commit 634c712

Please sign in to comment.