Join the Webstudio community

Updated last week

Collapsible open or not

Hi team.

I'm working with a "Collapsible" radix.

My goal is to make a table of contents visible on the page/folder.
It works.

Except that I want the table of contents to be visible by default on a computer, and hidden by default on smaller screens.

My problem:
When I enable the "Open" property on my Collapsible, it no longer works. (Screen)

I thought about using an accordion, but I don't think it's the best architectural solution.

Is this a bug?
1
M
y
J
16 comments
The Open Attribute you used doesn't affect the initial state
Attachment
image.png
Create a new Attribute
Attachment
image.png
This will set the Default Open = true
I think this should solve the first Problem I don't know about closing it on Mobile maybe there is still a better version o you can use the Expression Edito to toggel but didn't try.
Hi @yannick thanks for yr answer. But this dosn't work. I'have set the defaultOpen true
on my collapsible
But no effect
@Mr Bean, do I have this correct:
You want the collapsible component to be closed on small devices (like a phone), but open when on a larger device (like a laptop). If that's the use-case you'll need to write soem Jsavascript to identify your breakpoints and then trigger your element).
It should work let me guid you through it the problem is defaultOpen only accepts strings but if you insert a String it is always open so what do we have to change that it works:
  1. Reset the Open value to Default as long as you have Open selected it is forced Open we don't want it
  2. If you set a String inside defaultOpen it is Open if there is no String it is closed teh solution:
collapsibleOpen ? "true" : ""
  1. As Jeremy mentioned if you want it to change with the breakpoints you have to change your value of collapsibleOpen depending on the breakpoint
Attachment
image.png
Deployed the fix. "open" property should just work now
Yes working nice.
But breakpoint modification dosn't work. I think is normal. I will use the solution of yannick
Great answer, thank you very much.
Just one question for 3. How do you change a WebStudio value based on a breakpoint?
The best way is having two instances and show one based on breakpoint with "display" style property
Boy that was a hard one the code to change the state is easy but it won't work because the radix component won't actually react to the new value. So there are two ways you can handle this:
  1. You can do it like Bogdan said you can have 2 instances i personal don't like this way because you have two instances so more unnecessary code which is unused on some devices but the other Option isn't the best either
  2. You can writea Skript to click the button if it isn't collapsed on Desktop or in Case it is Collapsed on Mobile so whenever the site loads it shows it correctly and afterwrads it works as you want it to work:
Here the Code place it inside a HTML embeed or in the Page settings:

<script type="module">
const root = document.getElementById("myCollapsible");
const btn = document.getElementById("myCollapsibleTrigger");
const mq = window.matchMedia("(min-width: 768px)");

function sync() {
if (mq.matches && root.dataset.state === "closed") { // if state == closed so we don't close it if its open
btn.click(); // Opens Radix
}
if (!mq.matches && root.dataset.state === "open") { // if state == open so we don't open it if its closed
btn.click(); // Close Radix
}
}

window.addEventListener("load", sync);
mq.addEventListener("change", sync);
</script>

If you want the Code to work set IDs in the collapsibel and in the Button(use the IDs from the Skript) You can change the breapoint in the skript. Don't set any other Values like the dafultopen or the open we used before.

This should work if you have any questions or need more let me know
Another thing to mention you have to publish the site to work it doesn't show in Preview
Workink 🙂
Thanks you so much !
I agree with you for the two instance
And this method using JS, but working. I will check if there is any bad loading in Google Speed Page

Thanks you !
Add a reply
Sign up and join the conversation on Discord
If you want the Code to work set IDs in the collapsibel and in the Button(use the IDs from the Skript) You can change the breapoint in the skript. Don't set any other Values like the dafultopen or the open we used before.This should work if you have any questions or need more let me know","upvoteCount":0,"dateCreated":"2025-05-21T20:25:41.735Z","datePublished":"2025-05-21T20:25:41.735Z","dateModified":"2025-05-21T20:26:52.269Z","url":"https://help.webstudio.is/collapsible-open-or-not-yrK3Ss0PQWFh#f53b4c91-afc7-432c-8b41-3a25102db2c7","author":{"@type":"Person","url":"https://help.webstudio.is/members/ab3c43d4-d036-4884-b276-d8da47c3467b","name":"yannick | revaliant","identifier":"ab3c43d4-d036-4884-b276-d8da47c3467b","image":"https://cdn.discordapp.com/avatars/426729168907272203/645a32b18b9a095435f0d5ee4d08f7da.webp?size=256"}},{"@type":"Answer","text":"Another thing to mention you have to publish the site to work it doesn't show in Preview","upvoteCount":0,"dateCreated":"2025-05-21T20:38:13.627Z","datePublished":"2025-05-21T20:38:13.627Z","dateModified":"2025-05-21T20:38:13.627Z","url":"https://help.webstudio.is/collapsible-open-or-not-yrK3Ss0PQWFh#8ba62181-f83f-4c8c-9f66-a4c5aa007680","author":{"@type":"Person","url":"https://help.webstudio.is/members/ab3c43d4-d036-4884-b276-d8da47c3467b","name":"yannick | revaliant","identifier":"ab3c43d4-d036-4884-b276-d8da47c3467b","image":"https://cdn.discordapp.com/avatars/426729168907272203/645a32b18b9a095435f0d5ee4d08f7da.webp?size=256"}},{"@type":"Answer","text":"Workink 🙂Thanks you so much !I agree with you for the two instanceAnd this method using JS, but working. I will check if there is any bad loading in Google Speed PageThanks you !","upvoteCount":0,"dateCreated":"2025-05-22T21:26:41.653Z","datePublished":"2025-05-22T21:26:41.653Z","dateModified":"2025-05-22T21:26:41.653Z","url":"https://help.webstudio.is/collapsible-open-or-not-yrK3Ss0PQWFh#a6c60f79-6319-4ce8-a603-a28ef23e6e9c","author":{"@type":"Person","url":"https://help.webstudio.is/members/f623c301-541b-4951-9689-b1996b117cf7","name":"Mr Bean","identifier":"f623c301-541b-4951-9689-b1996b117cf7","image":"https://cdn.discordapp.com/avatars/219368881800609792/f3cbc6fa051e291e562b4da9154bddaf.webp?size=256"}}]}}