npm @sanity/default-layout 2.17.0
v2.17.0

latest releases: 2.36.2, 2.36.2-weighted-search.16, 2.36.2-weighted-search.10...
2 years ago

Upgrade the Command Line Interface (CLI) with:

npm install --global @sanity/cli

Upgrade Sanity Studio with:

sanity upgrade

🔀 Introducing Conditional fields

A lot of you have been waiting for this for a while: A way to show and hide fields based on the value of some other field. The wait is over! In this release of the Sanity Studio the hidden field has been upgraded to take a callback function.

Example

export default {
 type: 'object',
 name: 'dropdownExample',
 fields: [
   {
     name: 'kind',
     type: 'string',
     options: {list: ['foo', 'bar', 'baz']},
   },
   {
     name: 'fooOptions',
     type: 'object',
     hidden: ({parent}) => !(parent?.kind === 'foo'),
     fields: [/* ... */],
   },
   {
     name: 'barOptions',
     type: 'number',
     hidden: ({parent}) => !(parent?.kind === 'bar'),
     fields: [/* ... */],
   },
 ],
}

Conditional fields

Get more code examples and read more about the nitty gritty details in our docs.

🐛 Notable bugfixes

  • Fixes an issue that would sometimes make image asset sources appear for files

📓 Full changelog

Author Message Commit
Marius Lundgård chore(dev): introduce UI workshop (#2692) 2467b69
Fred Carlsen fix(form-builder): fix default asset source for file input (#2702) 4ab43c0
Bjørge Næss chore: fix eslint errors 8d8d874
Bjørge Næss fix(form-builder): improve typings of the withDocument HOC 3195970
Bjørge Næss feat(test-studio): add example schemas for hidden callback 126d364
Bjørge Næss fix(form-builder): require hidden on field type to be a boolean 29228f4
Bjørge Næss feat(types): add typings for hidden callback c889d7b
Bjørge Næss feat(form-builder): support callback for hidden option on object field types 1bc019b
Bjørge Næss fix(form-builder): warn if hidden predicate returns a promise e2f5ae3
Bjørge Næss refactor(form-builder): rewrite to ConditionalField to functional component 636e187
Bjørge Næss fix(form-builder): wrap hidden callback in try/catch and console log error aec1afe
Bjørge Næss fix(form-builder): import HiddenOption directly from @sanity/types 659b695
Bjørge Næss fix(types): remove hidden option from BaseSchemaType and support callback on ObjectField type f8e9954
Bjørge Næss fix(field): hide diff for fields that are always hidden 947d224
Bjørge Næss fix(types): only allow hidden property on object field types 3cc4ae7
Bjørge Næss refactor(types): move User and CurrentUser interfaces to @sanity/types 940de82
Bjørge Næss feat(form-builder): pass current user as context to hidden callback 3644076
Bjørge Næss refactor(form-builder): refactor file + imageinput to fix typing issue 5a17a51
Bjørge Næss fix(form-builder): get around forwardRef warning eec7dbc
Bjørge Næss feat(form-builder) support conditional fields on image and file types 69b9f6b
Per-Kristian Nordnes chore(portable-text-editor): upgrade @sanity/slate-react a520ab5

Don't miss a new default-layout release

NewReleases is sending notifications on new releases.