Skip to content

Commit

Permalink
fix(form): properly support passing undefined as title to `renderDe…
Browse files Browse the repository at this point in the history
…fault()` for array and object fields (#6774)

* chore(test-studio): add repro case for sdx-1358

* fix(form): support passing `undefined` as field title to renderDefault
  • Loading branch information
bjoerge authored May 28, 2024
1 parent 1961904 commit f341c2d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
34 changes: 34 additions & 0 deletions dev/test-studio/schema/standard/arrays.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,40 @@ export default defineType({
},
],
},
{
name: 'arrayWithNoTitle',
title: 'Array with no title',
type: 'array',
components: {
field: (props: any) => {
return (
<div style={{border: '1px solid palegreen', borderRadius: 4}}>
{props.renderDefault({
...props,
title: undefined,
})}
</div>
)
},
},
of: [
{
type: 'object',
name: 'obj',
title: 'Some object',
fields: [
{
name: 'title',
type: 'string',
},
{
name: 'description',
type: 'string',
},
],
},
],
},
{
name: 'arrayOfMultipleTypes',
title: 'Array of multiple types',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,14 @@ export const FormFieldSet = forwardRef(function FormFieldSet(
content={
<Stack space={3}>
<Flex align="center">
<FormFieldSetLegend
collapsed={Boolean(collapsed)}
collapsible={collapsible}
onClick={collapsible ? handleToggle : undefined}
title={title}
/>
{title && (
<FormFieldSetLegend
collapsed={Boolean(collapsed)}
collapsible={collapsible}
onClick={collapsible ? handleToggle : undefined}
title={title}
/>
)}
{deprecated && (
<Box marginLeft={2}>
<Badge data-testid={`deprecated-badge-${title}`} tone="caution">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {Box, Flex, rem, Text, type Theme} from '@sanity/ui'
import {memo, type ReactNode} from 'react'
import {css, styled} from 'styled-components'

import {useTranslation} from '../../../i18n'
import {focusRingStyle} from './styles'

export interface FormFieldSetLegendProps {
Expand Down Expand Up @@ -71,15 +70,10 @@ const ToggleIconBox = styled(Box)`

export const FormFieldSetLegend = memo(function FormFieldSetLegend(props: FormFieldSetLegendProps) {
const {collapsed, collapsible, onClick, title} = props
const {t} = useTranslation()

const text = (
<Text weight="medium" size={1}>
{title || (
<span style={{color: 'var(--card-muted-fg-color)'}}>
{t('form.field.untitled-fieldset-label')}
</span>
)}
{title}
</Text>
)

Expand Down
2 changes: 0 additions & 2 deletions packages/sanity/src/core/i18n/bundles/studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,6 @@ export const studioLocaleStrings = defineLocalesResources('studio', {
'form.field.deprecated-label': 'deprecated',
/** Fallback title shown above field if it has no defined title */
'form.field.untitled-field-label': 'Untitled',
/** Fallback title shown above fieldset if it has no defined title */
'form.field.untitled-fieldset-label': 'Untitled',
/** Accessibility label for the icon that indicates the field has a validation error */
'form.validation.has-error-aria-label': 'Has error',
/** Accessibility label for the icon that indicates the field has validation information */
Expand Down

0 comments on commit f341c2d

Please sign in to comment.