Skip to content

Commit 436e43d

Browse files
committed
Fix stretched SelectorGroup
1 parent 07c0da3 commit 436e43d

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

.changeset/famous-meals-perform.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sumup/circuit-ui': patch
3+
---
4+
5+
Fixed the stretched styles of the SelectorGroup component.

packages/circuit-ui/components/Selector/Selector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export interface SelectorProps
9898

9999
export const SelectorGroupContext = createContext(false);
100100

101-
const legacySizeMap: Record<string, 's' | 'm'> = {
101+
export const legacySizeMap: Record<string, 's' | 'm'> = {
102102
kilo: 's',
103103
mega: 'm',
104104
};
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
1-
.base {
2-
display: inline-flex;
1+
.stretch {
2+
width: 100%;
3+
}
4+
5+
.options {
6+
display: flex;
37
flex-direction: row;
4-
align-items: flex-start;
8+
align-items: stretch;
9+
justify-content: flex-start;
510
width: auto;
611
}
712

8-
.base > div:not(:last-child) {
9-
margin-right: var(--cui-spacings-mega);
13+
.stretch .options {
14+
justify-content: space-evenly;
15+
width: 100%;
1016
}
1117

12-
.stretch {
13-
display: flex;
14-
align-items: stretch;
15-
width: 100%;
18+
/* Sizes */
19+
.s .options {
20+
gap: var(--cui-spacings-byte);
21+
}
22+
23+
.m .options,
24+
.flexible .options {
25+
gap: var(--cui-spacings-kilo);
1626
}
1727

1828
.option {
1929
flex: 1;
20-
align-self: stretch;
2130
width: 100%;
2231
}

packages/circuit-ui/components/SelectorGroup/SelectorGroup.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
SelectorGroupContext,
2121
SelectorProps,
2222
SelectorSize,
23+
legacySizeMap,
2324
} from '../Selector/Selector.js';
2425
import {
2526
AccessibilityError,
@@ -81,7 +82,7 @@ export interface SelectorGroupProps
8182
*/
8283
size?: SelectorSize;
8384
/**
84-
* Whether the group should take the whole width available. Defaults to true.
85+
* Whether the group should take the whole width available. Defaults to false.
8586
*/
8687
stretch?: boolean;
8788
/**
@@ -137,11 +138,12 @@ export const SelectorGroup = forwardRef<
137138
optionalLabel,
138139
disabled,
139140
multiple,
140-
size,
141+
'size': legacySize = 'm',
141142
stretch = false,
142143
validationHint,
143144
invalid,
144145
hideLabel,
146+
className,
145147
...props
146148
},
147149
ref,
@@ -168,6 +170,8 @@ export const SelectorGroup = forwardRef<
168170
return null;
169171
}
170172

173+
const size = legacySizeMap[legacySize] || legacySize;
174+
171175
return (
172176
<FieldSet
173177
name={name}
@@ -176,6 +180,7 @@ export const SelectorGroup = forwardRef<
176180
disabled={disabled}
177181
role={multiple ? undefined : 'radiogroup'}
178182
aria-orientation={multiple ? undefined : 'horizontal'}
183+
className={clsx(className, stretch && classes.stretch, classes[size])}
179184
{...props}
180185
>
181186
<FieldLegend>
@@ -186,7 +191,7 @@ export const SelectorGroup = forwardRef<
186191
required={required}
187192
/>
188193
</FieldLegend>
189-
<div className={clsx(classes.base, stretch && classes.stretch)}>
194+
<div className={classes.options}>
190195
<SelectorGroupContext.Provider value={true}>
191196
{options.map((option) => (
192197
<Selector

0 commit comments

Comments
 (0)