diff --git a/.changeset/cold-rocks-notice.md b/.changeset/cold-rocks-notice.md new file mode 100644 index 000000000..e3c1ada62 --- /dev/null +++ b/.changeset/cold-rocks-notice.md @@ -0,0 +1,5 @@ +--- +"@khanacademy/wonder-blocks-form": patch +--- + +Adds `width: 100%` to `legend` element to allow expanding it to fill the available space diff --git a/__docs__/wonder-blocks-form/radio-group.stories.tsx b/__docs__/wonder-blocks-form/radio-group.stories.tsx index 8bc5f926d..6d0f678ab 100644 --- a/__docs__/wonder-blocks-form/radio-group.stories.tsx +++ b/__docs__/wonder-blocks-form/radio-group.stories.tsx @@ -2,7 +2,9 @@ import * as React from "react"; import {StyleSheet} from "aphrodite"; import type {Meta, StoryObj} from "@storybook/react"; -import {LabelLarge} from "@khanacademy/wonder-blocks-typography"; +import {View} from "@khanacademy/wonder-blocks-core"; +import {semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens"; +import {LabelLarge, LabelMedium} from "@khanacademy/wonder-blocks-typography"; import {Choice, RadioGroup} from "@khanacademy/wonder-blocks-form"; import packageConfig from "../../packages/wonder-blocks-form/package.json"; @@ -226,6 +228,36 @@ FiltersOutFalsyChildren.parameters = { }, }; +/** + * There are specific situations where you might want to use a custom label + * component instead of using the default `LabelMedium` component. This example + * demonstrates how to use a custom label component that can be passed in as a + * prop to the `RadioGroup` component. + */ +export const CustomLabel: StoryComponentType = { + ...Default, + args: { + style: { + // Adding an arbitrary width to the radio group to demonstrate how + // the custom label component expands to fill the available space. + width: 400, + }, + label: ( + + Pokemon + (optional) + + ), + }, +}; + const styles = StyleSheet.create({ choice: { margin: 0, diff --git a/packages/wonder-blocks-form/src/components/group-styles.ts b/packages/wonder-blocks-form/src/components/group-styles.ts index 6ce5e91c9..ae48810b3 100644 --- a/packages/wonder-blocks-form/src/components/group-styles.ts +++ b/packages/wonder-blocks-form/src/components/group-styles.ts @@ -15,6 +15,8 @@ const styles: StyleDeclaration = StyleSheet.create({ legend: { padding: 0, + // Let the legend use the size defined by the parent. + width: "100%", }, description: {