Skip to content

Commit

Permalink
Merge pull request #6357 from marmelab/revert-update-window-title
Browse files Browse the repository at this point in the history
Revert Update window title on page change
  • Loading branch information
djhi authored Jun 15, 2021
2 parents 93b7930 + 5d94b1a commit 675fca3
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 66 deletions.
9 changes: 0 additions & 9 deletions docs/CreateEdit.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,6 @@ export const PostEdit = (props) => (
);
```

React Admin also updates the page title based on this `title` prop, as long as it's a string. If you're passing an element as `title`, like in the example above, you have to update the page title yourself. React-admin exports a hook called `useDocumentTitle` to make this simple:

```jsx
const PostTitle = ({ record }) => {
useDocumentTitle(record ?? record.title);
return <span>Post {record ? `"${record.title}"` : ''}</span>;
};
```
### Actions

You can replace the list of default actions by your own element using the `actions` prop:
Expand Down
1 change: 0 additions & 1 deletion docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ title: "Reference"
* [`useDataProvider`](./Actions.md#usedataprovider-hook)
* [`useDelete`](./Actions.md#usedelete)
* [`useDeleteMany`](./Actions.md#usedeletemany)
* `useDocumentTitle`
* [`useEditController`](./CreateEdit.md#useeditcontroller)
* `useFilterState`
* [`useGetIdentity`](./Authentication.md#usegetidentity-hook)
Expand Down
14 changes: 8 additions & 6 deletions examples/simple/src/posts/PostTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import * as React from 'react';
import { useTranslate, TitleProps, useDocumentTitle } from 'react-admin';
import { useTranslate, TitleProps } from 'react-admin';

export default ({ record }: TitleProps) => {
const translate = useTranslate();
const title = translate('post.edit.title', { title: record?.title ?? '' });

useDocumentTitle(title);

return <span>{record ? title : ''}</span>;
return (
<span>
{record
? translate('post.edit.title', { title: record.title })
: ''}
</span>
);
};
2 changes: 1 addition & 1 deletion examples/simple/src/tags/TagEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const TagEdit = props => (
basePath="/posts"
resource="posts"
filter={{ tags: [props.id] }}
title={false}
title=" "
>
<Datagrid>
<TextField source="id" />
Expand Down
1 change: 0 additions & 1 deletion packages/ra-core/src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import warning from './warning';
import useWhyDidYouUpdate from './useWhyDidYouUpdate';
import { useSafeSetState, useTimeout } from './hooks';
import { getMutationMode } from './getMutationMode';
export * from './useDocumentTitle';
export * from './indexById';

export {
Expand Down
19 changes: 0 additions & 19 deletions packages/ra-core/src/util/useDocumentTitle.ts

This file was deleted.

19 changes: 7 additions & 12 deletions packages/ra-ui-materialui/src/layout/Title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { FC, cloneElement, ReactElement } from 'react';
import { createPortal } from 'react-dom';
import PropTypes from 'prop-types';
import { useTranslate, Record, warning } from 'ra-core';
import { TitleText } from './TitleText';

export interface TitleProps {
className?: string;
defaultTitle?: string;
record?: Record;
title?: string | ReactElement | false;
title?: string | ReactElement;
}

const Title: FC<TitleProps> = ({
Expand All @@ -27,18 +26,16 @@ const Title: FC<TitleProps> = ({

if (!container) return null;

if (typeof title === 'boolean' && !title) return null;

warning(!defaultTitle && !title, 'Missing title prop in <Title> element');

const titleElement = !title ? (
<TitleText className={className} {...rest} text={defaultTitle} />
<span className={className} {...rest}>
{defaultTitle}
</span>
) : typeof title === 'string' ? (
<TitleText
className={className}
{...rest}
text={translate(title, { _: title })}
/>
<span className={className} {...rest}>
{translate(title, { _: title })}
</span>
) : (
cloneElement(title, { className, record, ...rest })
);
Expand All @@ -48,14 +45,12 @@ const Title: FC<TitleProps> = ({
export const TitlePropType = PropTypes.oneOfType([
PropTypes.string,
PropTypes.element,
PropTypes.bool,
]);

Title.propTypes = {
defaultTitle: PropTypes.string,
className: PropTypes.string,
record: PropTypes.any,
// @ts-ignore
title: TitlePropType,
};

Expand Down
12 changes: 0 additions & 12 deletions packages/ra-ui-materialui/src/layout/TitleText.tsx

This file was deleted.

1 change: 0 additions & 1 deletion packages/ra-ui-materialui/src/layout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import Title, { TitleProps, TitlePropType } from './Title';
import TitleForRecord from './TitleForRecord';
import TopToolbar from './TopToolbar';
import UserMenu, { UserMenuProps } from './UserMenu';
export * from './TitleText';

export {
AppBar,
Expand Down
8 changes: 4 additions & 4 deletions packages/ra-ui-materialui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface ListProps extends ResourceComponentProps {
perPage?: number;
sort?: SortPayload;
syncWithLocation?: boolean;
title?: string | ReactElement | false;
title?: string | ReactElement;
}

export interface EditProps extends ResourceComponentPropsWithId {
Expand All @@ -43,7 +43,7 @@ export interface EditProps extends ResourceComponentPropsWithId {
onSuccess?: OnSuccess;
onFailure?: OnFailure;
transform?: (data: RaRecord) => RaRecord | Promise<RaRecord>;
title?: string | ReactElement | false;
title?: string | ReactElement;
}

export interface CreateProps extends ResourceComponentProps {
Expand All @@ -56,7 +56,7 @@ export interface CreateProps extends ResourceComponentProps {
onSuccess?: OnSuccess;
onFailure?: OnFailure;
transform?: (data: RaRecord) => RaRecord | Promise<RaRecord>;
title?: string | ReactElement | false;
title?: string | ReactElement;
}

export interface ShowProps extends ResourceComponentPropsWithId {
Expand All @@ -65,7 +65,7 @@ export interface ShowProps extends ResourceComponentPropsWithId {
classes?: any;
className?: string;
component?: ElementType;
title?: string | ReactElement | false;
title?: string | ReactElement;
}

export interface BulkActionProps {
Expand Down

0 comments on commit 675fca3

Please sign in to comment.