Skip to content

Commit 9eb52fe

Browse files
authored
[Radio] Added a reusable narrowViewportDecorator that constrains forcing content overflow so scroll buttons appear (#3254)
## Summary: Added a reusable narrowViewportDecorator that constrains the story width to 400px, forcing content overflow so scroll buttons appear and applied the decorator to all "with scroll" radio widget stories. Issue: LEMS-3889 ## Test plan: Author: ivyolamit Reviewers: anakaren-rojas, ivyolamit, Myranae, mark-fitzgerald Required Reviewers: Approved By: anakaren-rojas, mark-fitzgerald, Myranae Checks: ⏭️ 1 check has been skipped, ✅ 10 checks were successful Pull Request URL: #3254
1 parent 0e578d7 commit 9eb52fe

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

.changeset/six-crabs-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/perseus": patch
3+
---
4+
5+
Added a reusable narrowViewportDecorator that constrains the story width to 400px, forcing content overflow so scroll buttons appear and applied the decorator to all "with scroll" radio widget stories.

packages/perseus/src/widgets/__testutils__/story-decorators.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as React from "react";
22

3+
import type {Decorator} from "@storybook/react-vite";
4+
35
export const mobileDecorator = (Story) => (
46
<div className="framework-perseus perseus-mobile">
57
<Story />
@@ -82,3 +84,10 @@ export const articleFloatRightDecorator = (Story) => (
8284
<div className="paragraph">{articleContent3}</div>
8385
</div>
8486
);
87+
88+
// Force overflow so the radio widget’s scroll controls render in these stories.
89+
export const narrowViewportDecorator: Decorator = (Story) => (
90+
<div style={{maxWidth: "400px"}}>
91+
<Story />
92+
</div>
93+
);

packages/perseus/src/widgets/radio/__docs__/multiple-choice-demo.new.stories.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as React from "react";
33

44
import {getFeatureFlags} from "../../../testing/feature-flags-util";
55
import {ServerItemRendererWithDebugUI} from "../../../testing/server-item-renderer-with-debug-ui";
6+
import {narrowViewportDecorator} from "../../__testutils__/story-decorators";
67
import {groupedRadioRationaleQuestion} from "../../graded-group/graded-group.testdata";
78
import {
89
question,
@@ -122,6 +123,7 @@ export const SelectWithImagesAndScroll = {
122123
question: SingleSelectOverflowImageContent,
123124
}),
124125
},
126+
decorators: [narrowViewportDecorator],
125127
};
126128

127129
export const SingleSelectWithScroll = {
@@ -130,6 +132,7 @@ export const SingleSelectWithScroll = {
130132
question: SingleSelectOverflowContent,
131133
}),
132134
},
135+
decorators: [narrowViewportDecorator],
133136
};
134137

135138
export const MultiSelectSimple = {
@@ -154,6 +157,7 @@ export const MultiSelectWithScroll = {
154157
question: multiChoiceQuestionSimpleOverflowContent,
155158
}),
156159
},
160+
decorators: [narrowViewportDecorator],
157161
};
158162

159163
export const GradedGroupSetWithScroll = {
@@ -162,6 +166,7 @@ export const GradedGroupSetWithScroll = {
162166
question: overflowContentInGradedGroupSet,
163167
}),
164168
},
169+
decorators: [narrowViewportDecorator],
165170
};
166171

167172
export const GradedGroup = {

packages/perseus/src/widgets/radio/__docs__/multiple-choice-initial-state-regression.stories.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {ApiOptions} from "../../../perseus-api";
1212
import {ServerItemRenderer} from "../../../server-item-renderer";
1313
import {getFeatureFlags} from "../../../testing/feature-flags-util";
1414
import {testDependenciesV2} from "../../../testing/test-dependencies";
15+
import {narrowViewportDecorator} from "../../__testutils__/story-decorators";
1516
import {
1617
choicesWithGraphie,
1718
choicesWithImages,
@@ -155,6 +156,7 @@ export const SingleSelectWithImagesAndScroll: Story = {
155156
}),
156157
}),
157158
},
159+
decorators: [narrowViewportDecorator],
158160
};
159161

160162
export const SingleSelectWithLongMathjax: Story = {
@@ -329,6 +331,7 @@ export const MultiSelectWithImagesAndScroll: Story = {
329331
}),
330332
}),
331333
},
334+
decorators: [narrowViewportDecorator],
332335
};
333336

334337
export const MultiSelectWithLongText: Story = {
@@ -363,6 +366,7 @@ export const GradedGroupSetWithScroll: Story = {
363366
question: overflowContentInGradedGroupSet,
364367
}),
365368
},
369+
decorators: [narrowViewportDecorator],
366370
};
367371

368372
function RadioQuestionRenderer(props: {

0 commit comments

Comments
 (0)