Skip to content

Commit 5d4d619

Browse files
committed
fix(ui-form-field): should not change layout when only screenreader-only message is present
INSTUI-4673
1 parent c563623 commit 5d4d619

File tree

1 file changed

+12
-3
lines changed
  • packages/ui-form-field/src/FormFieldLayout

1 file changed

+12
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import type {
2929
} from './props'
3030
import type { FormFieldLayoutTheme } from '@instructure/shared-types'
3131
import { mapSpacingToShorthand } from '@instructure/emotion'
32+
import type { FormMessage } from '../FormPropTypes'
3233

3334
const generateGridLayout = (
3435
isInlineLayout: boolean,
@@ -75,10 +76,16 @@ const generateStyle = (
7576
props: FormFieldLayoutProps,
7677
styleProps: FormFieldStyleProps
7778
): FormFieldLayoutStyle => {
78-
const { inline, layout, vAlign, labelAlign, margin } = props
79+
const { inline, layout, vAlign, labelAlign, margin, messages } = props
7980
const { hasMessages, hasVisibleLabel, hasNewErrorMsgAndIsGroup } = styleProps
8081
const cssMargin = mapSpacingToShorthand(margin, componentTheme.spacing)
8182
const isInlineLayout = layout === 'inline'
83+
84+
const hasNonEmptyMessages = messages?.reduce(
85+
(_, message) => message.type !== 'screenreader-only',
86+
false
87+
)
88+
8289
// This is quite ugly, we should simplify it
8390
const gridTemplateAreas = generateGridLayout(
8491
isInlineLayout,
@@ -150,7 +157,7 @@ const generateStyle = (
150157
)
151158
},
152159
columnGap: '0.375rem',
153-
rowGap: '0.75rem',
160+
rowGap: hasNonEmptyMessages ? '0.75rem' : '0',
154161
width: '100%',
155162
...(inline && {
156163
display: 'inline-grid',
@@ -162,7 +169,9 @@ const generateStyle = (
162169
...labelStyles,
163170
// NOTE: needs separate groups for `:is()` and `:-webkit-any()` because of css selector group validation (see https://www.w3.org/TR/selectors-3/#grouping)
164171
'&:is(label)': labelStyles,
165-
'&:-webkit-any(label)': labelStyles
172+
'&:-webkit-any(label)': labelStyles,
173+
174+
paddingBottom: hasNonEmptyMessages ? '0' : '0.75rem'
166175
},
167176
formFieldChildren: {
168177
label: 'formFieldLayout__children',

0 commit comments

Comments
 (0)