Skip to content

Commit ef6f193

Browse files
authored
Fix choice cards when same product listed twice (#13984)
* Add ratePlan to choice cards ids * fix selected check * Fix comparison
1 parent 109e9e6 commit ef6f193

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

dotcom-rendering/src/components/marketing/epics/ThreeTierChoiceCards.tsx

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,34 @@ export const ThreeTierChoiceCards = ({
173173
({ product, label, benefitsLabel, benefits, pill }) => {
174174
const { supportTier } = product;
175175

176-
const selected =
177-
selectedProduct.supportTier === supportTier;
176+
const isSelected = (): boolean => {
177+
if (
178+
product.supportTier ===
179+
selectedProduct.supportTier
180+
) {
181+
if (
182+
product.supportTier !== 'OneOff' &&
183+
selectedProduct.supportTier !== 'OneOff'
184+
) {
185+
return (
186+
product.ratePlan ===
187+
selectedProduct.ratePlan
188+
);
189+
} else {
190+
return true;
191+
}
192+
} else {
193+
return false;
194+
}
195+
};
196+
const selected = isSelected();
178197

179-
const radioId = `choicecard-${id}-${supportTier}`;
198+
// Each radioId must be unique to the component and choice, e.g. "choicecard-epic-Contribution-Monthly"
199+
const radioId = `choicecard-${id}-${supportTier}${
200+
supportTier !== 'OneOff'
201+
? `-${product.ratePlan}`
202+
: ''
203+
}`;
180204

181205
return (
182206
<div
@@ -200,7 +224,7 @@ export const ThreeTierChoiceCards = ({
200224
/>
201225
}
202226
id={radioId}
203-
value={supportTier}
227+
value={radioId}
204228
cssOverrides={labelOverrideStyles(
205229
selected,
206230
)}

0 commit comments

Comments
 (0)