Skip to content

Commit 26eda60

Browse files
committed
Fix stretched SelectorGroup
1 parent e0000a1 commit 26eda60

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
@@ -100,7 +100,7 @@ export interface SelectorProps
100100

101101
export const SelectorGroupContext = createContext(false);
102102

103-
const legacySizeMap: Record<string, 's' | 'm'> = {
103+
export const legacySizeMap: Record<string, 's' | 'm'> = {
104104
kilo: 's',
105105
mega: 'm',
106106
};
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 { forwardRef, useId, type FieldsetHTMLAttributes } from 'react';
2020
import {
2121
Selector,
2222
SelectorGroupContext,
23+
legacySizeMap,
2324
type SelectorProps,
2425
type SelectorSize,
2526
} from '../Selector/Selector.js';
@@ -83,7 +84,7 @@ export interface SelectorGroupProps
8384
*/
8485
size?: SelectorSize;
8586
/**
86-
* Whether the group should take the whole width available. Defaults to true.
87+
* Whether the group should take the whole width available. Defaults to false.
8788
*/
8889
stretch?: boolean;
8990
/**
@@ -139,11 +140,12 @@ export const SelectorGroup = forwardRef<
139140
optionalLabel,
140141
disabled,
141142
multiple,
142-
size,
143+
'size': legacySize = 'm',
143144
stretch = false,
144145
validationHint,
145146
invalid,
146147
hideLabel,
148+
className,
147149
...props
148150
},
149151
ref,
@@ -170,6 +172,8 @@ export const SelectorGroup = forwardRef<
170172
return null;
171173
}
172174

175+
const size = legacySizeMap[legacySize] || legacySize;
176+
173177
return (
174178
<FieldSet
175179
name={name}
@@ -178,6 +182,7 @@ export const SelectorGroup = forwardRef<
178182
disabled={disabled}
179183
role={multiple ? undefined : 'radiogroup'}
180184
aria-orientation={multiple ? undefined : 'horizontal'}
185+
className={clsx(className, stretch && classes.stretch, classes[size])}
181186
{...props}
182187
>
183188
<FieldLegend>
@@ -188,7 +193,7 @@ export const SelectorGroup = forwardRef<
188193
required={required}
189194
/>
190195
</FieldLegend>
191-
<div className={clsx(classes.base, stretch && classes.stretch)}>
196+
<div className={classes.options}>
192197
<SelectorGroupContext.Provider value={true}>
193198
{options.map((option) => (
194199
<Selector

0 commit comments

Comments
 (0)