Skip to content

Commit 25f291b

Browse files
committed
fix(checkbox-group, radio-button-group): ensure right-aligned legend does not extend past the input
1 parent cbaf889 commit 25f291b

File tree

4 files changed

+49
-82
lines changed

4 files changed

+49
-82
lines changed

src/components/checkbox/checkbox-group/checkbox-group.component.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export const CheckboxGroup = ({
102102
warning={warning}
103103
isRequired={required}
104104
isOptional={isOptional}
105+
width="fit-content"
105106
{...(combinedAriaDescribedBy && {
106107
"aria-describedby": combinedAriaDescribedBy,
107108
})}

src/components/checkbox/checkbox-test.stories.tsx

+13-50
Original file line numberDiff line numberDiff line change
@@ -145,66 +145,29 @@ NewValidation.args = {
145145
inline: false,
146146
};
147147

148-
export const GroupWithFieldMetadata = ({ ...args }: CheckboxGroupProps) => {
148+
export const WithLegendAlignment = ({ ...args }: CheckboxGroupProps) => {
149149
return (
150150
<CarbonProvider validationRedesignOptIn>
151-
{["left", "right"].map((legendAlign) => (
152-
<div key={legendAlign}>
153-
<CheckboxGroup
154-
{...args}
155-
legendAlign={legendAlign as CheckboxGroupProps["legendAlign"]}
156-
>
157-
<Checkbox label="Checkbox 1" />
158-
<Checkbox label="Checkbox 2" />
159-
</CheckboxGroup>
160-
</div>
161-
))}
151+
<CheckboxGroup {...args} legendAlign="left" mb={2}>
152+
<Checkbox label="Checkbox option 1" />
153+
<Checkbox label="Checkbox option 2" fieldHelp="fieldHelp Text" />
154+
</CheckboxGroup>
155+
<CheckboxGroup {...args} legendAlign="right">
156+
<Checkbox label="Checkbox option 1" />
157+
<Checkbox label="Checkbox option 2" fieldHelp="fieldHelp Text" />
158+
</CheckboxGroup>
162159
</CarbonProvider>
163160
);
164161
};
165-
GroupWithFieldMetadata.storyName = "Group With Field Metadata";
166-
167-
GroupWithFieldMetadata.args = {
168-
id: "default",
169-
label: "Example Checkbox",
170-
autoFocus: false,
171-
disabled: false,
172-
fieldHelp: "This text provides help for the input.",
173-
fieldHelpInline: false,
174-
reverse: false,
175-
labelHelp: "This text provides more information for the label.",
162+
WithLegendAlignment.storyName = "With Legend Alignment";
163+
WithLegendAlignment.args = {
164+
id: "label-align",
176165
legend: "Checkbox Group",
177166
legendHelp: "Help text",
178167
legendInline: false,
179-
legendAlign: "left",
180-
inputWidth: 0,
181-
labelWidth: 0,
182-
labelSpacing: 1,
183-
size: "small",
184-
value: "",
185-
ml: "0",
186-
adaptiveSpacingBreakpoint: 0,
187168
required: false,
188169
isOptional: false,
189-
helpAriaLabel: "",
190-
validationOnLabel: false,
191170
validationIconId: "",
192-
error: "",
171+
error: "Error message",
193172
warning: "",
194-
info: "",
195-
};
196-
197-
GroupWithFieldMetadata.argTypes = {
198-
labelSpacing: {
199-
options: [1, 2],
200-
control: {
201-
type: "select",
202-
},
203-
},
204-
size: {
205-
options: ["small", "large"],
206-
control: {
207-
type: "select",
208-
},
209-
},
210173
};

src/components/radio-button/radio-button-group/radio-button-group.component.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export const RadioButtonGroup = ({
150150
legendAlign={legendAlign}
151151
isRequired={required}
152152
isOptional={isOptional}
153+
width="fit-content"
153154
{...tagComponent("radiogroup", rest)}
154155
{...marginProps}
155156
ml={marginLeft}

src/components/radio-button/radio-button-test.stories.tsx

+34-32
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@ import CarbonProvider from "../carbon-provider";
88

99
export default {
1010
title: "Radio Button/Test",
11-
includeStories: [
12-
"WithLabelHelp",
13-
"WithValidationsOnButtons",
14-
"WithValidationsOnRadioGroup",
15-
"WithTooltipPosition",
16-
"WithTooltipPositionOnRadioGroup",
17-
"WithNewValidation",
18-
"WithNewValidationGroup",
19-
"WithHintTextAlignment",
20-
],
2111
parameters: {
2212
info: { disable: true },
2313
chromatic: {
@@ -133,6 +123,7 @@ WithValidationsOnRadioGroup.args = {
133123
legendInline: false,
134124
required: false,
135125
inline: false,
126+
legendAlign: "left",
136127
};
137128

138129
export const WithTooltipPosition: StoryFn<typeof RadioButton> = () => (
@@ -240,35 +231,46 @@ WithNewValidationGroup.parameters = {
240231
chromatic: { disableSnapshot: false },
241232
};
242233

243-
export const WithHintTextAlignment = ({
234+
export const WithLegendAlignment = ({
244235
...props
245236
}: Partial<RadioButtonGroupProps>) => {
246237
return (
247238
<CarbonProvider validationRedesignOptIn>
248-
{["left", "right"].map((legendAlign) => {
249-
return (
250-
<RadioButtonGroup
251-
name="radio-button-group"
252-
legendAlign={legendAlign as RadioButtonGroupProps["legendAlign"]}
253-
{...props}
254-
>
255-
<RadioButton id="radio-1" value="radio1" label="Yes" />
256-
<RadioButton id="radio-2" value="radio2" label="No" />
257-
<RadioButton
258-
id="radio-3"
259-
value="radio3"
260-
label="Maybe"
261-
fieldHelp="fieldHelp text"
262-
/>
263-
</RadioButtonGroup>
264-
);
265-
})}
239+
<RadioButtonGroup
240+
name="radio-button-group-left"
241+
{...props}
242+
legendAlign="left"
243+
mb={2}
244+
>
245+
<RadioButton id="radio-1-left" value="radio1" label="Yes" />
246+
<RadioButton id="radio-2-left" value="radio2" label="No" />
247+
<RadioButton
248+
id="radio-3-left"
249+
value="radio3"
250+
label="RadioButton with a longer label"
251+
fieldHelp="fieldHelp text"
252+
/>
253+
</RadioButtonGroup>
254+
<RadioButtonGroup
255+
name="radio-button-group-right"
256+
{...props}
257+
legendAlign="right"
258+
>
259+
<RadioButton id="radio-1-right" value="radio1" label="Yes" />
260+
<RadioButton id="radio-2-right" value="radio2" label="No" />
261+
<RadioButton
262+
id="radio-3-right"
263+
value="radio3"
264+
label="RadioButton with a longer label"
265+
fieldHelp="fieldHelp text"
266+
/>
267+
</RadioButtonGroup>
266268
</CarbonProvider>
267269
);
268270
};
269271

270-
WithHintTextAlignment.args = {
271-
id: "with-hint-text-alignment",
272+
WithLegendAlignment.args = {
273+
id: "with-legend-alignment",
272274
legend: "Radio group legend",
273275
error: "Error message",
274276
warning: "",
@@ -277,6 +279,6 @@ WithHintTextAlignment.args = {
277279
isOptional: false,
278280
inline: false,
279281
};
280-
WithHintTextAlignment.parameters = {
282+
WithLegendAlignment.parameters = {
281283
chromatic: { disableSnapshot: false },
282284
};

0 commit comments

Comments
 (0)