Skip to content

Commit 324e0f0

Browse files
author
Hector Arce De Las Heras
committed
Add lastChild Property to RadioButton Component
This commit introduces a new lastChild property to the RadioButton component to manage the bottom margin of radio buttons within a group. The lastChild property identifies the last radio button in a group and removes its bottom margin. Key changes include: Addition of lastChild property to the IRadioButtonContentStyled interface in radioButton.styled.ts, used to conditionally set the margin-bottom in the RadioButtonStyled component. Update to RadioButtonStandAlone component in radioButtonStandAlone.tsx to pass the lastChild property to the RadioButtonStyled component. Addition of lastChild property to the IRadioButtonStandAlone interface in radioButton.ts. Calculation of the lastChild property in the RadioButtonGroupStandAloneComponent in radioButtonGroupStandAlone.tsx, passed to the RadioButtonStandAlone component. These changes improve the visual consistency and spacing within radio button groups.
1 parent b1d7e8e commit 324e0f0

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

src/components/radioButtonGroup/components/radioButton/radioButton.styled.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ interface IRadioButtonContentStyled {
1515
styles: VariantStyles<RadioButtonStylesType>;
1616
state: RadioButtonStateType;
1717
hasLabel?: boolean;
18+
lastChild?: boolean;
19+
}
20+
21+
interface IRadioButtonErrorStyled {
22+
styles?: RadioButtonBaseStyles;
1823
}
1924

2025
interface IRadioButtonErrorStyled {
@@ -58,7 +63,7 @@ export const RadioButtonStyled = styled.div<IRadioButtonContentStyled>`
5863
display: ${props => (props.hasLabel ? 'grid' : 'block')};
5964
grid-template-columns: auto 1fr;
6065
${props => getStyles(props.styles?.[props.state]?.rowContainer)}
61-
66+
margin-bottom: ${props => (props.lastChild ? 0 : undefined)};
6267
& > :nth-child(3) {
6368
grid-column: 2;
6469
}

src/components/radioButtonGroup/components/radioButton/radioButtonStandAlone.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ export const RadioButtonStandAlone = (props: IRadioButtonStandAlone): JSX.Elemen
3333
: props.styles?.[props.state]?.label?.font_weight;
3434

3535
return (
36-
<RadioButtonStyled hasLabel={!!props.label} state={props.state} styles={props.styles}>
36+
<RadioButtonStyled
37+
hasLabel={!!props.label}
38+
lastChild={props.lastChild}
39+
state={props.state}
40+
styles={props.styles}
41+
>
3742
<RadioButtonContainerInput styles={props.styles}>
3843
<RadioButtonInputStyled
3944
aria-describedby={
@@ -64,7 +69,7 @@ export const RadioButtonStandAlone = (props: IRadioButtonStandAlone): JSX.Elemen
6469
<Label
6570
color={props.styles?.[props.state]?.label?.color}
6671
cursor={props.disabled ? CURSOR_DEFAULT : CURSOR_POINTER}
67-
data-testid={`${props.dataTestId}Label`}
72+
dataTestId={`${props.dataTestId}Label`}
6873
inputId={inputId}
6974
textVariant={props.styles?.[props.state]?.label?.font_variant}
7075
weight={getLabelFontWeight()}

src/components/radioButtonGroup/components/radioButton/types/radioButton.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export interface IRadioButtonStandAlone extends IRadioButtonStyled {
4040
dataTestId?: string;
4141
screenReaderId?: string;
4242
id?: string;
43+
lastChild?: boolean;
4344
}
4445
/**
4546
* @description

src/components/radioButtonGroup/radioButtonGroupStandAlone.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const RadioButtonGroupStandAloneComponent = (
6363
errorIcon={o.errorIcon}
6464
errorMessage={o.errorMessage}
6565
label={{ content: o.label }}
66+
lastChild={index === props.options.length - 1}
6667
name={props.name}
6768
screenReaderId={o.screenReader ? screenReaderId : undefined}
6869
state={o.state}

0 commit comments

Comments
 (0)