Skip to content

Commit d5c2358

Browse files
committed
refactor(ui-form-field): more pixel pushing, now it should look like the original
1 parent b8c2963 commit d5c2358

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

packages/ui-form-field/src/FormField/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,11 @@ type: example
3333
<TextInput id="_foo124"/>
3434
</FormField>
3535
test
36+
<hr/>
37+
<FormField id="_foo121" label={<ScreenReaderContent>hidden text</ScreenReaderContent>} width="400px" layout="stacked">
38+
<TextInput id="_foo121" />
39+
</FormField>
40+
test
41+
<hr/>
3642
</div>
3743
```

packages/ui-form-field/src/FormFieldLayout/index.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,7 @@ class FormFieldLayout extends Component<FormFieldLayoutProps> {
149149
)
150150
}
151151
// needs to be wrapped because it needs an `id`
152-
return (
153-
<div id={this._labelId} css={this.props.styles?.formFieldLabel}>
154-
{this.props.label}
155-
</div>
156-
)
152+
return <div id={this._labelId}>{this.props.label}</div>
157153
} else return null
158154
}
159155

@@ -177,7 +173,6 @@ class FormFieldLayout extends Component<FormFieldLayoutProps> {
177173

178174
const hasNewErrorMsgAndIsGroup =
179175
!!messages?.find((m) => m.type === 'newError') && isGroup
180-
181176
return (
182177
<ElementType
183178
{...omitProps(props, [...FormFieldLayout.allowedProps])}

packages/ui-form-field/src/FormFieldLayout/props.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ type FormFieldLayoutOwnProps = {
6868
*/
6969
layout?: 'stacked' | 'inline'
7070
labelAlign?: 'start' | 'end'
71+
/**
72+
* The vertical alignment of the label and the controls.
73+
* "top" by default
74+
*/
7175
vAlign?: 'top' | 'middle' | 'bottom'
7276
width?: string
7377
/**

packages/ui-form-field/src/FormFieldLayout/styles.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ import type {
2828
FormFieldStyleProps
2929
} from './props'
3030
import type { FormFieldLayoutTheme } from '@instructure/shared-types'
31-
// TODO If the label is invisible the top gap is too large
32-
// TODO DateTimeInput renders empty messages, these leave too large gaps too
31+
3332
/**
3433
* ---
3534
* private: true
@@ -45,7 +44,7 @@ const generateStyle = (
4544
props: FormFieldLayoutProps,
4645
styleProps: FormFieldStyleProps
4746
): FormFieldLayoutStyle => {
48-
const { inline, layout } = props
47+
const { inline, layout, vAlign } = props
4948
const { hasMessages, hasVisibleLabel } = styleProps
5049
// This is quite ugly, we should simplify it
5150
const inlineContainerAndLabel = layout === 'inline' && !inline
@@ -77,7 +76,7 @@ const generateStyle = (
7776
fontWeight: componentTheme.fontWeight,
7877
fontSize: componentTheme.fontSize,
7978
lineHeight: componentTheme.lineHeight,
80-
margin: 0,
79+
margin: '0 0 0.75rem 0',
8180
textAlign: inlineContainerAndLabel ? 'end' : 'start',
8281
...(isInlineLayout &&
8382
inline && {
@@ -95,6 +94,14 @@ const generateStyle = (
9594
}
9695
}
9796

97+
let alignItems = 'start'
98+
if (vAlign == 'top') {
99+
alignItems = 'start'
100+
} else if (vAlign == 'middle') {
101+
alignItems = 'center'
102+
} else if (vAlign == 'bottom') {
103+
alignItems = 'end'
104+
}
98105
return {
99106
formFieldLayout: {
100107
label: 'formFieldLayout',
@@ -107,6 +114,7 @@ const generateStyle = (
107114
textAlign: 'start',
108115
opacity: 'inherit',
109116
display: 'grid',
117+
alignItems: alignItems,
110118
gridTemplateColumns: gridTemplateColumns,
111119
gridTemplateAreas: gridTemplateAreas,
112120
[`@media screen and (max-width: ${componentTheme.stackedOrInlineBreakpoint})`]:
@@ -119,19 +127,10 @@ const generateStyle = (
119127
gridTemplateColumns: '100%'
120128
})
121129
},
122-
[`@media screen and (min-width: ${componentTheme.stackedOrInlineBreakpoint})`]:
123-
{
124-
...(isInlineLayout &&
125-
inline && {
126-
textAlign: 'end' // TODO this is a bug, remove it!
127-
})
128-
},
129-
rowGap: '0.75rem',
130130
columnGap: '0.375rem',
131131
width: '100%',
132132
...(inline && {
133133
display: 'inline-grid',
134-
verticalAlign: 'middle',
135134
width: 'auto'
136135
})
137136
},
@@ -147,7 +146,7 @@ const generateStyle = (
147146
formFieldChildren: {
148147
label: 'formFieldLayout__children',
149148
gridArea: 'controls',
150-
alignSelf: 'center',
149+
...(hasMessages && { marginBottom: '0.75rem' }),
151150
...(isInlineLayout &&
152151
inline && {
153152
[`@media screen and (min-width: ${componentTheme.stackedOrInlineBreakpoint})`]:

0 commit comments

Comments
 (0)