Skip to content

Commit

Permalink
Fix stretched SelectorGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer committed Jan 23, 2024
1 parent 07c0da3 commit 95ffe71
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-meals-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': patch
---

Fixed the stretched styles of the SelectorGroup component.
2 changes: 1 addition & 1 deletion packages/circuit-ui/components/Selector/Selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export interface SelectorProps

export const SelectorGroupContext = createContext(false);

const legacySizeMap: Record<string, 's' | 'm'> = {
export const legacySizeMap: Record<string, 's' | 'm'> = {
kilo: 's',
mega: 'm',
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
.base {
display: inline-flex;
.stretch {
width: 100%;
}

.options {
display: flex;
flex-direction: row;
align-items: flex-start;
flex-wrap: wrap;
align-items: stretch;
justify-content: flex-start;
width: auto;
}

.base > div:not(:last-child) {
margin-right: var(--cui-spacings-mega);
.stretch .options {
justify-content: space-evenly;
width: 100%;
}

.stretch {
display: flex;
align-items: stretch;
width: 100%;
/* Sizes */
.s .options {
gap: var(--cui-spacings-byte);
}

.m .options,
.flexible .options {
gap: var(--cui-spacings-kilo);
}

.option {
flex: 1;
align-self: stretch;
width: 100%;
}
11 changes: 8 additions & 3 deletions packages/circuit-ui/components/SelectorGroup/SelectorGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
SelectorGroupContext,
SelectorProps,
SelectorSize,
legacySizeMap,
} from '../Selector/Selector.js';
import {
AccessibilityError,
Expand Down Expand Up @@ -81,7 +82,7 @@ export interface SelectorGroupProps
*/
size?: SelectorSize;
/**
* Whether the group should take the whole width available. Defaults to true.
* Whether the group should take the whole width available. Defaults to false.
*/
stretch?: boolean;
/**
Expand Down Expand Up @@ -137,11 +138,12 @@ export const SelectorGroup = forwardRef<
optionalLabel,
disabled,
multiple,
size,
'size': legacySize = 'm',
stretch = false,
validationHint,
invalid,
hideLabel,
className,
...props
},
ref,
Expand All @@ -168,6 +170,8 @@ export const SelectorGroup = forwardRef<
return null;
}

const size = legacySizeMap[legacySize] || legacySize;

return (
<FieldSet
name={name}
Expand All @@ -176,6 +180,7 @@ export const SelectorGroup = forwardRef<
disabled={disabled}
role={multiple ? undefined : 'radiogroup'}
aria-orientation={multiple ? undefined : 'horizontal'}
className={clsx(className, stretch && classes.stretch, classes[size])}
{...props}
>
<FieldLegend>
Expand All @@ -186,7 +191,7 @@ export const SelectorGroup = forwardRef<
required={required}
/>
</FieldLegend>
<div className={clsx(classes.base, stretch && classes.stretch)}>
<div className={classes.options}>
<SelectorGroupContext.Provider value={true}>
{options.map((option) => (
<Selector
Expand Down

0 comments on commit 95ffe71

Please sign in to comment.