Accordion

Sometimes referred to as "dropdown". An interactive component that enables the organization and navigation of content by allowing users to expand and collapse sections.

Demo

This is an accordion group
This is the accordion trigger
This is the accordion content
This is the accordion trigger
This is the accordion content

Scripts

Add these before the </body> tag in your site/page settings

GSAP
 <script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/gsap.min.js"></script>
Accordion component
<script src="https://cdn.jsdelivr.net/npm/socks-ui@{v}/dist/accordion.js"></script>

Features

  • Full keyboard navigation
  • All attributes for screen readers added
  • Can expand one or multiple items

Anatomy

  • Group
    • Root
      • Trigger
      • Content

Usage

Main Attributes:

s-accordion = group - The parent div that holds the accordions. By default, one accordion is open per group.

s-accordion = root - The root element of the accordion. A div that holds the trigger button and the content.

s-accordion = trigger - A div or button that when clicked will open or close the accordion.

s-accordion = content - A div that has hidden content, only shown when the accordion is open. Do not add padding to this element, as it will not allow it to have 0 height. For padding, add another div inside that will add padding to the content.

Options (add to group element):

s-ease - Change easing. See GSAP Eases for options. Default: power3.inOut

s-duration - Set duration (in seconds). Default: 0.5

s-multiple - Allows multiple accordions to be open

s-first-open - Have the first accordion open by default

Animating an icon:

s-add-class - Adds an active class to the element that has it when an accordion opens. You can add a combo class to that element called s-active and change its styling on that combo class. Then remove the combo class before publishing. Make sure to add that combo class in a hidden page so that you don't lose it when you clean up classes. Note, an active class gets added to the element root by default.

s-active-class - (Add this to the accordion group!) Change the active class that gets added to elements that have the attribute s-add-class. Default: s-active

Advanced

Events

accordion-open

accordion-close

In both events, the accordion being toggled can be accessed through event.detail.

Example usage:

window.addEventListener('accordion-open', (event)=> {
    console.log(event.detail)
})
No custom events are exported for this component.

Methods

socks.accordions["id"].open() - Open accordion with given ID

socks.accordions["id"].close() - Close accordion with given ID

Note: If you don't add your own IDs, Socks UI will generate them for you. The format is "accordion-" + Group index + Accordion index.
So the first accordion would have the ID "accordion-0-0"

How to use them:

// this opens the accordion that has the ID "some-id"
socks.accordions["some-id"].open()

// you could also save them in your own variable to shorten it:
const accordions = socks.accordions;
accordions["some-id"].open()


// if your ID doesn't have dashes, you could also do this:
socks.accordions.some_id.open()
No custom methods are exported for this component.

Use Cases

No special use cases added yet
{"type":"@webflow/XscpData","payload":{"nodes":[{"_id":"29f21f3a-5e93-3762-94d6-de94420bd390","type":"Block","tag":"div","classes":["25004d11-aa89-42b8-b116-43debc0e8039"],"children":["cb475020-85f2-bb1e-ffda-0f3eca7c38e7","5d7b6fb4-9fb3-249d-49de-af2ab3670217"],"data":{"text":false,"tag":"div","devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[{"name":"s-accordion","value":"group"},{"name":"s-first-open","value":""},{"name":"s-active-class","value":"cc-active"}],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"cb475020-85f2-bb1e-ffda-0f3eca7c38e7","type":"Block","tag":"div","classes":["eade1e4b-844e-2758-3a0d-c7d0de837a5d"],"children":["36f3c0b2-1d0c-cc98-fdc8-1668b2333267","3c0e4b82-c271-10bf-604b-eab690937315"],"data":{"text":false,"tag":"div","devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[{"name":"s-accordion","value":"root"}],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"36f3c0b2-1d0c-cc98-fdc8-1668b2333267","type":"Block","tag":"div","classes":["97153c5f-d660-317c-9d1a-5e352a6cd0e1"],"children":["3c5cd45c-c1b4-6526-5292-c6d5a81c5caa","0b7c8e89-cd80-ae0f-7c74-60413c42430d"],"data":{"text":false,"tag":"div","devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[{"name":"s-accordion","value":"trigger"}],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"3c5cd45c-c1b4-6526-5292-c6d5a81c5caa","type":"Block","tag":"div","classes":[],"children":["563eac17-3453-8636-6263-6bd8f79bb385"],"data":{"text":true,"tag":"div","devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"563eac17-3453-8636-6263-6bd8f79bb385","text":true,"v":"Accordion"},{"_id":"0b7c8e89-cd80-ae0f-7c74-60413c42430d","type":"Image","tag":"img","classes":["6928c262-4385-797b-a9d4-957a8f137bc9","e408a658-875c-e488-2dd9-238515c89e6c"],"children":[],"data":{"img":{"id":"6609d4a75e9084457b3def2c"},"srcsetDisabled":false,"attr":{"width":"auto","height":"auto","alt":"__wf_reserved_inherit","src":"https://cdn.prod.website-files.com/6609d4a65e9084457b3dee6e/6609d4a75e9084457b3def2c_chevron-down_white.svg","loading":"lazy","id":""},"sizes":[],"devlink":{"runtimeProps":{},"slot":""},"displayName":"","xattr":[{"name":"s-add-class","value":""}],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"3c0e4b82-c271-10bf-604b-eab690937315","type":"Block","tag":"div","classes":["278f6c5c-1fd4-f04b-fdef-23add3ab16e4"],"children":["f51d2095-a9c6-4854-ac2f-cb9e21b262d3"],"data":{"text":false,"tag":"div","devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[{"name":"s-accordion","value":"content"}],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"f51d2095-a9c6-4854-ac2f-cb9e21b262d3","type":"Block","tag":"div","classes":["5eafa8b1-70b5-9dd3-1fc2-498ae8707056"],"children":[],"data":{"text":false,"tag":"div","devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"5d7b6fb4-9fb3-249d-49de-af2ab3670217","type":"Block","tag":"div","classes":["eade1e4b-844e-2758-3a0d-c7d0de837a5d"],"children":["b831ec5b-f57e-dcee-dadd-dda2a37e065f","fbbfd624-90cc-9787-c682-a40385c764ac"],"data":{"text":false,"tag":"div","devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[{"name":"s-accordion","value":"root"}],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"b831ec5b-f57e-dcee-dadd-dda2a37e065f","type":"Block","tag":"div","classes":["97153c5f-d660-317c-9d1a-5e352a6cd0e1"],"children":["76521447-644f-fd9b-808b-42a3870ca59b","6e981b39-ca69-0c68-cff4-e9bd86e83773"],"data":{"text":false,"tag":"div","devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[{"name":"s-accordion","value":"trigger"}],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"76521447-644f-fd9b-808b-42a3870ca59b","type":"Block","tag":"div","classes":[],"children":["a508a25c-9fb4-e4c4-2832-434be3d797a7"],"data":{"text":true,"tag":"div","devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"a508a25c-9fb4-e4c4-2832-434be3d797a7","text":true,"v":"Accordion"},{"_id":"6e981b39-ca69-0c68-cff4-e9bd86e83773","type":"Image","tag":"img","classes":["6928c262-4385-797b-a9d4-957a8f137bc9"],"children":[],"data":{"img":{"id":"6609d4a75e9084457b3def2c"},"srcsetDisabled":false,"attr":{"width":"auto","height":"auto","alt":"__wf_reserved_inherit","src":"https://cdn.prod.website-files.com/6609d4a65e9084457b3dee6e/6609d4a75e9084457b3def2c_chevron-down_white.svg","loading":"lazy","id":""},"sizes":[],"devlink":{"runtimeProps":{},"slot":""},"displayName":"","xattr":[{"name":"s-add-class","value":""}],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"fbbfd624-90cc-9787-c682-a40385c764ac","type":"Block","tag":"div","classes":["278f6c5c-1fd4-f04b-fdef-23add3ab16e4"],"children":["8bad7890-2e87-43e5-942c-4cc4547999e2"],"data":{"text":false,"tag":"div","devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[{"name":"s-accordion","value":"content"}],"search":{"exclude":false},"visibility":{"conditions":[]}}},{"_id":"8bad7890-2e87-43e5-942c-4cc4547999e2","type":"Block","tag":"div","classes":["5eafa8b1-70b5-9dd3-1fc2-498ae8707056"],"children":[],"data":{"text":false,"tag":"div","devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[],"search":{"exclude":false},"visibility":{"conditions":[]}}}],"styles":[{"_id":"25004d11-aa89-42b8-b116-43debc0e8039","fake":false,"type":"class","name":"accordion-group","namespace":"","comb":"","styleLess":"display: flex; margin-bottom: 40px; flex-direction: column; flex-wrap: nowrap; grid-column-gap: 16px; grid-row-gap: 16px;","variants":{},"children":[],"createdBy":"5de3f22e747d41cf4377aef1","origin":null,"selector":null},{"_id":"eade1e4b-844e-2758-3a0d-c7d0de837a5d","fake":false,"type":"class","name":"accordion","namespace":"","comb":"","styleLess":"border-top-style: solid; border-top-width: 1px; border-top-color: hsla(0, 0.00%, 100.00%, 1.00); border-right-style: solid; border-right-width: 1px; border-right-color: hsla(0, 0.00%, 100.00%, 1.00); border-bottom-style: solid; border-bottom-width: 1px; border-bottom-color: hsla(0, 0.00%, 100.00%, 1.00); border-left-style: solid; border-left-width: 1px; border-left-color: hsla(0, 0.00%, 100.00%, 1.00); border-top-left-radius: 0.8rem; border-top-right-radius: 0.8rem; border-bottom-left-radius: 0.8rem; border-bottom-right-radius: 0.8rem;","variants":{},"children":[],"createdBy":"5de3f22e747d41cf4377aef1","origin":null,"selector":null},{"_id":"97153c5f-d660-317c-9d1a-5e352a6cd0e1","fake":false,"type":"class","name":"accordion_trigger","namespace":"","comb":"","styleLess":"display: flex; padding-top: 16px; padding-right: 16px; padding-bottom: 16px; padding-left: 16px; justify-content: space-between; align-items: center;","variants":{},"children":[],"createdBy":"5de3f22e747d41cf4377aef1","origin":null,"selector":null},{"_id":"6928c262-4385-797b-a9d4-957a8f137bc9","fake":false,"type":"class","name":"icon","namespace":"","comb":"","styleLess":"width: 1.5rem; height: 1.5rem; transition-property: transform; transition-duration: 400ms; transition-timing-function: ease;","variants":{},"children":["2c72980d-cb6e-5bf2-4478-5c969012aba5","d8ce40a0-8a26-74a9-2d23-5b8243f62cfc","e408a658-875c-e488-2dd9-238515c89e6c"],"createdBy":"64f4c4cdbe566b5a0114b6d3","origin":null,"selector":null},{"_id":"e408a658-875c-e488-2dd9-238515c89e6c","fake":false,"type":"class","name":"cc-active","namespace":"","comb":"&","styleLess":"transform: rotate(180deg);","variants":{},"children":[],"createdBy":"5de3f22e747d41cf4377aef1","origin":null,"selector":null},{"_id":"278f6c5c-1fd4-f04b-fdef-23add3ab16e4","fake":false,"type":"class","name":"accordion_content","namespace":"","comb":"","styleLess":"display: none; overflow: hidden; height: 0px;","variants":{},"children":[],"createdBy":"5de3f22e747d41cf4377aef1","origin":null,"selector":null},{"_id":"5eafa8b1-70b5-9dd3-1fc2-498ae8707056","fake":false,"type":"class","name":"accordion_inner","namespace":"","comb":"","styleLess":"padding-top: 16px; padding-right: 16px; padding-bottom: 16px; padding-left: 16px;","variants":{},"children":[],"createdBy":"5de3f22e747d41cf4377aef1","origin":null,"selector":null}],"assets":[{"cdnUrl":"https://cdn.prod.website-files.com/6609d4a65e9084457b3dee6e/6609d4a75e9084457b3def2c_chevron-down_white.svg","siteId":"6609d4a65e9084457b3dee6e","width":16,"isHD":false,"height":16,"fileName":"6609d4a75e9084457b3def2c_chevron-down_white.svg","createdOn":"2023-10-22T11:51:34.488Z","origFileName":"chevron-down_white.svg","alt":"chevron down","fileHash":"3fa4459221a73ed7e976e392e9c1baf0","translationLoading":false,"variants":[],"mimeType":"image/svg+xml","s3Url":"https://s3.amazonaws.com/webflow-prod-assets/6609d4a65e9084457b3dee6e/6609d4a75e9084457b3def2c_chevron-down_white.svg","thumbUrl":"https://cdn.prod.website-files.com/6609d4a65e9084457b3dee6e/6609d4a75e9084457b3def2c_chevron-down_white.svg","_id":"6609d4a75e9084457b3def2c","updatedOn":"2024-03-31T21:24:55.591Z","fileSize":215,"localizedSettings":{}}],"ix1":[],"ix2":{"interactions":[],"events":[],"actionLists":[]}},"meta":{"droppedLinks":0,"dynBindRemovedCount":0,"dynListBindRemovedCount":0,"paginationRemovedCount":0,"universalBindingsRemovedCount":0,"unlinkedSymbolCount":0}}