Skip to content

Commit

Permalink
feat(titles): Adds controlsDocumentTitle property to Tool
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Sep 5, 2023
1 parent 917c34e commit 5242d30
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/sanity/src/core/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ export interface Tool<Options = any> {
*/
title: string

/**
* Determines whether the tool will control the document title.
*/
controlsDocumentTitle?: boolean

/**
* Gets the state for the given intent.
*
Expand Down
6 changes: 3 additions & 3 deletions packages/sanity/src/core/studio/StudioLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ export function StudioLayout() {

return mainTitle
}, [activeToolName, name, title])
const toolControlsDocumentTitle = !!activeTool?.controlsDocumentTitle

useEffect(() => {
if (activeToolName === 'content') {
// Will be handled by sanity/src/desk/components/deskTool/DeskTitle.tsx
if (toolControlsDocumentTitle) {
return
}
document.title = documentTitle
}, [documentTitle, activeToolName])
}, [documentTitle, toolControlsDocumentTitle])

const handleSearchFullscreenOpenChange = useCallback((open: boolean) => {
setSearchFullscreenOpen(open)
Expand Down
2 changes: 2 additions & 0 deletions packages/sanity/src/desk/deskTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ export const deskTool = definePlugin<DeskToolOptions | void>((options) => ({
(intent === 'create' && params.template),
)
},
// Controlled by sanity/src/desk/components/deskTool/DeskTitle.tsx
controlsDocumentTitle: true,
getIntentState,
options,
router,
Expand Down

0 comments on commit 5242d30

Please sign in to comment.