Skip to content

Commit cb34663

Browse files
authored
Fix layout shift in PricingOptions accordion (#1121)
* rework pricingoption accordion logic * add visual snapshots * add changeset * rename a state variable * copilot feedback * remove redundant condition for narrow viewports * add tests
1 parent c7d36b9 commit cb34663

File tree

18 files changed

+489
-74
lines changed

18 files changed

+489
-74
lines changed

.changeset/chilled-moles-remain.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@primer/react-brand': patch
3+
---
4+
5+
Fix layout shift in the `PricingOptions` feature list accordion
6+
7+
The feature lists now respect their explicit `expanded` prop values on the initial render, and no longer apply default animations. This prevents layout shift in certain SSR contexts where the component was incorrectly relying on the client-side `window` size even when explicitly passed `expanded={true}` or `expanded={false}`, which shouldn't depend on viewport size.

packages/react/src/PricingOptions/PricingOptions.features.stories.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,3 +1129,38 @@ ExpandedTablet.parameters = {
11291129
defaultViewport: 'ipad',
11301130
},
11311131
}
1132+
1133+
export const HideFeatureListOnNarrowAndRegular: StoryFn<typeof PricingOptions> = () => {
1134+
return (
1135+
<PricingOptions>
1136+
<PricingOptions.Item>
1137+
<PricingOptions.Heading>Copilot Individual</PricingOptions.Heading>
1138+
<PricingOptions.Description>
1139+
Code completions, Chat, and more for indie developers and freelancers.
1140+
</PricingOptions.Description>
1141+
<PricingOptions.Price trailingText="per month / $100 per year">10</PricingOptions.Price>
1142+
<PricingOptions.FeatureList expanded={{narrow: false, regular: false, wide: true}}>
1143+
<PricingOptions.FeatureListItem>Code completions</PricingOptions.FeatureListItem>
1144+
<PricingOptions.FeatureListItem>Chat in IDE and Mobile</PricingOptions.FeatureListItem>
1145+
<PricingOptions.FeatureListItem>CLI assistance</PricingOptions.FeatureListItem>
1146+
<PricingOptions.FeatureListItem>Security vulnerability filter</PricingOptions.FeatureListItem>
1147+
</PricingOptions.FeatureList>
1148+
<PricingOptions.Footnote>
1149+
Free for verified students, teachers, and maintainers of popular open source projects.
1150+
</PricingOptions.Footnote>
1151+
<PricingOptions.PrimaryAction as="a" href="#">
1152+
Start a free trial
1153+
</PricingOptions.PrimaryAction>
1154+
</PricingOptions.Item>
1155+
</PricingOptions>
1156+
)
1157+
}
1158+
HideFeatureListOnNarrowAndRegular.storyName = 'Hide feature list on all viewports except wide'
1159+
1160+
export const HideFeatureListOnNarrowAndRegularNarrow = () => <HideFeatureListOnNarrowAndRegular />
1161+
HideFeatureListOnNarrowAndRegularNarrow.parameters = {
1162+
viewport: {
1163+
defaultViewport: 'iphonexr',
1164+
},
1165+
}
1166+
HideFeatureListOnNarrowAndRegularNarrow.storyName = 'Hide feature list on all viewports except wide (narrow)'

packages/react/src/PricingOptions/PricingOptions.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,3 +444,7 @@
444444
.PricingOptions__feature-list-accordion[open] .PricingOptions__feature-list-accordion-chevron {
445445
transform: rotate(180deg);
446446
}
447+
448+
.PricingOptions__feature-list-accordion-content {
449+
animation: none !important;
450+
}

0 commit comments

Comments
 (0)