Hiding the "+" button in Sanity's document list pane
12 replies
Last updated: Feb 7, 2025
D
I'm following the structure cheet sheet and I've the exact same use case as shown in this code. And I'm able to show blog by category. But at the top there is + button. It is behaving not as expected. When I click on it opens the new section on the right side with no documents and when I click on the + icon of this no documents list it opens add new blog page. I want to hide thay + icon.
Attaching an image for understanding that which + button I want to hide.
Attaching an image for understanding that which + button I want to hide.
S.documentTypeListItem('post').title('Posts'), S.documentTypeListItem('category').title('Categories'), S.listItem() .title('Posts By Category') .child( S.documentTypeList('category') .title('Posts by Category') .child((categoryId) => S.documentList() .apiVersion('2024-06-01') .title('Posts') .filter('_type == "post" && $categoryId in categories[]._ref') .params({categoryId}), ), )
Feb 5, 2025, 5:20 PM
C
Take a look at:
•
https://www.sanity.io/docs/new-document-options •
https://www.sanity.io/schemas/use-newdocumentoptions-to-configure-new-document-creation-2c640bf6 (if the site is working... it seems 'down' atm, but maybe that is just me)
•
https://www.sanity.io/docs/new-document-options •
https://www.sanity.io/schemas/use-newdocumentoptions-to-configure-new-document-creation-2c640bf6 (if the site is working... it seems 'down' atm, but maybe that is just me)
Feb 5, 2025, 5:25 PM
D
user P
these links are for simple use cases. If you look at code I've provided and the image I've attached I want to disable add/create option at custom code.If you can help it would be great. Thanks for your attention
Feb 5, 2025, 5:27 PM
C
The 'New Document Options' is the api used by the structure builder to control that "+" button and what you see there. The example I recall being for the 'global' but you should be able to make it work for just your specific sub menu... but I'm sorry I don't know the syntax off the top. Good luck!
Feb 5, 2025, 5:31 PM
R
The first code example in this post https://www.sanity.io/schemas/use-newdocumentoptions-to-configure-new-document-creation-2c640bf6 will remove the + button from your documents list.
Here's what it looks like after implementing in my sandbox.
Is that not what you're trying to accomplish?
Here's what it looks like after implementing in my sandbox.
// sanity.config.ts export default defineConfig() => { ... document: { newDocumentOptions: (prev, { currentUser, creationContext }) => { if (creationContext.type === 'structure') { return []; } return prev; }, }, ... }
Feb 5, 2025, 6:40 PM
D
user N
your solution will remove + icon from all the schemas. that is what I don’t want. let me record the video and provide you full structure.ts file code.Feb 6, 2025, 4:32 AM
D
user N
sharing here my structure.ts file and video recording to explain the issue. thank you for your attention.//structure.ts import type { StructureResolver } from 'sanity/structure'; // <https://www.sanity.io/docs/structure-builder-cheat-sheet> export const structure: StructureResolver = (S) => S.list() .title('Sanity') .items([ S.listItem() .title('Blog') .child( S.list() .title('Main') .items([ S.listItem() .title('Blog Settings') .child( S.editor() .title('Blog Settings') .schemaType('blogSetting') .documentId('blogSettings') ), S.documentTypeListItem('blog').title('All Blog Posts'), S.listItem() .title('Blog Posts by Category') .child( // Query categories and create dynamic list S.documentTypeList('blogCategory') .title('Blog Categories') .child((categoryId: string) => // For each category, list related blog posts S.documentList() .title('Blog Posts') .filter('_type == "blog" && references($categoryId)') .params({ categoryId }) ) ), S.documentTypeListItem('blogCategory').title('Categories'), S.documentTypeListItem('blogKeyword').title('Keywords'), ]) ), ]);
Feb 6, 2025, 4:44 AM
D
user N
when you get a time if you could take a look. thank you.Feb 6, 2025, 3:21 PM
R
user X
— The 'create' button is built into the documentTypeList. I don't believe you can remove it from a specific pane without creating a custom component to emulate that list.
Feb 6, 2025, 8:01 PM
R
user X
— This kept nagging at me and I think I found a solution for you after talking with some other folks.//structure.ts import type { StructureResolver } from 'sanity/structure'; // <https://www.sanity.io/docs/structure-builder-cheat-sheet> export const structure: StructureResolver = (S) => S.list() .title('Sanity') .items([ S.listItem() .title('Blog') .child( S.list() .title('Main') .items([ S.listItem() .title('Blog Settings') .child( S.editor() .title('Blog Settings') .schemaType('blogSetting') .documentId('blogSettings') ), S.documentTypeListItem('blog').title('All Blog Posts'), S.listItem() .title('Blog Posts by Category') .child( // Query categories and create dynamic list S.documentTypeList('blogCategory') .title('Blog Categories') .initialValueTemplates([]) // <-- This should prevent the create button .child((categoryId: string) => { // For each category, list related blog posts return S.documentList() .title('Blog Posts') .filter('_type == "blog" && references($categoryId)') .params({ categoryId }); }) ), S.documentTypeListItem('blogCategory').title('Categories'), S.documentTypeListItem('blogKeyword').title('Keywords'), ]) ), ]);
In my sandbox, I grouped posts by author; but the same should work when grouping by your
blogCategory
Feb 7, 2025, 1:02 AM
D
user N
I will try this solution.Feb 7, 2025, 5:44 AM
D
user N
this works like a magic. thank you for spending time on this issue and helping out. i wonder where we can find documentation for this kind of issues. for normal cases documentation is easy to follow and find answer but for tricky scenarios like this is there detailed reference or anything?Feb 7, 2025, 6:15 AM
R
We document the initial value templates here: https://www.sanity.io/docs/initial-value-templates#febce15880e2 There's also a comprehensive reference for our various APIs available here:
https://www.sanity.io/docs/reference/api/sanity that covers the following packages:sanity
sanity/cli
sanity/migrate
sanity/presentation
sanity/router
sanity/structure
https://www.sanity.io/docs/reference/api/sanity that covers the following packages:sanity
sanity/cli
sanity/migrate
sanity/presentation
sanity/router
sanity/structure
Feb 7, 2025, 12:23 PM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.