Skip to content

Commit f7e7350

Browse files
author
Luke Bowerman
authored
Fieldset, Legend improvements + more
Checkbox & Radio - Remove default margin (previously `3px) ToggleSwitch - Explicitly specify `margin: 0` to suppress browser-default styling Field improvements - Set `id` on label based on field.id to allow for `Fieldset` `legend` replacement / association - Remove bottom margin - Vertically center input (for checkbox & radio group) within Field - Only apply Label styling to immediate child to prevent unintended consequences on nested Fields (e.g. CheckboxGroup) Fieldset - Implement with a `Space` / `SpaceVertical` layout (emulate `Form`) - Enable `inline` presentation - Use `div` instead of `fieldset` for DOM object due to Chrome implementation bug of `fieldset` (doesn’t allow for Flex / Grid layouts within `fieldset` - Minor fix-up to Fieldset composition (no visual impact) Legend - Extend `Label` styles to keep Label & Legend presentation bound where appropriate Grid - Correct column specification to prevent grid “blow-out” - Remove explicitly specified `width: 100%` (it’s implied) Space & SpaceVertical - Specify `width: 100%` by default - Add `layout` / `layoutProps` to simpleLayoutProps to allow for default width specification - Improve specificity of child selectors to apply only to direct descendants. - Use double selector to override theme reset behavior - FieldColor defaults to `width=“100%”` - `RequiredStar` was preventing visual artifact from being rendered (`className` assignment missing) - TextArea now only resizes on the Y access
1 parent 238f6c9 commit f7e7350

File tree

45 files changed

+716
-612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+716
-612
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- `Menu` closes by default on `MenuItem` click
1313
- Provide `@types/styled-system` as a package dependency
14+
- `TextArea` only supports vertical resizing now
1415

1516
### Fixed
1617

packages/components/src/Form/Fields/Field.tsx

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
import React, { FunctionComponent, ReactNode } from 'react'
28-
import styled from 'styled-components'
28+
import styled, { css } from 'styled-components'
2929
import { ResponsiveValue, TLengthStyledSystem } from 'styled-system'
3030
import omit from 'lodash/omit'
3131
import pick from 'lodash/pick'
@@ -124,7 +124,12 @@ const FieldLayout: FunctionComponent<FieldPropsInternal> = ({
124124

125125
return (
126126
<div className={className}>
127-
<Label htmlFor={id} fontWeight={labelFontWeight} fontSize={labelFontSize}>
127+
<Label
128+
fontSize={labelFontSize}
129+
fontWeight={labelFontWeight}
130+
htmlFor={id}
131+
id={`${id}-labeledby`}
132+
>
128133
{label}
129134
{required && <RequiredStar />}
130135
</Label>
@@ -147,12 +152,24 @@ FieldDetail.defaultProps = {
147152
const InputArea = styled.div``
148153
const MessageArea = styled.div``
149154

155+
const fieldLabelCSS = (inline?: boolean) =>
156+
inline
157+
? css`
158+
text-align: right;
159+
line-height: ${inputHeight};
160+
justify-self: end;
161+
height: ${inputHeight};
162+
padding-right: ${({ theme }) => theme.space.small};
163+
`
164+
: css`
165+
padding-bottom: ${({ theme }) => theme.space.xsmall};
166+
`
167+
150168
export const Field = styled(FieldLayout)<FieldPropsInternal>`
151169
height: fit-content;
152170
width: ${({ width }) => width || 'fit-content'};
153171
align-items: left;
154172
justify-content: space-between;
155-
margin-bottom: ${({ theme }) => theme.space.xsmall};
156173
157174
display: grid;
158175
grid-template-areas: ${({ inline }) =>
@@ -165,28 +182,16 @@ export const Field = styled(FieldLayout)<FieldPropsInternal>`
165182
${InputArea} {
166183
display: flex;
167184
grid-area: input;
185+
align-items: center;
168186
}
169187
170188
${MessageArea} {
171189
grid-area: messages;
172190
}
173191
174-
${Label} {
192+
& > ${Label} {
175193
grid-area: label;
176-
177-
${({ inline, theme }) =>
178-
inline
179-
? `
180-
text-align: right;
181-
line-height: ${inputHeight};
182-
justify-self: end;
183-
height: ${inputHeight};
184-
padding-right: ${theme.space.small};
185-
`
186-
: `
187-
padding-bottom: ${theme.space.xsmall};
188-
189-
`}
194+
${({ inline }) => fieldLabelCSS(inline)}
190195
}
191196
192197
${FieldDetail} {
@@ -195,10 +200,8 @@ export const Field = styled(FieldLayout)<FieldPropsInternal>`
195200
196201
${({ inline, theme }) =>
197202
inline &&
198-
`
199-
align-self: center;
200-
padding-left: ${theme.space.small};
201-
`}
203+
` align-self: center;
204+
padding-left: ${theme.space.small}; `}
202205
}
203206
204207
${ValidationMessage} {

packages/components/src/Form/Fields/FieldCheckbox/__snapshots__/FieldCheckbox.test.tsx.snap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ exports[`A FieldCheckbox 1`] = `
2424
}
2525
2626
.c4 {
27-
margin: 3px;
2827
display: inline-block;
2928
height: 1rem;
3029
position: relative;
@@ -69,7 +68,6 @@ exports[`A FieldCheckbox 1`] = `
6968
color: #343C42;
7069
font-size: 0.75rem;
7170
font-weight: 600;
72-
display: inline-block;
7371
}
7472
7573
.c0 {
@@ -176,7 +174,6 @@ exports[`A FieldCheckbox with checked value 1`] = `
176174
}
177175
178176
.c4 {
179-
margin: 3px;
180177
display: inline-block;
181178
height: 1rem;
182179
position: relative;
@@ -221,7 +218,6 @@ exports[`A FieldCheckbox with checked value 1`] = `
221218
color: #343C42;
222219
font-size: 0.75rem;
223220
font-weight: 600;
224-
display: inline-block;
225221
}
226222
227223
.c0 {

packages/components/src/Form/Fields/FieldColor/FieldColor.tsx

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import { useID, useWrapEvent } from '../../../utils'
3737
import { usePopover, PopoverContent } from '../../../Popover'
3838
import { InputText, InputTextProps } from '../../Inputs/InputText'
3939
import { Field, FieldProps, omitFieldProps, pickFieldProps } from '../Field'
40-
import { FormControl } from '../../FormControl'
4140
import { useFormContext } from '../../Form'
4241
import {
4342
HueSaturation,
@@ -186,36 +185,34 @@ export const FieldColorComponent = forwardRef(
186185
id={inputID}
187186
validationMessage={validationMessage}
188187
>
189-
<FormControl alignLabel="left">
190-
<Swatch
191-
ref={triggerRef}
192-
color={hsv2hex(color)}
193-
borderRadius={hideInput ? 'medium' : 'none'}
194-
borderTopLeftRadius="medium"
195-
borderBottomLeftRadius="medium"
196-
border="1px solid"
197-
borderRight={hideInput ? undefined : 'none'}
198-
disabled={props.disabled}
199-
onClick={open}
188+
<Swatch
189+
ref={triggerRef}
190+
color={hsv2hex(color)}
191+
borderRadius={hideInput ? 'medium' : 'none'}
192+
borderTopLeftRadius="medium"
193+
borderBottomLeftRadius="medium"
194+
border="1px solid"
195+
borderRight={hideInput ? undefined : 'none'}
196+
disabled={props.disabled}
197+
onClick={open}
198+
/>
199+
{!props.disabled && popover}
200+
{!hideInput && (
201+
<InputText
202+
{...omitFieldProps(props)}
203+
aria-describedby={`${id}-describedby`}
204+
id={inputID}
205+
ref={ref}
206+
borderRadius="none"
207+
borderTopRightRadius="medium"
208+
borderBottomRightRadius="medium"
209+
validationType={validationMessage && validationMessage.type}
210+
onChange={handleInputTextChange}
211+
value={inputTextValue}
212+
onFocus={wrappedOnFocus}
213+
onBlur={wrappedOnBlur}
200214
/>
201-
{!props.disabled && popover}
202-
{!hideInput && (
203-
<InputText
204-
{...omitFieldProps(props)}
205-
aria-describedby={`${id}-describedby`}
206-
id={inputID}
207-
ref={ref}
208-
borderRadius="none"
209-
borderTopRightRadius="medium"
210-
borderBottomRightRadius="medium"
211-
validationType={validationMessage && validationMessage.type}
212-
onChange={handleInputTextChange}
213-
value={inputTextValue}
214-
onFocus={wrappedOnFocus}
215-
onBlur={wrappedOnBlur}
216-
/>
217-
)}
218-
</FormControl>
215+
)}
219216
</Field>
220217
)
221218
}

packages/components/src/Form/Fields/FieldRadio/__snapshots__/FieldRadio.test.tsx.snap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ exports[`A FieldRadio 1`] = `
2626
}
2727
2828
.c4 {
29-
margin: 3px;
3029
display: inline-block;
3130
height: 1rem;
3231
position: relative;
@@ -74,7 +73,6 @@ exports[`A FieldRadio 1`] = `
7473
color: #343C42;
7574
font-size: 0.75rem;
7675
font-weight: 600;
77-
display: inline-block;
7876
}
7977
8078
.c0 {
@@ -168,7 +166,6 @@ exports[`A FieldRadio checked 1`] = `
168166
}
169167
170168
.c4 {
171-
margin: 3px;
172169
display: inline-block;
173170
height: 1rem;
174171
position: relative;
@@ -216,7 +213,6 @@ exports[`A FieldRadio checked 1`] = `
216213
color: #343C42;
217214
font-size: 0.75rem;
218215
font-weight: 600;
219-
display: inline-block;
220216
}
221217
222218
.c0 {

0 commit comments

Comments
 (0)