-
Notifications
You must be signed in to change notification settings - Fork 204
feat(accordion): add direct actions #4020
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
rise-erpelding
merged 9 commits into
spectrum-two
from
rise-erpelding/accordion-followups
Jul 29, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e7f0c25
feat(accordion): update test cases
rise-erpelding 5d00ba1
feat(accordion): add direct actions feature
rise-erpelding ce323bd
docs(accordion): update docs and tests to include direct actions
rise-erpelding 614148c
feat(accordion): style adjustments
rise-erpelding 49eadfa
fix(accordion): pr fixes
rise-erpelding 5e96d7f
fix(accordion): adjust minimum height to match spec
rise-erpelding 91f89d4
fix(tokens): temporarily add in correct top to text tokens for accordion
rise-erpelding 48b3275
Revert "fix(tokens): temporarily add in correct top to text tokens fo…
rise-erpelding 192bbd3
Revert "fix(accordion): adjust minimum height to match spec"
rise-erpelding File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
"@spectrum-css/accordion": minor | ||
--- | ||
|
||
Accordion now supports direct actions. Direct actions, which may consist of a quiet action button or a switch, or both, may be added to each accordion item's heading. Direct action items are vertically centered within the heading's first line of text for all sizes and densities, and maintain their own individual key focus states. | ||
|
||
To allow the same level of customizability found in other elements within this component, the following --mod custom properties have been added: | ||
|
||
- "--mod-accordion-item-direct-actions-height", | ||
- "--mod-accordion-item-direct-actions-spacing", | ||
- "--mod-accordion-item-direct-actions-vertical-spacing" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ | |
--spectrum-accordion-item-content-area-top-to-content: var(--spectrum-accordion-content-area-top-to-content); | ||
--spectrum-accordion-item-content-area-bottom-to-content: var(--spectrum-accordion-content-area-bottom-to-content); | ||
--spectrum-accordion-divider-thickness: var(--spectrum-divider-thickness-small); | ||
--spectrum-accordion-item-direct-actions-height: var(--spectrum-component-height-100); | ||
--spectrum-accordion-item-header-to-direct-actions-space: var(--spectrum-spacing-100); /* same for all sizes */ | ||
|
||
/* Text header */ | ||
--spectrum-accordion-item-header-font: var(--spectrum-sans-font-family-stack); | ||
|
@@ -40,6 +42,7 @@ | |
--spectrum-accordion-item-header-line-height: var(--spectrum-line-height-100); | ||
|
||
--spectrum-accordion-item-header-cursor: pointer; | ||
--spectrum-accordion-item-direct-actions-spacing: var(--spectrum-spacing-100); | ||
--spectrum-accordion-animation-duration: var(--spectrum-animation-duration-100); | ||
|
||
/* Text body */ | ||
|
@@ -72,6 +75,12 @@ | |
var(--mod-accordion-item-header-top-to-text-space, var(--spectrum-accordion-item-header-top-to-text-space)) + var(--mod-accordion-item-header-bottom-to-text-space, var(--spectrum-accordion-item-header-bottom-to-text-space)) + (var(--mod-accordion-item-header-font-size, var(--spectrum-accordion-item-header-font-size)) * var(--mod-accordion-item-header-line-height, var(--spectrum-accordion-item-header-line-height))) | ||
); | ||
|
||
/* Calculated vertical spacing for action button and switch to center them within the accordion item */ | ||
--spectrum-accordion-item-direct-actions-vertical-spacing: calc( | ||
(var(--mod-accordion-item-min-block-size, var(--spectrum-accordion-item-min-block-size)) - | ||
var(--mod-accordion-item-direct-actions-height, var(--spectrum-accordion-item-direct-actions-height))) / 2 | ||
); | ||
|
||
Comment on lines
+78
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did I miss a better way to do vertical spacing for this situation? I was finding that this got pretty complex, pretty fast:
|
||
/* Right-to-left adjustments for transforms */ | ||
&:dir(rtl) { | ||
--spectrum-logical-rotation: matrix(-1, 0, 0, 1, 0, 0); | ||
|
@@ -100,6 +109,7 @@ | |
--spectrum-accordion-item-header-top-to-text-space: var(--spectrum-accordion-top-to-text-small); | ||
--spectrum-accordion-item-header-bottom-to-text-space: var(--spectrum-accordion-bottom-to-text-small); | ||
--spectrum-accordion-top-to-disclosure-indicator: var(--spectrum-field-top-to-disclosure-icon-small); | ||
--spectrum-accordion-item-direct-actions-height: var(--spectrum-component-height-75); /* component height for switch and action button */ | ||
} | ||
|
||
.spectrum-Accordion--sizeL { | ||
|
@@ -116,6 +126,7 @@ | |
--spectrum-accordion-item-header-top-to-text-space: var(--spectrum-accordion-top-to-text-large); | ||
--spectrum-accordion-item-header-bottom-to-text-space: var(--spectrum-accordion-bottom-to-text-large); | ||
--spectrum-accordion-top-to-disclosure-indicator: var(--spectrum-field-top-to-disclosure-icon-large); | ||
--spectrum-accordion-item-direct-actions-height: var(--spectrum-component-height-200); | ||
} | ||
|
||
.spectrum-Accordion--sizeXL { | ||
|
@@ -132,6 +143,7 @@ | |
--spectrum-accordion-item-header-top-to-text-space: var(--spectrum-accordion-top-to-text-extra-large); | ||
--spectrum-accordion-item-header-bottom-to-text-space: var(--spectrum-accordion-bottom-to-text-extra-large); | ||
--spectrum-accordion-top-to-disclosure-indicator: var(--spectrum-field-top-to-disclosure-icon-extra-large); | ||
--spectrum-accordion-item-direct-actions-height: var(--spectrum-component-height-300); | ||
} | ||
|
||
.spectrum-Accordion--compact { | ||
|
@@ -237,6 +249,7 @@ | |
margin: 0; | ||
position: relative; | ||
box-sizing: border-box; | ||
display: flex; | ||
} | ||
|
||
.spectrum-Accordion-itemIndicator { | ||
|
@@ -268,15 +281,17 @@ | |
|
||
/* Focusable button that expands/collapses the accordion item. */ | ||
.spectrum-Accordion-itemHeader { | ||
overflow-wrap: anywhere; | ||
marissahuysentruyt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
word-break: normal; | ||
box-sizing: border-box; | ||
position: relative; | ||
|
||
display: flex; | ||
align-items: flex-start; | ||
justify-content: flex-start; | ||
|
||
/* start spacing controlled by edge to disclosure icon spacing */ | ||
padding-inline: 0 var(--mod-accordion-edge-to-content-area, var(--spectrum-accordion-edge-to-content-area)); | ||
padding-block: 0; /* reset user-agent styles */ | ||
line-height: var(--mod-accordion-item-header-line-height, var(--spectrum-accordion-item-header-line-height)); | ||
|
||
text-overflow: ellipsis; | ||
|
@@ -313,6 +328,20 @@ | |
background-color: var(--spectrum-accordion-background-color-down); | ||
color: var(--spectrum-accordion-item-header-color-down); | ||
} | ||
|
||
&:has(+ .spectrum-Accordion-itemDirectActions) { | ||
/* set spacing between header and direct actions, whether or not noInlinePadding variant is used */ | ||
padding-inline-end: var(--mod-accordion-item-header-to-direct-actions-space, var(--spectrum-accordion-item-header-to-direct-actions-space)); | ||
} | ||
} | ||
|
||
.spectrum-Accordion-itemDirectActions { | ||
margin-inline-end: var(--mod-accordion-edge-to-content-area, var(--spectrum-accordion-edge-to-content-area)); | ||
display: inline-flex; | ||
gap: var(--mod-accordion-item-direct-actions-spacing, var(--spectrum-accordion-item-direct-actions-spacing)); | ||
|
||
/* margin needs to be set on top and bottom to keep compact XL items vertically centered and prevent them from growing vertically */ | ||
margin-block: var(--mod-accordion-item-direct-actions-vertical-spacing, var(--spectrum-accordion-item-direct-actions-vertical-spacing)); | ||
} | ||
|
||
.spectrum-Accordion-item.is-open { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.