Skip to content

Commit ce22d15

Browse files
author
Luke Bowerman
authored
Expose wrap option on Fieldset for use by OptionsGroup(s) (#1104)
* Expose `wrap` option on Fieldset for use by OptionsGroup(s) * Tweak typing on Fieldset a smidge
1 parent a3853a7 commit ce22d15

File tree

6 files changed

+71
-20
lines changed

6 files changed

+71
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535
- `SelectMulti` create option unnecessary left padding
3636
- `FieldSelect`/`FieldSelectMulti` missing `aria-labelledby` attribute on the input
3737
- Major CSS linting clean-up
38+
- `CheckboxGroup` & `RadioGroup` options now properly wrap when the exceed the container width
3839

3940
### Removed
4041

packages/components/src/Form/Fieldset/Fieldset.tsx

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ import {
3333
} from '@looker/design-tokens'
3434
import omit from 'lodash/omit'
3535
import pick from 'lodash/pick'
36-
import { Space, SpaceHelperProps, SpaceVertical } from '../../Layout'
36+
import { Space, SpaceVertical } from '../../Layout'
37+
import { SimpleLayoutProps, simpleLayoutCSS } from '../../Layout/utils/simple'
3738
import { Legend } from '../Legend'
3839
import {
3940
Accordion,
@@ -45,19 +46,29 @@ import {
4546
} from '../../Accordion'
4647

4748
export interface FieldsetProps
48-
extends SpaceHelperProps,
49-
CompatibleHTMLProps<HTMLDivElement>,
49+
extends Omit<CompatibleHTMLProps<HTMLDivElement>, 'wrap'>,
50+
SimpleLayoutProps,
5051
AccordionControlProps {
51-
/** If true, the Fieldset will be wrapped by an Accordion structure (i.e. a collapsible section)
52+
/**
53+
* If true, the Fieldset will be wrapped by an Accordion structure (i.e. a collapsible section)
5254
* @default false
5355
*/
5456
accordion?: boolean
5557
ariaLabeledby?: string
56-
/** Determines where to place the label in relation to the input.
58+
/**
59+
* Determines where to place the label in relation to the input.
5760
* @default false
5861
*/
5962
inline?: boolean
60-
/** Displayed above the children of Fieldset
63+
64+
/**
65+
* Allowed fields to wrap if they exceed the container width
66+
* @default false
67+
*/
68+
wrap?: boolean
69+
70+
/**
71+
* Displayed above the children of Fieldset
6172
*/
6273
legend?: ReactNode
6374
/*
@@ -98,6 +109,7 @@ const FieldsetLayout = forwardRef(
98109
legend,
99110
fieldsHideLabel,
100111
children,
112+
wrap,
101113
...restProps
102114
} = omit(props, [...AccordionControlPropKeys])
103115

@@ -123,6 +135,7 @@ const FieldsetLayout = forwardRef(
123135
ref={ref}
124136
role="group"
125137
align="start"
138+
flexWrap={wrap ? 'wrap' : undefined}
126139
>
127140
{children}
128141
</LayoutComponent>
@@ -166,19 +179,18 @@ const FieldsetLayout = forwardRef(
166179
FieldsetLayout.displayName = 'FieldsetLayout'
167180

168181
export const Fieldset = styled(FieldsetLayout)`
182+
${simpleLayoutCSS}
183+
184+
${AccordionContent} {
185+
padding-top: ${({ theme }) => theme.space.medium};
186+
}
187+
169188
${AccordionDisclosure} {
170189
font-size: ${({ theme }) => theme.fontSizes.small};
171190
font-weight: ${({ theme }) => theme.fontWeights.semiBold};
172191
height: 24px;
173192
padding: ${({ theme: { space } }) => space.xxsmall} 0;
174193
}
175-
176-
${AccordionContent} {
177-
padding-top: ${({ theme }) => theme.space.medium};
178-
}
179194
`
180195

181-
Fieldset.defaultProps = {
182-
padding: 'none',
183-
width: '100%',
184-
}
196+
Fieldset.defaultProps = { width: '100%' }

packages/components/src/Form/Fieldset/__snapshots__/Fieldset.test.tsx.snap

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,21 @@ exports[`Fieldset 1`] = `
110110
font-weight: 600;
111111
}
112112
113+
.c0 {
114+
width: 100%;
115+
}
116+
117+
.c0 .c12 {
118+
padding-top: 1rem;
119+
}
120+
113121
.c0 .c11 {
114122
font-size: 0.875rem;
115123
font-weight: 600;
116124
height: 24px;
117125
padding: 0.25rem 0;
118126
}
119127
120-
.c0 .c12 {
121-
padding-top: 1rem;
122-
}
123-
124128
.c6 {
125129
color: #343C42;
126130
font-size: 0.75rem;

packages/components/src/Form/Inputs/OptionsGroup/CheckboxGroup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const CheckboxGroupLayout = forwardRef(
102102
<Fieldset
103103
data-testid="checkbox-list"
104104
inline={inline}
105-
flexWrap={inline ? 'wrap' : undefined}
105+
wrap={inline}
106106
gap={!inline ? 'xxsmall' : undefined}
107107
width={inline ? 'auto' : undefined}
108108
ref={ref}

packages/components/src/Form/Inputs/OptionsGroup/RadioGroup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const RadioGroupLayout = forwardRef(
9595
<Fieldset
9696
data-testid="radio-list"
9797
inline={inline}
98-
flexWrap={inline ? 'wrap' : undefined}
98+
wrap={inline}
9999
gap={!inline ? 'xxsmall' : undefined}
100100
width={inline ? 'auto' : undefined}
101101
ref={ref}

storybook/src/Forms/CheckboxGroup.stories.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,40 @@ const options = [
6161
label: 'Roquefort',
6262
value: 'roquefort',
6363
},
64+
{
65+
label: 'Cheddar',
66+
value: 'cheddar',
67+
},
68+
{
69+
label: 'Gouda',
70+
value: 'gouda',
71+
},
72+
{
73+
disabled: true,
74+
label: 'Swiss',
75+
value: 'swiss',
76+
},
77+
{
78+
label: 'Roquefort',
79+
value: 'roquefort',
80+
},
81+
{
82+
label: 'Cheddar',
83+
value: 'cheddar',
84+
},
85+
{
86+
label: 'Gouda',
87+
value: 'gouda',
88+
},
89+
{
90+
disabled: true,
91+
label: 'Swiss',
92+
value: 'swiss',
93+
},
94+
{
95+
label: 'Roquefort',
96+
value: 'roquefort',
97+
},
6498
]
6599

66100
const defaultValueCheckbox = ['swiss', 'cheddar']

0 commit comments

Comments
 (0)